From 480a5484bb38b9996d1533f7826a7eaa129cece1 Mon Sep 17 00:00:00 2001 From: Bas Date: Tue, 21 Jan 2025 14:21:35 +0100 Subject: [PATCH] Add MW deprovision test --- .../features/bootstrap/ReplayContext.php | 25 +- .../behat/features/mw_deprovision.feature | 15 ++ stepup/tests/behat/features/mw_replay.feature | 2 +- stepup/tests/behat/fixtures/deprovision.sql | 244 ++++++++++++++++++ 4 files changed, 282 insertions(+), 4 deletions(-) create mode 100644 stepup/tests/behat/features/mw_deprovision.feature create mode 100644 stepup/tests/behat/fixtures/deprovision.sql diff --git a/stepup/tests/behat/features/bootstrap/ReplayContext.php b/stepup/tests/behat/features/bootstrap/ReplayContext.php index 8ba5961..1a1ca30 100644 --- a/stepup/tests/behat/features/bootstrap/ReplayContext.php +++ b/stepup/tests/behat/features/bootstrap/ReplayContext.php @@ -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 @@ -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"; @@ -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'])); + } + } + } } diff --git a/stepup/tests/behat/features/mw_deprovision.feature b/stepup/tests/behat/features/mw_deprovision.feature new file mode 100644 index 0000000..d48c7fc --- /dev/null +++ b/stepup/tests/behat/features/mw_deprovision.feature @@ -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 | diff --git a/stepup/tests/behat/features/mw_replay.feature b/stepup/tests/behat/features/mw_replay.feature index 85d55cd..0508b41 100644 --- a/stepup/tests/behat/features/mw_replay.feature +++ b/stepup/tests/behat/features/mw_replay.feature @@ -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 diff --git a/stepup/tests/behat/fixtures/deprovision.sql b/stepup/tests/behat/fixtures/deprovision.sql new file mode 100644 index 0000000..ed4ee45 --- /dev/null +++ b/stepup/tests/behat/fixtures/deprovision.sql @@ -0,0 +1,244 @@ +-- MySQL dump 10.13 Distrib 5.7.23, for Linux (x86_64) +-- +-- Host: 127.0.0.1 Database: middleware_test +-- ------------------------------------------------------ +-- Server version 5.5.5-10.0.35-MariaDB-wsrep + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `event_stream` +-- + +DROP TABLE IF EXISTS `event_stream`; +/*!40101 SET @saved_cs_client=@@character_set_client */; +/*!40101 SET character_set_client=utf8 */; +CREATE TABLE `event_stream` +( + `uuid` varchar(36) COLLATE utf8_unicode_ci NOT NULL, + `playhead` int(11) NOT NULL, + `metadata` text COLLATE utf8_unicode_ci NOT NULL, + `payload` longtext COLLATE utf8_unicode_ci NOT NULL, + `recorded_on` varchar(32) COLLATE utf8_unicode_ci NOT NULL, + `type` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`uuid`, `playhead`), + KEY `type` (`type`) +) ENGINE=InnoDB + DEFAULT CHARSET=utf8 + COLLATE=utf8_unicode_ci; +/*!40101 SET character_set_client=@saved_cs_client */; + +-- +-- Dumping data for table `event_stream` +-- + +LOCK TABLES `event_stream` WRITE; +/*!40000 ALTER TABLE `event_stream` + DISABLE KEYS */; + +insert into event_stream (uuid, playhead, metadata, payload, recorded_on, type) 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"}}', '2024-12-12T09:52:59.694250+00:00', 'Surfnet.Stepup.Configuration.Event.NewConfigurationCreatedEvent'); +insert into event_stream (uuid, playhead, metadata, payload, recorded_on, type) values ('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>