Skip to content

Commit 9330b7a

Browse files
authored
Merge pull request #21 from OpenConext/feature/make-behat-replay-more-verbose
Optimize behat tests
2 parents 50124a9 + 19bfffc commit 9330b7a

16 files changed

+495
-80
lines changed

stepup/tests/behat/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/vendor
1+
/vendor
2+
setup.sql

stepup/tests/behat/config/behat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ default:
2222
raUrl: 'https://ra.dev.openconext.local'
2323
- ApiFeatureContext:
2424
apiUrl: 'https://middleware.dev.openconext.local'
25+
- ReplayContext: ~
2526
- Behat\MinkExtension\Context\MinkContext
2627

2728
extensions:

stepup/tests/behat/features/bootstrap/FeatureContext.php

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
55
use Behat\MinkExtension\Context\MinkContext;
66
use Behat\Behat\Hook\Scope\BeforeFeatureScope;
7+
use Behat\Testwork\Hook\Scope\BeforeSuiteScope;
78
use Ramsey\Uuid\Uuid;
89
use Surfnet\StepupBehat\Factory\CommandPayloadFactory;
910
use Surfnet\StepupBehat\Repository\SecondFactorRepository;
@@ -44,24 +45,64 @@ class FeatureContext implements Context
4445
*/
4546
private $institutionConfiguration;
4647

48+
public static function execCommand(string $command): void
49+
{
50+
$output = [];
51+
$returnCode = -1;
52+
$result = exec($command, $output, $returnCode);
53+
54+
if($result === false) {
55+
echo "Failed executing command\n";
56+
die();
57+
}
58+
59+
foreach ($output as $line) {
60+
echo $line."\n";
61+
}
62+
63+
if ($returnCode !== 0) {
64+
die();
65+
}
66+
}
67+
4768
/**
48-
* @BeforeFeature
69+
* @BeforeSuite
4970
*/
50-
public static function setupDatabase(BeforeFeatureScope $scope)
71+
public static function setupDatabase(BeforeSuiteScope $scope)
5172
{
5273
// Generate test databases
5374
echo "Preparing test schemas\n";
54-
shell_exec("docker exec -t stepup-middleware-1 bin/console doctrine:schema:drop --env=smoketest --force");
55-
shell_exec("docker exec -t stepup-gateway-1 bin/console doctrine:schema:drop --env=smoketest --force");
56-
shell_exec("docker exec -t stepup-middleware-1 bin/console doctrine:schema:create --env=smoketest");
57-
shell_exec("docker exec -t stepup-gateway-1 bin/console doctrine:schema:create --env=smoketest");
75+
self::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:drop --em=middleware --env=smoketest --force');
76+
self::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:drop --em=gateway --env=smoketest --force');
77+
self::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:create --em=middleware --env=smoketest');
78+
self::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:create --em=gateway --env=smoketest');
5879

59-
echo "Replaying event stream\n";
6080
// Import the events.sql into middleware
61-
shell_exec("mysql -uroot -psecret middleware_test -h mariadb < ./fixtures/events.sql");
62-
shell_exec("./fixtures/middleware-push-config.sh");
81+
echo "Add events to test database\n";
82+
self::execCommand("mysql -uroot -psecret middleware_test -h mariadb < ./fixtures/events.sql");
83+
6384
// Perform an event replay
64-
shell_exec("docker exec -t stepup-middleware-1 bin/console middleware:event:replay --env=smoketest_event_replay --no-interaction -q");
85+
echo "Replaying event stream\n";
86+
self::execCommand("docker exec -t stepup-middleware-1 bin/console middleware:event:replay --env=smoketest_event_replay --no-interaction -vvv");
87+
88+
// Push config
89+
echo "Push Middleware config\n";
90+
self::execCommand("./fixtures/middleware-push-config.sh");
91+
self::execCommand("./fixtures/middleware-push-whitelist.sh");
92+
self::execCommand("./fixtures/middleware-push-institution.sh");
93+
94+
// Write base setup for initializing features
95+
echo "Dump empty setup to mysql file\n";
96+
self::execCommand("mysqldump -h mariadb -u root -psecret --single-transaction --databases middleware_test gateway_test > setup.sql");
97+
}
98+
99+
/**
100+
* @BeforeFeature
101+
*/
102+
public static function load(BeforeFeatureScope $scope)
103+
{
104+
// restore base setup
105+
self::execCommand("mysql -h mariadb -u root -psecret < setup.sql");
65106
}
66107

