From 82bed25ebedc96e485667aff1febbcfe35b3f937 Mon Sep 17 00:00:00 2001 From: Bas Date: Mon, 2 Dec 2024 13:43:24 +0100 Subject: [PATCH] Add dedicated replay test --- stepup/tests/behat/config/behat.yml | 1 + .../features/bootstrap/FeatureContext.php | 2 +- .../features/bootstrap/ReplayContext.php | 44 ++++++++++ stepup/tests/behat/features/replay.feature | 11 +++ stepup/tests/behat/fixtures/eventstream.sql | 84 +++++++++++++++++++ 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 stepup/tests/behat/features/bootstrap/ReplayContext.php create mode 100644 stepup/tests/behat/features/replay.feature create mode 100644 stepup/tests/behat/fixtures/eventstream.sql diff --git a/stepup/tests/behat/config/behat.yml b/stepup/tests/behat/config/behat.yml index 2735079..07490ba 100644 --- a/stepup/tests/behat/config/behat.yml +++ b/stepup/tests/behat/config/behat.yml @@ -22,6 +22,7 @@ default: raUrl: 'https://ra.dev.openconext.local' - ApiFeatureContext: apiUrl: 'https://middleware.dev.openconext.local' + - ReplayContext: ~ - Behat\MinkExtension\Context\MinkContext extensions: diff --git a/stepup/tests/behat/features/bootstrap/FeatureContext.php b/stepup/tests/behat/features/bootstrap/FeatureContext.php index 3370baa..d1f21d5 100644 --- a/stepup/tests/behat/features/bootstrap/FeatureContext.php +++ b/stepup/tests/behat/features/bootstrap/FeatureContext.php @@ -45,7 +45,7 @@ class FeatureContext implements Context */ private $institutionConfiguration; - private static function execCommand(string $command): void + public static function execCommand(string $command): void { $output = []; $returnCode = -1; diff --git a/stepup/tests/behat/features/bootstrap/ReplayContext.php b/stepup/tests/behat/features/bootstrap/ReplayContext.php new file mode 100644 index 0000000..85e49fe --- /dev/null +++ b/stepup/tests/behat/features/bootstrap/ReplayContext.php @@ -0,0 +1,44 @@ +getEnvironment(); + + $this->minkContext = $environment->getContext(MinkContext::class); + } + + /** + * @Given a replay is performed + */ + public function replay() + { + // Generate test databases + echo "Preparing test schemas\n"; + FeatureContext::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:drop --em=middleware --env=smoketest --force'); + FeatureContext::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:drop --em=gateway --env=smoketest --force'); + FeatureContext::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:create --em=middleware --env=smoketest'); + FeatureContext::execCommand('docker exec -t stepup-middleware-1 bin/console doctrine:schema:create --em=gateway --env=smoketest'); + + // 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"); + + // Perform an event replay + echo "Replaying event stream\n"; + FeatureContext::execCommand("docker exec -t stepup-middleware-1 bin/console middleware:event:replay --env=smoketest_event_replay --no-interaction -vvv"); + } +} diff --git a/stepup/tests/behat/features/replay.feature b/stepup/tests/behat/features/replay.feature new file mode 100644 index 0000000..00c60a3 --- /dev/null +++ b/stepup/tests/behat/features/replay.feature @@ -0,0 +1,11 @@ +Feature: A replay is performed on Middleware + In order to replay an event stream + On the command line + I expect tha 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 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 + And the "items" property should contain 1 items diff --git a/stepup/tests/behat/fixtures/eventstream.sql b/stepup/tests/behat/fixtures/eventstream.sql new file mode 100644 index 0000000..f9126eb --- /dev/null +++ b/stepup/tests/behat/fixtures/eventstream.sql @@ -0,0 +1,84 @@ +-- 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` VALUES ('0007699b-7a29-4526-9e08-fe291806361f',0,'{\"class\":\"Broadway\\\\Domain\\\\Metadata\",\"payload\":[]}','{\"class\":\"Surfnet\\\\Stepup\\\\Identity\\\\Event\\\\IdentityCreatedEvent\",\"payload\":{\"id\":\"0007699b-7a29-4526-9e08-fe291806361f\",\"institution\":\"dev.openconext.local\",\"name_id\":\"urn:collab:person:dev.openconext.local:sraa2\",\"preferred_locale\":\"en_GB\"}}','2023-09-14T12:22:22.541496+00:00','Surfnet.Stepup.Identity.Event.IdentityCreatedEvent'),('0007699b-7a29-4526-9e08-fe291806361f',1,'{\"class\":\"Broadway\\\\Domain\\\\Metadata\",\"payload\":[]}','{\"class\":\"Surfnet\\\\Stepup\\\\Identity\\\\Event\\\\YubikeySecondFactorBootstrappedEvent\",\"payload\":{\"identity_id\":\"0007699b-7a29-4526-9e08-fe291806361f\",\"name_id\":\"urn:collab:person:dev.openconext.local:sraa2\",\"identity_institution\":\"dev.openconext.local\",\"preferred_locale\":\"en_GB\",\"second_factor_id\":\"f2b1e616-ecde-458b-9f12-1536ad63ded0\"}}','2023-09-14T12:22:22.545350+00:00','Surfnet.Stepup.Identity.Event.YubikeySecondFactorBootstrappedEvent'),('12345678-abcd-4321-abcd-123456789012',0,'{\"class\":\"Broadway\\\\Domain\\\\Metadata\",\"payload\":[]}','{\"class\":\"Surfnet\\\\Stepup\\\\Configuration\\\\Event\\\\NewConfigurationCreatedEvent\",\"payload\":{\"id\":\"12345678-abcd-4321-abcd-123456789012\"}}','2023-07-19T06:46:34.940735+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>