From ecba3e3a0eed47dc00408570fab4dc89b873861c Mon Sep 17 00:00:00 2001 From: dmyios Date: Fri, 7 Oct 2022 16:00:46 +0200 Subject: [PATCH 1/2] Tests Access Group --- tests/api/behat.yml | 4 ++ .../ConfigurationAccessGroups.feature | 71 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/api/features/ConfigurationAccessGroups.feature diff --git a/tests/api/behat.yml b/tests/api/behat.yml index 975f73d260d..3611318842b 100644 --- a/tests/api/behat.yml +++ b/tests/api/behat.yml @@ -96,3 +96,7 @@ default: paths: [ "%paths.base%/features/MonitoringServerConfiguration.feature" ] contexts: - Centreon\Test\Api\Context\MonitoringServerConfigurationContext + access_groups_configuration: + paths: [ "%paths.base%/features/ConfigurationAccessGroups.feature" ] + contexts: + - Centreon\Test\Behat\Api\Context\ApiContext diff --git a/tests/api/features/ConfigurationAccessGroups.feature b/tests/api/features/ConfigurationAccessGroups.feature new file mode 100644 index 00000000000..9cfd19b5b7d --- /dev/null +++ b/tests/api/features/ConfigurationAccessGroups.feature @@ -0,0 +1,71 @@ +Feature: List Access Group API + In order to use List Access Groups API + As a logged user + I need to be able to list Access Groups + + Background: + Given a running instance of Centreon Web API + + Scenario: List Access Groups as an admin user + Given I am logged in + And the endpoints are described in Centreon Web API documentation (version: 22.10) + + When I send a GET request to '/api/latest/configuration/access-groups' + Then the response code should be "200" + And the JSON should be equal to: + """ + { + "result": [ + { + "id": 1, + "name": "ALL", + "alias": "ALL", + "has_changed": false, + "is_activated": true + } + ], + "meta": { + "page": 1, + "limit": 10, + "search": {}, + "sort_by": {}, + "total": 1 + } + } + """ + + Scenario: List Access Groups as a non-admin user with no rights to Reach API + Given the following CLAPI import data: + """ + CONTACT;ADD;kev;kev;kev@localhost;Centreon@2022;0;1;en_US;local + CONTACT;setparam;kev;reach_api;0 + """ + And I am logged in with "kev"/"Centreon@2022" + + When I send a GET request to '/api/latest/configuration/access-groups' + Then the response code should be "403" + + Scenario: List Access Groups as a non-admin user with the rights to Reach API and Access Groups + Given the following CLAPI import data: + """ + CONTACT;ADD;kev;kev;kev@localhost;$2y$10$M61cjm4zlrlrEUtv081FJugTqk6MFuK5bwV8yDxZb6edXgI7n7Gl2;0;1;en_US.UTF-8;local + CONTACT;setparam;kev;hostnotifopt;n + CONTACT;setparam;kev;servicenotifopt;n + CONTACT;setparam;kev;contact_js_effects;0 + CONTACT;setparam;kev;contact_theme;light + CONTACT;setparam;kev;timezone;0 + CONTACT;setparam;kev;reach_api;1 + CONTACT;setparam;kev;reach_api_rt;0 + CONTACT;setparam;kev;contact_enable_notifications;0 + CONTACT;setparam;kev;contact_type_msg;txt + CONTACT;setparam;kev;contact_activate;1 + CONTACT;setparam;kev;show_deprecated_pages;0 + CONTACT;setparam;kev;contact_ldap_last_sync;0 + CONTACT;setparam;kev;contact_ldap_required_sync;0 + """ + And I am logged in with "kev"/"Centreon@2022" + + When I send a GET request to '/api/latest/configuration/access-groups' + Then the response code should be "200" + + # Scenario: List Access Groups as a non-admin user with the rights to Reach API and no rights to Access \ No newline at end of file From 7d3872e015e921b85b58dc92470241503b601d39 Mon Sep 17 00:00:00 2001 From: dmyios Date: Thu, 20 Oct 2022 10:06:30 +0200 Subject: [PATCH 2/2] Finalized test for Acces-Groups --- .../ConfigurationAccessGroups.feature | 66 ++++++++++++++----- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/tests/api/features/ConfigurationAccessGroups.feature b/tests/api/features/ConfigurationAccessGroups.feature index 9cfd19b5b7d..a48e4c3422c 100644 --- a/tests/api/features/ConfigurationAccessGroups.feature +++ b/tests/api/features/ConfigurationAccessGroups.feature @@ -34,6 +34,41 @@ Feature: List Access Group API } """ + Scenario: List Access Groups as a non-admin user with the rights to Reach API and an Access Group + Given the following CLAPI import data: + """ + CONTACT;ADD;kev;kev;kev@localhost;Centreon@2022;0;1;en_US;local + CONTACT;setparam;kev;reach_api;1 + ACLGROUP;ADD;myGroup;myGroup; + ACLGROUP;SETPARAM;myGroup;activate;1; + ACLGROUP;SETCONTACT;myGroup;kev; + """ + And I am logged in with "kev"/"Centreon@2022" + + When I send a GET request to '/api/latest/configuration/access-groups' + Then the response code should be "200" + And the JSON should be equal to: + """ + { + "result": [ + { + "id": 2, + "name": "myGroup", + "alias": "myGroup", + "has_changed": true, + "is_activated": true + } + ], + "meta": { + "page": 1, + "limit": 10, + "search": {}, + "sort_by": {}, + "total": 1 + } + } + """ + Scenario: List Access Groups as a non-admin user with no rights to Reach API Given the following CLAPI import data: """ @@ -45,27 +80,26 @@ Feature: List Access Group API When I send a GET request to '/api/latest/configuration/access-groups' Then the response code should be "403" - Scenario: List Access Groups as a non-admin user with the rights to Reach API and Access Groups + Scenario: List Access Groups as a non-admin user with the rights to Reach API and no rights to Access Groups Given the following CLAPI import data: """ - CONTACT;ADD;kev;kev;kev@localhost;$2y$10$M61cjm4zlrlrEUtv081FJugTqk6MFuK5bwV8yDxZb6edXgI7n7Gl2;0;1;en_US.UTF-8;local - CONTACT;setparam;kev;hostnotifopt;n - CONTACT;setparam;kev;servicenotifopt;n - CONTACT;setparam;kev;contact_js_effects;0 - CONTACT;setparam;kev;contact_theme;light - CONTACT;setparam;kev;timezone;0 + CONTACT;ADD;kev;kev;kev@localhost;Centreon@2022;0;1;en_US;local CONTACT;setparam;kev;reach_api;1 - CONTACT;setparam;kev;reach_api_rt;0 - CONTACT;setparam;kev;contact_enable_notifications;0 - CONTACT;setparam;kev;contact_type_msg;txt - CONTACT;setparam;kev;contact_activate;1 - CONTACT;setparam;kev;show_deprecated_pages;0 - CONTACT;setparam;kev;contact_ldap_last_sync;0 - CONTACT;setparam;kev;contact_ldap_required_sync;0 """ And I am logged in with "kev"/"Centreon@2022" When I send a GET request to '/api/latest/configuration/access-groups' Then the response code should be "200" - - # Scenario: List Access Groups as a non-admin user with the rights to Reach API and no rights to Access \ No newline at end of file + And the JSON should be equal to: + """ + { + "result": [], + "meta": { + "page": 1, + "limit": 10, + "search": {}, + "sort_by": {}, + "total": 0 + } + } + """