67108
/**
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
use Behat\Behat\Context\Context;
4+
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
5+
use Behat\MinkExtension\Context\MinkContext;
6+
7+
class ReplayContext implements Context
8+
{
9+
/**
10+
* @var \Behat\MinkExtension\Context\MinkContext
11+
*/
12+
private $minkContext;
13+
14+
/**
15+
* @BeforeScenario
16+
*/
17+
public function gatherContexts(BeforeScenarioScope $scope)
18+
{
19+
$environment = $scope->getEnvironment();
20+
21+
$this->minkContext = $environment->getContext(MinkContext::class);
22+
}
23+
24+
/**
25+
* @Given a replay is performed
26+
*/
27+
public function replay()
28+
{
29+
// Generate test databases
30+
echo "Preparing test schemas\n";
31+
FeatureContext::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:drop --em=middleware --env=smoketest --force');
32+
FeatureContext::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:drop --em=gateway --env=smoketest --force');
33+
FeatureContext::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:create --em=middleware --env=smoketest');
34+
FeatureContext::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:create --em=gateway --env=smoketest');
35+
36+
// Import the events.sql into middleware
37+
echo "Add events to test database\n";
38+
FeatureContext::execCommand("mysql -uroot -psecret middleware_test -h mariadb < ./fixtures/eventstream.sql");
39+
40+
// Perform an event replay
41+
echo "Replaying event stream\n";
42+
FeatureContext::execCommand("docker exec -t stepup-middleware-1 bin/console middleware:event:replay --env=smoketest_event_replay --no-interaction -vvv");
43+
}
44+
}

stepup/tests/behat/features/bootstrap/SecondFactorAuthContext.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,14 +387,6 @@ public function authenticateWithIdentityProviderForWithStepup($userName)
387387
$this->minkContext->pressButton('Yes, continue');
388388
}
389389

390-
private function passTroughIdentityProviderAssertionConsumerService()
391-
{
392-
$this->minkContext->assertPageAddress('https://gateway.dev.openconext.local/authentication/consume-assertion');
393-
394-
$this->minkContext->assertPageNotContainsText('Incorrect username or password');
395-
$this->minkContext->pressButton('Submit');
396-
}
397-
398390
/**
399391
* @Then I am logged on the service provider
400392
*/

stepup/tests/behat/features/bootstrap/SelfServiceContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ private function getLastSentEmail()
508508
}
509509

