Skip to content

Commit

Permalink
Add MW deprovision test
Browse files Browse the repository at this point in the history
  • Loading branch information
pablothedude committed Jan 21, 2025
1 parent 98e9f7c commit 480a548
Show file tree
Hide file tree
Showing 4 changed files with 282 additions and 4 deletions.
25 changes: 22 additions & 3 deletions stepup/tests/behat/features/bootstrap/ReplayContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;

class ReplayContext implements Context
Expand All @@ -22,9 +23,9 @@ public function gatherContexts(BeforeScenarioScope $scope)
}

/**
* @Given a replay is performed
* @Given a replay of :arg is performed
*/
public function replay()
public function replay($name)
{
// Generate test databases
echo "Preparing test schemas\n";
Expand All @@ -35,10 +36,28 @@ public function replay()

// Import the events.sql into middleware
echo "Add events to test database\n";
FeatureContext::execCommand("mysql -uroot -psecret middleware_test -h mariadb < ./fixtures/eventstream.sql");
FeatureContext::execCommand("mysql -uroot -psecret middleware_test -h mariadb < ./fixtures/".$name.".sql");

// Perform an event replay
echo "Replaying event stream\n";
FeatureContext::execCommand("docker exec -t stepup-middleware-1 php bin/console middleware:event:replay --env=smoketest_event_replay --no-interaction -vvv");
}


/**
* @Given the database should not contain
* @param TableNode $table
*/
public function tempDataBaseDoesNotContains(TableNode $table)
{
FeatureContext::execCommand("mysqldump -h mariadb -u root -psecret --single-transaction --databases middleware_test gateway_test > temp.sql");
$dataset = file_get_contents('temp.sql');

$hash = $table->getHash();
foreach ($hash as $row) {
if (str_contains($dataset, $row['value'])) {
throw new RuntimeException(sprintf("Data %s with value %s is still in the data set.", $row['name'], $row['value']));
}
}
}
}
15 changes: 15 additions & 0 deletions stepup/tests/behat/features/mw_deprovision.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Feature: A user can be deprovisioned from Middleware
In order to deprovision a user for middleware
On the command line
I expect this to be reflected in the data set

Scenario: After a replay is performed I would expect the last event reflected in the data set
Given a replay of deprovision is performed
Given I authenticate with user "lifecycle" and password "secret"
And I request "DELETE /deprovision/urn:collab:person:institution-a.example.com:joe-a-raa"
Then the api response status code should be 200
And the database should not contain
| name | value |
| email | joe-a-raa@institution-a.nl |
| common_name | Joe RAA |
| document_number | 467890 |
2 changes: 1 addition & 1 deletion stepup/tests/behat/features/mw_replay.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Feature: A replay is performed on Middleware
I expect the last event to be reflected in the data set

Scenario: After a replay is performed I would expect the last event reflected in the data set
Given a replay is performed
Given a replay of eventstream is performed
Given I authenticate with user "ra" and password "secret"
And I request "GET /identity?institution=institution-b.example.com&NameID=urn:collab:person:institution-b.example.com:joe-b5"
Then the api response status code should be 200
Expand Down
244 changes: 244 additions & 0 deletions stepup/tests/behat/fixtures/deprovision.sql

Large diffs are not rendered by default.

0 comments on commit 480a548

Please sign in to comment.