From c95ae92dedf8ee641ff5f1945f878818784080df Mon Sep 17 00:00:00 2001 From: Michiel Kodde Date: Wed, 17 Jan 2024 07:52:49 +0100 Subject: [PATCH] Start work on running the behat tests --- stepup/docker-compose.yml | 10 ++++++++++ stepup/tests/behat/behat | 2 +- .../behat/features/bootstrap/ApiFeatureContext.php | 7 ------- .../behat/features/bootstrap/FeatureContext.php | 8 -------- stepup/tests/behat/features/bootstrap/RaContext.php | 12 +++++++----- .../features/bootstrap/SecondFactorAuthContext.php | 11 ++++++++++- .../behat/features/bootstrap/SelfServiceContext.php | 7 +++++++ stepup/tests/behat/features/ra_profile.feature | 4 ++-- stepup/tests/behat/fixtures/events.sql | 13 ++++++++----- 9 files changed, 45 insertions(+), 29 deletions(-) diff --git a/stepup/docker-compose.yml b/stepup/docker-compose.yml index 5e6c86d..ad8d355 100644 --- a/stepup/docker-compose.yml +++ b/stepup/docker-compose.yml @@ -25,6 +25,16 @@ services: - ${PWD}/dbschema:/docker-entrypoint-initdb.d - stepup_mariadb:/var/lib/mysql + behat: + image: ghcr.io/openconext/openconext-devconf/openconext-devconf:test + environment: + - APP_ENV=${APP_ENV:-prod} + networks: + openconextdev: + volumes: + - ${PWD}/:/config + - /var/run/docker.sock:/var/run/docker.sock + webauthn: image: ghcr.io/openconext/stepup-webauthn/stepup-webauthn:${STEPUP_VERSION:-prod} ports: diff --git a/stepup/tests/behat/behat b/stepup/tests/behat/behat index 3cd4926..352d9cf 100755 --- a/stepup/tests/behat/behat +++ b/stepup/tests/behat/behat @@ -4,4 +4,4 @@ # For now the only feature is that it pipes on any argument provided # to the script, into the behat command -./vendor/bin/behat --config config/behat.yml $1 +./vendor/bin/behat --config config/behat.yml --strict $1 diff --git a/stepup/tests/behat/features/bootstrap/ApiFeatureContext.php b/stepup/tests/behat/features/bootstrap/ApiFeatureContext.php index e039ae6..98146c5 100644 --- a/stepup/tests/behat/features/bootstrap/ApiFeatureContext.php +++ b/stepup/tests/behat/features/bootstrap/ApiFeatureContext.php @@ -123,16 +123,9 @@ class ApiFeatureContext implements Context */ public function __construct($apiUrl) { - // Configure the testcookie for the guzzle client that will be handling the Api calls. - $domain = 'middleware.dev.openconext.local'; - $values = ['testcookie' => 'testcookie']; - - $cookieJar = CookieJar::fromArray($values, $domain); - $this->client = new Client( [ 'base_uri' => $apiUrl, - 'cookies' => $cookieJar, ] ); } diff --git a/stepup/tests/behat/features/bootstrap/FeatureContext.php b/stepup/tests/behat/features/bootstrap/FeatureContext.php index 1b02396..b9ed807 100644 --- a/stepup/tests/behat/features/bootstrap/FeatureContext.php +++ b/stepup/tests/behat/features/bootstrap/FeatureContext.php @@ -62,10 +62,6 @@ public static function setupDatabase(BeforeFeatureScope $scope) shell_exec("./fixtures/middleware-push-config.sh"); // Perform an event replay shell_exec("docker exec -ti stepup-middleware-1 bin/console middleware:event:replay --env=smoketest_event_replay --no-interaction -q"); - - echo "Update the keys\n"; - // Update the `saml_entities` projection in `gateway_test` -// shell_exec("/vagrant/deploy/tests/behat/fixtures/bin/override_sp_public_keys"); } /** @@ -79,10 +75,6 @@ public function gatherContexts(BeforeScenarioScope $scope) $this->apiContext = $environment->getContext(ApiFeatureContext::class); $this->serlfServiceContext = $environment->getContext(SelfServiceContext::class); - // Set the testcookie for both sessions, effectively putting the Stepup suite in test mode - $this->minkContext->getSession()->setCookie('testcookie', 'testcookie'); - $this->minkContext->getSession('second')->setCookie('testcookie', 'testcookie'); - $this->payloadFactory = new CommandPayloadFactory(); $this->repository = new SecondFactorRepository(); $this->institutionConfiguration = new InstitutionConfiguration(); diff --git a/stepup/tests/behat/features/bootstrap/RaContext.php b/stepup/tests/behat/features/bootstrap/RaContext.php index 6a0d76d..760e031 100644 --- a/stepup/tests/behat/features/bootstrap/RaContext.php +++ b/stepup/tests/behat/features/bootstrap/RaContext.php @@ -109,15 +109,11 @@ public function iAmLoggedInIntoTheRaPortalAs($userName, $tokenType) */ public function iTryToLoginIntoTheRaPortalAs($userName, $tokenType) { - $this->minkContext->getSession()->stop(); - $this->minkContext->getSession()->setCookie('testcookie', 'testcookie'); - // We visit the RA location url $this->minkContext->visit($this->raUrl); // The admin user logs in and gives a Yubikey second factor $this->authContext->authenticateWithIdentityProviderFor($userName); - switch ($tokenType) { case "yubikey": $this->authContext->verifyYuikeySecondFactor(); @@ -129,7 +125,6 @@ public function iTryToLoginIntoTheRaPortalAs($userName, $tokenType) $tokenType ) ); - break; } } @@ -644,4 +639,11 @@ public function iVerifyTheUsersIdentityByFillingTheLastCharactersOfTheDocumentNu $this->minkContext->checkOption('ra_verify_identity_identityVerified'); $this->minkContext->pressButton('Verify identity'); } + + private function diePrintingContent() + { + echo $this->minkContext->getSession()->getCurrentUrl(); + echo $this->minkContext->getSession()->getPage()->getContent(); + die; + } } diff --git a/stepup/tests/behat/features/bootstrap/SecondFactorAuthContext.php b/stepup/tests/behat/features/bootstrap/SecondFactorAuthContext.php index e4dd1f7..f5717c1 100644 --- a/stepup/tests/behat/features/bootstrap/SecondFactorAuthContext.php +++ b/stepup/tests/behat/features/bootstrap/SecondFactorAuthContext.php @@ -306,7 +306,9 @@ public function authenticateWithIdentityProviderFor($userName) $this->minkContext->fillField('password', $userName); $this->minkContext->pressButton('Login'); - $this->passTroughIdentityProviderAssertionConsumerService(); + $this->minkContext->pressButton('Yes, continue'); + $this->minkContext->assertPageAddress('https://gateway.dev.openconext.local/authentication/consume-assertion'); + $this->minkContext->assertPageNotContainsText('Incorrect username or password'); } private function passTroughIdentityProviderAssertionConsumerService() @@ -438,4 +440,11 @@ public function theVerificationCodeIsInvalid() { $this->minkContext->assertResponseContains('This code is not correct. Please try again or request a new code.'); } + + private function diePrintingContent() + { + echo $this->minkContext->getSession()->getCurrentUrl(); + echo $this->minkContext->getSession()->getPage()->getContent(); + die; + } } diff --git a/stepup/tests/behat/features/bootstrap/SelfServiceContext.php b/stepup/tests/behat/features/bootstrap/SelfServiceContext.php index b9f3fe5..520bdef 100644 --- a/stepup/tests/behat/features/bootstrap/SelfServiceContext.php +++ b/stepup/tests/behat/features/bootstrap/SelfServiceContext.php @@ -352,4 +352,11 @@ public function getVerifiedSecondFactorId() { return $this->verifiedSecondFactorId; } + + private function diePrintingContent() + { + echo $this->minkContext->getSession()->getCurrentUrl(); + echo $this->minkContext->getSession()->getPage()->getContent(); + die; + } } diff --git a/stepup/tests/behat/features/ra_profile.feature b/stepup/tests/behat/features/ra_profile.feature index 01e9c0d..ceec852 100644 --- a/stepup/tests/behat/features/ra_profile.feature +++ b/stepup/tests/behat/features/ra_profile.feature @@ -5,10 +5,10 @@ Feature: A RA(A) can view profile information And institution "institution-a.example.com" can "use_raa" from institution "institution-a.example.com" And institution "institution-a.example.com" can "select_raa" from institution "institution-a.example.com" And a user "Jane Toppan" identified by "urn:collab:person:institution-a.example.com:jane-a-ra" from institution "institution-a.example.com" with UUID "00000000-0000-4000-A000-000000000001" - And the user "urn:collab:person:institution-a.example.com:jane-a-ra" has a vetted "yubikey" + And the user "urn:collab:person:institution-a.example.com:jane-a-ra" has a vetted "yubikey" identified by "00000000-0000-4000-A000-000000000001" And the user "urn:collab:person:institution-a.example.com:jane-a-ra" has the role "raa" for institution "institution-a.example.com" And a user "Joe Satriani" identified by "urn:collab:person:institution-a.example.com:joe-a-ra" from institution "institution-a.example.com" with UUID "00000000-0000-4000-A000-000000000002" - And the user "urn:collab:person:institution-a.example.com:joe-a-ra" has a vetted "yubikey" + And the user "urn:collab:person:institution-a.example.com:joe-a-ra" has a vetted "yubikey" identified by "00000000-0000-4000-A000-000000000002" And the user "urn:collab:person:institution-a.example.com:joe-a-ra" has the role "ra" for institution "institution-a.example.com" Scenario: RAA user for one institution sees the authorization for that institution diff --git a/stepup/tests/behat/fixtures/events.sql b/stepup/tests/behat/fixtures/events.sql index f2a875b..82533bb 100644 --- a/stepup/tests/behat/fixtures/events.sql +++ b/stepup/tests/behat/fixtures/events.sql @@ -40,7 +40,9 @@ CREATE TABLE `event_stream` ( LOCK TABLES `event_stream` WRITE; /*!40000 ALTER TABLE `event_stream` DISABLE KEYS */; -INSERT INTO `event_stream` VALUES ('12345678-abcd-4321-abcd-123456789012',0,'{\"class\":\"Broadway\\\\Domain\\\\Metadata\",\"payload\":[]}','{\"class\":\"Surfnet\\\\Stepup\\\\Configuration\\\\Event\\\\NewConfigurationCreatedEvent\",\"payload\":{\"id\":\"12345678-abcd-4321-abcd-123456789012\"}}','2018-07-30T13:09:35.998358+00:00','Surfnet.Stepup.Configuration.Event.NewConfigurationCreatedEvent'),('12345678-abcd-4321-abcd-123456789012',1,'{\"class\":\"Broadway\\\\Domain\\\\Metadata\",\"payload\":[]}','{\"class\":\"Surfnet\\\\Stepup\\\\Configuration\\\\Event\\\\ConfigurationUpdatedEvent\",\"payload\":{\"id\":\"12345678-abcd-4321-abcd-123456789012\",\"new_configuration\":{\"sraa\":[\"urn:collab:person:dev.openconext.local:admin\",\"urn:collab:person:dev.openconext.local:pieter\",\"urn:collab:person:dev.openconext.local:joost\"],\"email_templates\":{\"confirm_email\":{\"en_GB\":\"

Dear {{ commonName }},<\\/p>

Thank you for registering your token. Please visit this link to verify your email address:<\\/p>

{{ verificationUrl }}<\\/a><\\/p>

If you can not click on the URL, please copy the link and paste it in the address bar of your browser.<\\/p>\",\"nl_NL\":\"

Beste {{ commonName }},<\\/p>

Bedankt voor het registreren van je token. Klik op onderstaande link om je e-mailadres te bevestigen:<\\/p>

{{ verificationUrl }}<\\/a><\\/p>

Is klikken op de link niet mogelijk? Kopieer dan de link en plak deze in de adresbalk van je browser.<\\/p>\"},\"registration_code_with_ras\":{\"en_GB\":\"

Dear {{ commonName }},<\\/p>

Thank you for registering your token. Please visit one of the locations below within 14 days to get your token activated. After {{ expirationDate | localizeddate(\'full\', \'none\', locale) }} your activation code is no longer valid.<\\/p>

Please bring the following:<\\/p>