510510
$messages = json_decode($response);
511-
if (!$messages) {
511+
if (!is_array($messages)) {
512512
throw new Exception(
513513
'Unable to parse mailcatcher response'
514514
);

stepup/tests/behat/features/identity.feature

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ Feature: A (S)RA(A) user reads identities of StepUp users in the middleware API
33
As a (S)RA(A) user
44
I must be able to read from the middleware API
55

6+
Scenario: Provision the following users:
7+
Given a user "jane-a1" identified by "urn:collab:person:institution-a.example.com:jane-a-ra" from institution "institution-a.example.com" with UUID "00000000-0000-4000-8000-000000000001"
8+
And a user "joe-a1" identified by "urn:collab:person:institution-a.example.com:jane-a-ra" from institution "institution-a.example.com" with UUID "00000000-0000-4000-8000-000000000002"
9+
And a user "jill-a1" identified by "urn:collab:person:institution-a.example.com:jane-a-ra" from institution "institution-a.example.com" with UUID "00000000-0000-4000-8000-000000000003"
10+
611
Scenario: A (S)RA(A) user reads identities without additional authorization context
712
Given I authenticate with user "ra" and password "secret"
813
When I request "GET /identity?institution=institution-a.example.com"

stepup/tests/behat/features/ra_candidate.feature

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ Feature: A RAA manages ra candidates in the ra environment
2323
Then I should see the following candidates:
2424
| name | institution |
2525
| jane-a-ra | institution-a.example.com |
26-
| jane-b1 institution-b.example.com | institution-b.example.com |
27-
| user-b-ra institution-b.example.com | institution-b.example.com |
28-
| user-b5 institution-b.example.com | institution-b.example.com |
2926
| Admin | dev.openconext.local |
30-
| SRAA2 | dev.openconext.local |
3127

3228
Scenario: SRAA user checks if "Jane Toppan" is a candidate for all institutions (with filtering on institution-a)
3329
Given I am logged in into the ra portal as "admin" with a "yubikey" token
@@ -42,9 +38,6 @@ Feature: A RAA manages ra candidates in the ra environment
4238
When I visit the RA promotion page
4339
Then I should see the following candidates for "institution-b.example.com":
4440
| name | institution |
45-
| jane-b1 institution-b.example.com | institution-b.example.com |
46-
| user-b-ra institution-b.example.com | institution-b.example.com |
47-
| user-b5 institution-b.example.com | institution-b.example.com |
4841

4942
Scenario: SRAA user demotes "jane-a-ra" to no longer be an RAA for "institution-a"
5043
Given I am logged in into the ra portal as "admin" with a "yubikey" token
@@ -57,18 +50,12 @@ Feature: A RAA manages ra candidates in the ra environment
5750
Then I should see the following candidates for "institution-a.example.com":
5851
| name | institution |
5952
| jane-a-ra | institution-a.example.com |
60-
| jane-b1 institution-b.example.com | institution-b.example.com |
61-
| user-b-ra institution-b.example.com | institution-b.example.com |
62-
| user-b5 institution-b.example.com | institution-b.example.com |
6353

6454
Scenario: SRAA user checks if "Jane Toppan" is not a candidate for "institution-b"
6555
Given I am logged in into the ra portal as "admin" with a "yubikey" token
6656
When I visit the RA promotion page
6757
Then I should see the following candidates for "institution-b.example.com":
6858
| name | institution |
69-
| jane-b1 institution-b.example.com | institution-b.example.com |
70-
| user-b-ra institution-b.example.com | institution-b.example.com |
71-
| user-b5 institution-b.example.com | institution-b.example.com |
7259

7360
Scenario: SRAA user checks if "Jane Toppan" is not listed for "institution-a"
7461
Given I am logged in into the ra portal as "admin" with a "yubikey" token

stepup/tests/behat/features/ra_multiple_tokens.feature

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ Feature: A RAA (jane a ra) has two loa 3 tokens which makes her a valid RA candi
5454
Then I should see the following candidates:
5555
| name | institution |
5656
| jane-a-ra | institution-a.example.com |
57-
| jane-b1 institution-b.example.com | institution-b.example.com |
58-
| user-b5 institution-b.example.com | institution-b.example.com |
59-
| user-b-ra institution-b.example.com | institution-b.example.com |
6057
| Admin | dev.openconext.local |
61-
| SRAA2 | dev.openconext.local |
6258

6359
Scenario: SRAA user checks if "jane-a-ra" is a candidate for institutions if relieved from the RAA role
6460
Given I am logged in into the ra portal as "admin" with a "yubikey" token
@@ -68,11 +64,7 @@ Feature: A RAA (jane a ra) has two loa 3 tokens which makes her a valid RA candi
6864
And I should see the following candidates:
6965
| name | institution |
7066
| jane-a-ra | institution-a.example.com |
71-
| jane-b1 institution-b.example.com | institution-b.example.com |
72-
| user-b5 institution-b.example.com | institution-b.example.com |
73-
| user-b-ra institution-b.example.com | institution-b.example.com |
7467
| Admin | dev.openconext.local |
75-
| SRAA2 | dev.openconext.local |
7668

7769
Scenario: Sraa revokes only one vetted token from "jane-a-ra" and that shouldn't remove her as candidate
7870
Given I am logged in into the ra portal as "admin" with a "yubikey" token
@@ -82,11 +74,7 @@ Feature: A RAA (jane a ra) has two loa 3 tokens which makes her a valid RA candi
8274
And I should see the following candidates:
8375
| name | institution |
8476
| jane-a-ra | institution-a.example.com |
85-
| jane-b1 institution-b.example.com | institution-b.example.com |
86-
| user-b5 institution-b.example.com | institution-b.example.com |
87-
| user-b-ra institution-b.example.com | institution-b.example.com |
8877
| Admin | dev.openconext.local |
89-
| SRAA2 | dev.openconext.local |
9078

9179
Scenario: Sraa revokes the last vetted token from "Jane Toppan" and that must remove her as candidate
9280
Given I am logged in into the ra portal as "admin" with a "yubikey" token
@@ -95,8 +83,4 @@ Feature: A RAA (jane a ra) has two loa 3 tokens which makes her a valid RA candi
9583
Then I visit the RA promotion page
9684
And I should see the following candidates:
9785
| name | institution |
98-
| jane-b1 institution-b.example.com | institution-b.example.com |
99-
| user-b5 institution-b.example.com | institution-b.example.com |
100-
| user-b-ra institution-b.example.com | institution-b.example.com |
10186
| Admin | dev.openconext.local |
102-
| SRAA2 | dev.openconext.local |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature: A replay is performed on Middleware
2+
In order to replay an event stream
3+
On the command line
4+
I expect the last event to be reflected in the data set
5+
6+
Scenario: After a replay is performed I would expect the last event reflected in the data set
7+
Given a replay is performed
8+
Given I authenticate with user "ra" and password "secret"
9+
And I request "GET /identity?institution=institution-b.example.com&NameID=urn:collab:person:institution-b.example.com:joe-b5"
10+
Then the api response status code should be 200
11+
And the "items" property should contain 1 items

0 commit comments

Comments
 (0)