Adapt plugins tests from bash to robot framework (#4487)
This commit is contained in:
parent
7f1ecee9fd
commit
ffdbfd018a
|
@ -1,4 +1,4 @@
|
||||||
name: Functional tests
|
name: functional-tests
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||||
|
@ -8,23 +8,27 @@ on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
|
- '.github/workflows/tests-functional.yml'
|
||||||
- 'src/**'
|
- 'src/**'
|
||||||
- 'tests/functional/**'
|
- 'tests/functional/**'
|
||||||
|
- 'tests/resources/mockoon/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
AWS_tests:
|
functional-tests-with-robot:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
- name: Install Node.js
|
||||||
- name: Use Node.js
|
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
node-version: "16.x"
|
node-version: "16.x"
|
||||||
|
|
||||||
- name: Install Mockoon CLI
|
- name: Install Mockoon CLI
|
||||||
run: npm install -D @mockoon/cli
|
run: npm install -g -D @mockoon/cli
|
||||||
|
|
||||||
|
- name: Install libs
|
||||||
|
run: sudo apt-get install libcurl4-openssl-dev
|
||||||
|
|
||||||
- name: Install perl dependencies
|
- name: Install perl dependencies
|
||||||
uses: shogo82148/actions-setup-perl@v1
|
uses: shogo82148/actions-setup-perl@v1
|
||||||
|
@ -35,40 +39,31 @@ jobs:
|
||||||
DateTime
|
DateTime
|
||||||
Digest::MD5
|
Digest::MD5
|
||||||
Encode
|
Encode
|
||||||
|
ExtUtils::PkgConfig
|
||||||
HTTP::ProxyPAC
|
HTTP::ProxyPAC
|
||||||
IO::Socket::SSL
|
IO::Socket::SSL
|
||||||
JSON::XS
|
JSON::XS
|
||||||
LWP::Protocol::https
|
LWP::Protocol::https
|
||||||
LWP::UserAgent
|
LWP::UserAgent
|
||||||
MIME::Base64
|
MIME::Base64
|
||||||
|
Net::Curl::Easy
|
||||||
Paws
|
Paws
|
||||||
POSIX
|
POSIX
|
||||||
Storable
|
Storable
|
||||||
URI
|
URI
|
||||||
URI::Encode
|
URI::Encode
|
||||||
|
|
||||||
- name: Run Mockoon CLI
|
- name: Install Python
|
||||||
run: npx mockoon-cli start --data tests/resources/mockoon/cloud-aws-cloudtrail.json --port 3000
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '3.10'
|
||||||
|
|
||||||
- name: Run plugin
|
- name: Install Robot Framework
|
||||||
|
run: pip3 install robotframework
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Run Robot Framework tests
|
||||||
run: |
|
run: |
|
||||||
sudo chmod -R +x tests/functional/
|
|
||||||
sudo mkdir -p /var/lib/centreon/centplugins/
|
sudo mkdir -p /var/lib/centreon/centplugins/
|
||||||
sudo chmod 777 /var/lib/centreon/centplugins/
|
sudo chmod 777 /var/lib/centreon/centplugins/
|
||||||
TESTS="$(tests/functional/cloud/aws/cloudtrail/checktrailstatus.sh)"
|
robot tests/functional/
|
||||||
echo "tests=$(echo $TESTS)" >> $GITHUB_OUTPUT
|
|
||||||
if [[ $TESTS = "OK:"* ]]; then
|
|
||||||
echo "OK"
|
|
||||||
else
|
|
||||||
echo $TESTS
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
TESTS="$(tests/functional/cloud/aws/cloudtrail/countevents.sh)"
|
|
||||||
echo "tests=$(echo $TESTS)" >> $GITHUB_OUTPUT
|
|
||||||
if [[ $TESTS = "OK:"* ]]; then
|
|
||||||
echo "OK"
|
|
||||||
else
|
|
||||||
echo $TESTS
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
shell: bash
|
|
||||||
|
|
|
@ -68,8 +68,8 @@ sub run {
|
||||||
if (length($self->{option_results}->{event_type}) || length($self->{option_results}->{error_message})) {
|
if (length($self->{option_results}->{event_type}) || length($self->{option_results}->{error_message})) {
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach my $event (@{$self->{events}}) {
|
foreach my $event (@{$self->{events}}) {
|
||||||
if ((defined($self->{option_results}->{event_type}) && length($self->{option_results}->{event_type}) && ($event->{eventType} eq $self->{option_results}->{event_type}))
|
if ((length($self->{option_results}->{event_type}) && ($event->{eventType} eq $self->{option_results}->{event_type}))
|
||||||
|| (defined($self->{option_results}->{error_message}) && length($self->{option_results}->{error_message}) && ($event->{errorMessage} =~ $self->{option_results}->{error_message}))) {
|
|| (length($self->{option_results}->{error_message}) && length($event->{errorMessage}) && $event->{errorMessage} =~ $self->{option_results}->{error_message})) {
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,215 @@
|
||||||
|
*** Settings ***
|
||||||
|
Documentation AWS CloudTrail plugin
|
||||||
|
|
||||||
|
Library OperatingSystem
|
||||||
|
Library Process
|
||||||
|
Library String
|
||||||
|
|
||||||
|
Suite Setup Start Mockoon
|
||||||
|
Suite Teardown Stop Mockoon
|
||||||
|
|
||||||
|
|
||||||
|
*** Variables ***
|
||||||
|
${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}src${/}centreon_plugins.pl
|
||||||
|
${MOCKOON_JSON} ${CURDIR}${/}..${/}resources${/}mockoon${/}cloud-aws-cloudtrail.json
|
||||||
|
|
||||||
|
${CMD} perl ${CENTREON_PLUGINS} --plugin=cloud::aws::cloudtrail::plugin --custommode=paws --region=eu-west --aws-secret-key=secret --aws-access-key=key
|
||||||
|
|
||||||
|
&{checktrailstatus_value1}
|
||||||
|
... trailstatus=true
|
||||||
|
... trailname=TrailName
|
||||||
|
... result=OK: Trail is logging: 1 | 'trail_is_logging'=1;;;0;
|
||||||
|
&{checktrailstatus_value2}
|
||||||
|
... trailstatus=false
|
||||||
|
... trailname=TrailName
|
||||||
|
... result=CRITICAL: Trail is logging: 0 | 'trail_is_logging'=0;;;0;
|
||||||
|
@{checktrailstatus_values} &{checktrailstatus_value1} &{checktrailstatus_value2}
|
||||||
|
|
||||||
|
&{countevents_value1}
|
||||||
|
... AwsApiCall=4
|
||||||
|
... AwsServiceEvent=2
|
||||||
|
... AwsConsoleAction=1
|
||||||
|
... AwsConsoleSignIn=3
|
||||||
|
... NextToken=false
|
||||||
|
... eventtype=
|
||||||
|
... delta=
|
||||||
|
... errormessage=
|
||||||
|
... warningcount=
|
||||||
|
... criticalcount=
|
||||||
|
... result=OK: Number of events: 10.00 | 'events_count'=10.00;;;0;
|
||||||
|
&{countevents_value2}
|
||||||
|
... AwsApiCall=4
|
||||||
|
... AwsServiceEvent=2
|
||||||
|
... AwsConsoleAction=1
|
||||||
|
... AwsConsoleSignIn=3
|
||||||
|
... NextToken=true
|
||||||
|
... eventtype=
|
||||||
|
... delta=
|
||||||
|
... errormessage=
|
||||||
|
... warningcount=
|
||||||
|
... criticalcount=
|
||||||
|
... result=OK: Number of events: 20.00 | 'events_count'=20.00;;;0;
|
||||||
|
&{countevents_value3}
|
||||||
|
... AwsApiCall=4
|
||||||
|
... AwsServiceEvent=2
|
||||||
|
... AwsConsoleAction=1
|
||||||
|
... AwsConsoleSignIn=3
|
||||||
|
... NextToken=false
|
||||||
|
... eventtype=AwsApiCall
|
||||||
|
... delta=
|
||||||
|
... errormessage=
|
||||||
|
... warningcount=
|
||||||
|
... criticalcount=
|
||||||
|
... result=OK: Number of events: 4.00 | 'events_count'=4.00;;;0;
|
||||||
|
&{countevents_value4}
|
||||||
|
... AwsApiCall=4
|
||||||
|
... AwsServiceEvent=2
|
||||||
|
... AwsConsoleAction=1
|
||||||
|
... AwsConsoleSignIn=3
|
||||||
|
... NextToken=true
|
||||||
|
... eventtype=AwsServiceEvent
|
||||||
|
... delta=
|
||||||
|
... errormessage=
|
||||||
|
... warningcount=
|
||||||
|
... criticalcount=
|
||||||
|
... result=OK: Number of events: 4.00 | 'events_count'=4.00;;;0;
|
||||||
|
&{countevents_value5}
|
||||||
|
... AwsApiCall=4
|
||||||
|
... AwsServiceEvent=2
|
||||||
|
... AwsConsoleAction=1
|
||||||
|
... AwsConsoleSignIn=3
|
||||||
|
... NextToken=false
|
||||||
|
... eventtype=AwsApiCall
|
||||||
|
... delta=10
|
||||||
|
... errormessage=
|
||||||
|
... warningcount=
|
||||||
|
... criticalcount=
|
||||||
|
... result=OK: Number of events: 4.00 | 'events_count'=4.00;;;0;
|
||||||
|
&{countevents_value6}
|
||||||
|
... AwsApiCall=4
|
||||||
|
... AwsServiceEvent=2
|
||||||
|
... AwsConsoleAction=1
|
||||||
|
... AwsConsoleSignIn=3
|
||||||
|
... NextToken=false
|
||||||
|
... eventtype=
|
||||||
|
... delta=
|
||||||
|
... errormessage='Login error'
|
||||||
|
... warningcount=
|
||||||
|
... criticalcount=
|
||||||
|
... result=OK: Number of events: 3.00 | 'events_count'=3.00;;;0;
|
||||||
|
&{countevents_value7}
|
||||||
|
... AwsApiCall=4
|
||||||
|
... AwsServiceEvent=2
|
||||||
|
... AwsConsoleAction=1
|
||||||
|
... AwsConsoleSignIn=3
|
||||||
|
... NextToken=false
|
||||||
|
... eventtype=
|
||||||
|
... delta=
|
||||||
|
... errormessage='.*error'
|
||||||
|
... warningcount=
|
||||||
|
... criticalcount=
|
||||||
|
... result=OK: Number of events: 4.00 | 'events_count'=4.00;;;0;
|
||||||
|
&{countevents_value8}
|
||||||
|
... AwsApiCall=4
|
||||||
|
... AwsServiceEvent=2
|
||||||
|
... AwsConsoleAction=1
|
||||||
|
... AwsConsoleSignIn=3
|
||||||
|
... NextToken=false
|
||||||
|
... eventtype=
|
||||||
|
... delta=
|
||||||
|
... errormessage=
|
||||||
|
... warningcount=3
|
||||||
|
... criticalcount=
|
||||||
|
... result=WARNING: Number of events: 10.00 | 'events_count'=10.00;;;0;
|
||||||
|
&{countevents_value9}
|
||||||
|
... AwsApiCall=4
|
||||||
|
... AwsServiceEvent=2
|
||||||
|
... AwsConsoleAction=1
|
||||||
|
... AwsConsoleSignIn=3
|
||||||
|
... NextToken=false
|
||||||
|
... eventtype=
|
||||||
|
... delta=
|
||||||
|
... errormessage=
|
||||||
|
... warningcount=
|
||||||
|
... criticalcount=5
|
||||||
|
... result=CRITICAL: Number of events: 10.00 | 'events_count'=10.00;;;0;
|
||||||
|
@{countevents_values}
|
||||||
|
... &{countevents_value1}
|
||||||
|
... &{countevents_value2}
|
||||||
|
... &{countevents_value3}
|
||||||
|
... &{countevents_value4}
|
||||||
|
... &{countevents_value5}
|
||||||
|
... &{countevents_value6}
|
||||||
|
... &{countevents_value7}
|
||||||
|
... &{countevents_value8}
|
||||||
|
... &{countevents_value9}
|
||||||
|
|
||||||
|
|
||||||
|
*** Test Cases ***
|
||||||
|
AWS CloudTrail check trail status
|
||||||
|
[Documentation] Check AWS CloudTrail trail status
|
||||||
|
[Tags] cloud aws cloudtrail
|
||||||
|
FOR ${checktrailstatus_value} IN @{checktrailstatus_values}
|
||||||
|
${output} = Run
|
||||||
|
... ${CMD} --mode=checktrailstatus --endpoint=http://localhost:3000/cloudtrail/gettrailstatus/${checktrailstatus_value.trailstatus} --trail-name=${checktrailstatus_value.trailname}
|
||||||
|
Should Be Equal As Strings
|
||||||
|
... ${output}
|
||||||
|
... ${checktrailstatus_value.result}
|
||||||
|
... msg=Wrong output result for check trail status of ${checktrailstatus_value}
|
||||||
|
END
|
||||||
|
|
||||||
|
AWS CloudTrail count events
|
||||||
|
[Documentation] Check AWS CloudTrail count events
|
||||||
|
[Tags] cloud aws cloudtrail
|
||||||
|
FOR ${countevents_value} IN @{countevents_values}
|
||||||
|
${command} = Catenate
|
||||||
|
... ${CMD}
|
||||||
|
... --mode=countevents
|
||||||
|
... --endpoint=http://localhost:3000/cloudtrail/events/AwsApiCall/${countevents_value.AwsApiCall}/AwsServiceEvent/${countevents_value.AwsServiceEvent}/AwsConsoleAction/${countevents_value.AwsConsoleAction}/AwsConsoleSignIn/${countevents_value.AwsConsoleSignIn}/NextToken/${countevents_value.NextToken}
|
||||||
|
${length} = Get Length ${countevents_value.eventtype}
|
||||||
|
IF ${length} > 0
|
||||||
|
${command} = Catenate ${command} --event-type=${countevents_value.eventtype}
|
||||||
|
END
|
||||||
|
${length} = Get Length ${countevents_value.delta}
|
||||||
|
IF ${length} > 0
|
||||||
|
${command} = Catenate ${command} --delta=${countevents_value.delta}
|
||||||
|
END
|
||||||
|
${length} = Get Length ${countevents_value.errormessage}
|
||||||
|
IF ${length} > 0
|
||||||
|
${command} = Catenate ${command} --error-message=${countevents_value.errormessage}
|
||||||
|
END
|
||||||
|
${length} = Get Length ${countevents_value.warningcount}
|
||||||
|
IF ${length} > 0
|
||||||
|
${command} = Catenate ${command} --warning-count=${countevents_value.warningcount}
|
||||||
|
END
|
||||||
|
${length} = Get Length ${countevents_value.criticalcount}
|
||||||
|
IF ${length} > 0
|
||||||
|
${command} = Catenate ${command} --critical-count=${countevents_value.criticalcount}
|
||||||
|
END
|
||||||
|
${output} = Run ${command}
|
||||||
|
Should Be Equal As Strings
|
||||||
|
... ${output}
|
||||||
|
... ${countevents_value.result}
|
||||||
|
... msg=Wrong output result for count events of ${countevents_value}
|
||||||
|
END
|
||||||
|
|
||||||
|
|
||||||
|
*** Keywords ***
|
||||||
|
Start Mockoon
|
||||||
|
${executionresult} = Run Process
|
||||||
|
... mockoon-cli
|
||||||
|
... start
|
||||||
|
... --data
|
||||||
|
... ${MOCKOON_JSON}
|
||||||
|
... --port
|
||||||
|
... 3000
|
||||||
|
... --pname
|
||||||
|
... azure-policyinsights
|
||||||
|
Should Be Empty ${executionresult.stderr}
|
||||||
|
|
||||||
|
Stop Mockoon
|
||||||
|
${executionresult} = Run Process
|
||||||
|
... mockoon-cli
|
||||||
|
... stop
|
||||||
|
... mockoon-azure-policyinsights
|
||||||
|
Should Be Empty ${executionresult.stderr}
|
|
@ -0,0 +1,93 @@
|
||||||
|
*** Settings ***
|
||||||
|
Documentation Azure PolicyInsights PolicyStates plugin
|
||||||
|
|
||||||
|
Library OperatingSystem
|
||||||
|
Library Process
|
||||||
|
Library String
|
||||||
|
|
||||||
|
Suite Setup Start Mockoon
|
||||||
|
Suite Teardown Stop Mockoon
|
||||||
|
|
||||||
|
|
||||||
|
*** Variables ***
|
||||||
|
${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}src${/}centreon_plugins.pl
|
||||||
|
${MOCKOON_JSON} ${CURDIR}${/}..${/}resources${/}mockoon${/}cloud-azure-policyinsights-policystates.json
|
||||||
|
|
||||||
|
${LOGIN_ENDPOINT} http://localhost:3000/login
|
||||||
|
${CMD} perl ${CENTREON_PLUGINS} --plugin=cloud::azure::policyinsights::policystates::plugin --subscription=subscription --tenant=tenant --client-id=client_id --client-secret=secret --login-endpoint=${LOGIN_ENDPOINT}
|
||||||
|
|
||||||
|
&{compliance_value1}
|
||||||
|
... endpoint=http://localhost:3000/ok
|
||||||
|
... policyname=
|
||||||
|
... resourcelocation=
|
||||||
|
... resourcetype=
|
||||||
|
... result=OK: Number of non compliant policies: 0 - All compliances states are ok | 'policies.non_compliant.count'=0;;;0;
|
||||||
|
&{compliance_value2}
|
||||||
|
... endpoint=http://localhost:3000/oknextlink
|
||||||
|
... policyname=9daedab3-fb2d-461e-b861-71790eead4f6
|
||||||
|
... resourcelocation=
|
||||||
|
... resourcetype=
|
||||||
|
... result=OK: Number of non compliant policies: 0 - All compliances states are ok | 'policies.non_compliant.count'=0;;;0;
|
||||||
|
&{compliance_value3}
|
||||||
|
... endpoint=http://localhost:3000/nok1
|
||||||
|
... policyname=9daedab3-fb2d-461e-b861-71790eead4f6
|
||||||
|
... resourcelocation=fr
|
||||||
|
... resourcetype=
|
||||||
|
... result=CRITICAL: Compliance state for policy '9daedab3-fb2d-461e-b861-71790eead4f6' on resource 'mypubip1' is 'NonCompliant' | 'policies.non_compliant.count'=1;;;0;
|
||||||
|
&{compliance_value4}
|
||||||
|
... endpoint=http://localhost:3000/nok2
|
||||||
|
... policyname=9daedab3-fb2d-461e-b861-71790eead4f6
|
||||||
|
... resourcelocation=fr
|
||||||
|
... resourcetype=ip
|
||||||
|
... result=CRITICAL: Compliance state for policy '9daedab3-fb2d-461e-b861-71790eead4f6' on resource 'mypubip1' is 'NonCompliant' - Compliance state for policy '9daedab3-fb2d-461e-b861-71790eead4f6' on resource 'mypubip2' is 'NonCompliant' | 'policies.non_compliant.count'=2;;;0;
|
||||||
|
@{compliance_values} &{compliance_value1} &{compliance_value2} &{compliance_value3} &{compliance_value4}
|
||||||
|
|
||||||
|
|
||||||
|
*** Test Cases ***
|
||||||
|
Azure PolicyInsights PolicyStates compliance
|
||||||
|
[Documentation] Check Azure PolicyInsights PolicyStates compliance
|
||||||
|
[Tags] cloud azure policyinsights policystates
|
||||||
|
FOR ${compliance_value} IN @{compliance_values}
|
||||||
|
${command} = Catenate
|
||||||
|
... ${CMD}
|
||||||
|
... --mode=compliance
|
||||||
|
... --management-endpoint=${compliance_value.endpoint}
|
||||||
|
${length} = Get Length ${compliance_value.policyname}
|
||||||
|
IF ${length} > 0
|
||||||
|
${command} = Catenate ${command} --policy-name=${compliance_value.policyname}
|
||||||
|
END
|
||||||
|
${length} = Get Length ${compliance_value.resourcelocation}
|
||||||
|
IF ${length} > 0
|
||||||
|
${command} = Catenate ${command} --resource-location=${compliance_value.resourcelocation}
|
||||||
|
END
|
||||||
|
${length} = Get Length ${compliance_value.resourcetype}
|
||||||
|
IF ${length} > 0
|
||||||
|
${command} = Catenate ${command} --resource-type=${compliance_value.resourcetype}
|
||||||
|
END
|
||||||
|
${output} = Run ${command}
|
||||||
|
Should Be Equal As Strings
|
||||||
|
... ${output}
|
||||||
|
... ${compliance_value.result}
|
||||||
|
... msg=Wrong output result for compliance of ${compliance_value}
|
||||||
|
END
|
||||||
|
|
||||||
|
|
||||||
|
*** Keywords ***
|
||||||
|
Start Mockoon
|
||||||
|
${executionresult} = Run Process
|
||||||
|
... mockoon-cli
|
||||||
|
... start
|
||||||
|
... --data
|
||||||
|
... ${MOCKOON_JSON}
|
||||||
|
... --port
|
||||||
|
... 3000
|
||||||
|
... --pname
|
||||||
|
... azure-policyinsights
|
||||||
|
Should Be Empty ${executionresult.stderr}
|
||||||
|
|
||||||
|
Stop Mockoon
|
||||||
|
${executionresult} = Run Process
|
||||||
|
... mockoon-cli
|
||||||
|
... stop
|
||||||
|
... mockoon-azure-policyinsights
|
||||||
|
Should Be Empty ${executionresult.stderr}
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue