diff --git a/ci/qa/phpstan-baseline.php b/ci/qa/phpstan-baseline.php index 7d9d5c3bf..1d82bb98e 100644 --- a/ci/qa/phpstan-baseline.php +++ b/ci/qa/phpstan-baseline.php @@ -2871,11 +2871,6 @@ 'count' => 2, 'path' => __DIR__ . '/../../src/Surfnet/ServiceProviderDashboard/Domain/ValueObject/Ticket.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Parameter \\#2 \\$manageId of class Surfnet\\\\ServiceProviderDashboard\\\\Domain\\\\ValueObject\\\\Ticket constructor expects string, string\\|null given\\.$#', - 'count' => 2, - 'path' => __DIR__ . '/../../src/Surfnet/ServiceProviderDashboard/Domain/ValueObject/Ticket.php', -]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#3 \\$entityName of class Surfnet\\\\ServiceProviderDashboard\\\\Domain\\\\ValueObject\\\\Ticket constructor expects string, string\\|null given\\.$#', 'count' => 2, diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/PublishEntityTestCommand.php b/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/PublishEntityTestCommand.php index f59777381..e15646bfd 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/PublishEntityTestCommand.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/PublishEntityTestCommand.php @@ -28,6 +28,7 @@ class PublishEntityTestCommand implements Command public function __construct( #[Assert\Type(ManageEntity::class)] private readonly ManageEntity $manageEntity, + private readonly Contact $applicant, ) { } @@ -35,4 +36,9 @@ public function getManageEntity(): ManageEntity { return $this->manageEntity; } + + public function getApplicant(): Contact + { + return $this->applicant; + } } diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/ResetOidcSecretCommand.php b/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/ResetOidcSecretCommand.php index f3849ed41..ce9110c1f 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/ResetOidcSecretCommand.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/ResetOidcSecretCommand.php @@ -19,6 +19,7 @@ namespace Surfnet\ServiceProviderDashboard\Application\Command\Entity; use Surfnet\ServiceProviderDashboard\Application\Command\Command; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; use Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\Validator\Constraints as SpDashboardAssert; @@ -26,6 +27,7 @@ class ResetOidcSecretCommand implements Command { public function __construct( private readonly ManageEntity $manageEntity, + private readonly Contact $applicant, ) { } @@ -33,4 +35,9 @@ public function getManageEntity(): ManageEntity { return $this->manageEntity; } + + public function getApplicant(): Contact + { + return $this->applicant; + } } diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/UpdateEntityAclCommand.php b/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/UpdateEntityAclCommand.php index 1c8dfbb19..85a5f3cc0 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/UpdateEntityAclCommand.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/UpdateEntityAclCommand.php @@ -19,6 +19,7 @@ namespace Surfnet\ServiceProviderDashboard\Application\Command\Entity; use Surfnet\ServiceProviderDashboard\Application\Command\Command; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact; use Surfnet\ServiceProviderDashboard\Domain\Entity\IdentityProvider; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; use Surfnet\ServiceProviderDashboard\Domain\Entity\Service; @@ -37,6 +38,7 @@ public function __construct( ])] private array $selected, private bool $selectAll, + private readonly Contact $applicant, ) { } @@ -73,4 +75,9 @@ public function setSelectAll($selectAll): void { $this->selectAll = (bool)$selectAll; } + + public function getApplicant(): Contact + { + return $this->applicant; + } } diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/UpdateEntityIdpsCommand.php b/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/UpdateEntityIdpsCommand.php index 69881d5bd..687813545 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/UpdateEntityIdpsCommand.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Command/Entity/UpdateEntityIdpsCommand.php @@ -21,6 +21,7 @@ namespace Surfnet\ServiceProviderDashboard\Application\Command\Entity; use Surfnet\ServiceProviderDashboard\Application\Command\Command; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact; use Surfnet\ServiceProviderDashboard\Domain\Entity\IdentityProvider; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; use Symfony\Component\Validator\Constraints as Assert; @@ -45,6 +46,7 @@ public function __construct( new Assert\Type(type: IdentityProvider::class), ])] public array $institutionEntities, + public readonly Contact $applicant, ) { } } diff --git a/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/PublishEntityProductionCommandHandler.php b/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/PublishEntityProductionCommandHandler.php index 294d6687c..13fc13820 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/PublishEntityProductionCommandHandler.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/PublishEntityProductionCommandHandler.php @@ -27,6 +27,7 @@ use Surfnet\ServiceProviderDashboard\Application\Service\MailService; use Surfnet\ServiceProviderDashboard\Application\Service\TicketService; use Surfnet\ServiceProviderDashboard\Domain\Entity\Constants; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\JiraTicketNumber; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; use Surfnet\ServiceProviderDashboard\Domain\Repository\PublishEntityRepository; use Surfnet\ServiceProviderDashboard\Infrastructure\HttpClient\Exceptions\RuntimeException\PublishMetadataException; @@ -80,17 +81,13 @@ public function handle(PublishProductionCommandInterface $command): void $entity->getMetaData()->getNameEn() ) ); - $publishResponse = $this->publishClient->publish($entity, $pristineEntity); + $publishResponse = $this->publishClient->publish( + $entity, + $pristineEntity, + $command->getApplicant(), + ); if (array_key_exists('id', $publishResponse)) { $entity->setId($publishResponse['id']); - - $this->logger->info( - sprintf( - 'Updating status of "%s" to published', - $entity->getMetaData()->getNameEn() - ) - ); - // No need to create a Jira ticket when resetting the client secret if ($command instanceof PublishEntityProductionCommand && !$command->isClientReset()) { $this->ticketService->createJiraTicket( @@ -101,6 +98,12 @@ public function handle(PublishProductionCommandInterface $command): void $this->descriptionTranslationKey ); } + $this->logger->info( + sprintf( + 'Updating status of "%s" to published', + $entity->getMetaData()->getNameEn() + ) + ); } else { $this->logger->error( sprintf( diff --git a/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/PublishEntityTestCommandHandler.php b/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/PublishEntityTestCommandHandler.php index 3d1ea33fe..ebbe5c5c1 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/PublishEntityTestCommandHandler.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/PublishEntityTestCommandHandler.php @@ -24,6 +24,8 @@ use Surfnet\ServiceProviderDashboard\Application\Exception\InvalidArgumentException; use Surfnet\ServiceProviderDashboard\Application\Service\EntityServiceInterface; use Surfnet\ServiceProviderDashboard\Domain\Entity\Constants; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\JiraTicketNumber; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; use Surfnet\ServiceProviderDashboard\Domain\Repository\PublishEntityRepository; use Surfnet\ServiceProviderDashboard\Infrastructure\HttpClient\Exceptions\RuntimeException\PublishMetadataException; @@ -60,7 +62,11 @@ public function handle(PublishEntityTestCommand $command): void ) ); - $publishResponse = $this->publishClient->publish($entity, $pristineEntity); + $publishResponse = $this->publishClient->publish( + $entity, + $pristineEntity, + $command->getApplicant(), + ); if (array_key_exists('id', $publishResponse)) { if ($this->isNewResourceServer($entity)) { $this->requestStack->getSession()->getFlashBag()->add('wysiwyg', 'entity.list.oidcng_connection.info.html'); diff --git a/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/ResetOidcSecretCommandHandler.php b/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/ResetOidcSecretCommandHandler.php index 8cf6d5488..1be947f6b 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/ResetOidcSecretCommandHandler.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/ResetOidcSecretCommandHandler.php @@ -68,7 +68,7 @@ public function handle(ResetOidcSecretCommand $command): void $publishCommand->markPublishClientReset(); $this->commandBus->handle($publishCommand); } elseif ($entity->getEnvironment() === Constants::ENVIRONMENT_TEST) { - $publishCommand = new PublishEntityTestCommand($entity); + $publishCommand = new PublishEntityTestCommand($entity, $command->getApplicant()); $this->commandBus->handle($publishCommand); } if (!$entity->isExcludedFromPush()) { diff --git a/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/UpdateEntityAclCommandHandler.php b/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/UpdateEntityAclCommandHandler.php index 92680631d..49179e68f 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/UpdateEntityAclCommandHandler.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/UpdateEntityAclCommandHandler.php @@ -54,7 +54,7 @@ public function handle(UpdateEntityAclCommand $command): void $allowedIdps = new AllowedIdentityProviders($idps, $command->isSelectAll()); $entity->getAllowedIdentityProviders()->merge($allowedIdps); try { - $this->publishClient->publish($entity, $entity, 'ACL'); + $this->publishClient->publish($entity, $entity, $command->getApplicant(), 'ACL'); } catch (PublishMetadataException $e) { $this->logger->error( sprintf( diff --git a/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/UpdateEntityIdpsCommandHandler.php b/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/UpdateEntityIdpsCommandHandler.php index d8fdf4882..06bc5de3e 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/UpdateEntityIdpsCommandHandler.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/CommandHandler/Entity/UpdateEntityIdpsCommandHandler.php @@ -58,7 +58,7 @@ public function handle(UpdateEntityIdpsCommand $command): void $allowedIdps = new AllowedIdentityProviders($idps, $allowedAll); $entity->getAllowedIdentityProviders()->merge($allowedIdps); try { - $this->publishClient->publish($entity, $entity, 'ACL'); + $this->publishClient->publish($entity, $entity, $command->applicant, 'ACL'); } catch (Exception $e) { $this->logger->error( sprintf( diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/GeneratorInterface.php b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/GeneratorInterface.php index c4b98043c..81dfdfc2f 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/GeneratorInterface.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/GeneratorInterface.php @@ -28,7 +28,11 @@ interface GeneratorInterface /** * Convert a new, unpublished entity to json-serializable array. */ - public function generateForNewEntity(ManageEntity $entity, string $workflowState): array; + public function generateForNewEntity( + ManageEntity $entity, + string $workflowState, + Contact $contact, + ): array; /** * Convert entity to an array for the manage merge-write API call. diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/JsonGenerator.php b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/JsonGenerator.php index 5ddfedc04..d73e1a5c7 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/JsonGenerator.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/JsonGenerator.php @@ -25,6 +25,7 @@ use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact as ContactEntity; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\ChangeRequestRevisionNote; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\Contact; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\EntityCreationRevisionNote; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\JiraTicketNumber; use Surfnet\ServiceProviderDashboard\Domain\Entity\EntityDiff; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; @@ -44,13 +45,22 @@ public function __construct( ) { } - public function generateForNewEntity(ManageEntity $entity, string $workflowState): array - { + public function generateForNewEntity( + ManageEntity $entity, + string $workflowState, + ContactEntity $contact, + ): array { // the type for entities is always saml because manage is using saml internally - return [ + $payload = [ 'data' => $this->generateDataForNewEntity($entity, $workflowState), 'type' => 'saml20_sp', ]; + $payload['data']['revisionnote'] = (string) new EntityCreationRevisionNote( + $entity->getComments(), + $contact->getDisplayName(), + $contact->getEmailAddress(), + ); + return $payload; } public function generateForExistingEntity( @@ -75,20 +85,22 @@ public function generateEntityChangeRequest( ContactEntity $contact, JiraTicketNumber $jiraTicketNumber, ): array { + $revisionNote = (string) new ChangeRequestRevisionNote( + $entity->getComments(), + $contact->getDisplayName(), + $contact->getEmailAddress(), + $jiraTicketNumber, + ); $payload = [ 'metaDataId' => $entity->getId(), 'type' => 'saml20_sp', 'pathUpdates' => $this->generateForChangeRequest($entity, $differences), 'auditData' => [ 'user' => $contact->getEmailAddress(), + 'notes' => $revisionNote, ], ]; - $payload['note'] = (string) new ChangeRequestRevisionNote( - $entity->getComments(), - $contact->getDisplayName(), - $contact->getEmailAddress(), - $jiraTicketNumber, - ); + $payload['note'] = $revisionNote; return $payload; } diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/JsonGeneratorStrategy.php b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/JsonGeneratorStrategy.php index d5a18f639..9a16d8f3d 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/JsonGeneratorStrategy.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/JsonGeneratorStrategy.php @@ -50,9 +50,16 @@ public function addStrategy($identifier, GeneratorInterface $generator): void /** * @throws JsonGeneratorStrategyNotFoundException */ - public function generateForNewEntity(ManageEntity $entity, string $workflowState): array - { - return $this->getStrategy($entity->getProtocol()->getProtocol())->generateForNewEntity($entity, $workflowState); + public function generateForNewEntity( + ManageEntity $entity, + string $workflowState, + Contact $contact, + ): array { + return $this->getStrategy($entity->getProtocol()->getProtocol())->generateForNewEntity( + $entity, + $workflowState, + $contact, + ); } /** diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OauthClientCredentialsClientJsonGenerator.php b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OauthClientCredentialsClientJsonGenerator.php index 77bf7935e..201efcfbe 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OauthClientCredentialsClientJsonGenerator.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OauthClientCredentialsClientJsonGenerator.php @@ -24,6 +24,7 @@ use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact as ContactEntity; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\ChangeRequestRevisionNote; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\Contact; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\EntityCreationRevisionNote; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\JiraTicketNumber; use Surfnet\ServiceProviderDashboard\Domain\Entity\EntityDiff; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; @@ -49,13 +50,22 @@ public function __construct( ) { } - public function generateForNewEntity(ManageEntity $entity, string $workflowState): array - { + public function generateForNewEntity( + ManageEntity $entity, + string $workflowState, + ContactEntity $contact, + ): array { // The Oauth Client Credential Client is actually an oidc10_rp entity - return [ + $payload = [ 'data' => $this->generateDataForNewEntity($entity, $workflowState), 'type' => 'oidc10_rp', ]; + $payload['data']['revisionnote'] = (string) new EntityCreationRevisionNote( + $entity->getComments(), + $contact->getDisplayName(), + $contact->getEmailAddress(), + ); + return $payload; } public function generateForExistingEntity( @@ -96,23 +106,22 @@ public function generateEntityChangeRequest( ContactEntity $contact, JiraTicketNumber $jiraTicketNumber, ): array { + $revisionNote = (string) new ChangeRequestRevisionNote( + $entity->getComments(), + $contact->getDisplayName(), + $contact->getEmailAddress(), + $jiraTicketNumber, + ); $payload = [ 'metaDataId' => $entity->getId(), 'type' => 'oidc10_rp', 'pathUpdates' => $this->generateForChangeRequest($differences), 'auditData' => [ 'user' => $contact->getEmailAddress(), + 'notes' => $revisionNote ], ]; - - $payload['note'] = (string) new ChangeRequestRevisionNote( - $entity->getComments(), - $contact->getDisplayName(), - $contact->getEmailAddress(), - $jiraTicketNumber, - ); - - + $payload['note'] = $revisionNote; return $payload; } diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OidcngJsonGenerator.php b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OidcngJsonGenerator.php index 7e4670f73..57a8e9fa1 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OidcngJsonGenerator.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OidcngJsonGenerator.php @@ -25,6 +25,7 @@ use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact as ContactEntity; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\ChangeRequestRevisionNote; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\Contact; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\EntityCreationRevisionNote; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\JiraTicketNumber; use Surfnet\ServiceProviderDashboard\Domain\Entity\EntityDiff; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; @@ -49,13 +50,22 @@ public function __construct( ) { } - public function generateForNewEntity(ManageEntity $entity, string $workflowState): array - { + public function generateForNewEntity( + ManageEntity $entity, + string $workflowState, + ContactEntity $contact, + ) : array { // the type for entities is always saml because manage is using saml internally - return [ + $payload = [ 'data' => $this->generateDataForNewEntity($entity, $workflowState), 'type' => 'oidc10_rp', ]; + $payload['data']['revisionnote'] = (string) new EntityCreationRevisionNote( + $entity->getComments(), + $contact->getDisplayName(), + $contact->getEmailAddress(), + ); + return $payload; } public function generateForExistingEntity( @@ -77,21 +87,23 @@ public function generateEntityChangeRequest( ContactEntity $contact, JiraTicketNumber $jiraTicketNumber, ): array { + $revisionNote = (string) new ChangeRequestRevisionNote( + $entity->getComments(), + $contact->getDisplayName(), + $contact->getEmailAddress(), + $jiraTicketNumber, + ); $payload = [ 'metaDataId' => $entity->getId(), 'type' => 'oidc10_rp', 'pathUpdates' => $this->generateForChangeRequest($differences, $entity), 'auditData' => [ 'user' => $contact->getEmailAddress(), + 'notes' => $revisionNote, ], ]; - $payload['note'] = (string) new ChangeRequestRevisionNote( - $entity->getComments(), - $contact->getDisplayName(), - $contact->getEmailAddress(), - $jiraTicketNumber, - ); + $payload['note'] = $revisionNote; return $payload; } diff --git a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OidcngResourceServerJsonGenerator.php b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OidcngResourceServerJsonGenerator.php index f57fb9dcb..aa4a9741f 100644 --- a/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OidcngResourceServerJsonGenerator.php +++ b/src/Surfnet/ServiceProviderDashboard/Application/Metadata/OidcngResourceServerJsonGenerator.php @@ -25,6 +25,7 @@ use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact as ContactEntity; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\ChangeRequestRevisionNote; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\Contact; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\EntityCreationRevisionNote; use Surfnet\ServiceProviderDashboard\Domain\Entity\Entity\JiraTicketNumber; use Surfnet\ServiceProviderDashboard\Domain\Entity\EntityDiff; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; @@ -45,12 +46,21 @@ public function __construct( ) { } - public function generateForNewEntity(ManageEntity $entity, string $workflowState): array - { - return [ + public function generateForNewEntity( + ManageEntity $entity, + string $workflowState, + ContactEntity $contact, + ): array { + $payload = [ 'data' => $this->generateDataForNewEntity($entity, $workflowState), 'type' => 'oauth20_rs', ]; + $payload['data']['revisionnote'] = (string) new EntityCreationRevisionNote( + $entity->getComments(), + $contact->getDisplayName(), + $contact->getEmailAddress(), + ); + return $payload; } public function generateForExistingEntity( @@ -73,22 +83,22 @@ public function generateEntityChangeRequest( ContactEntity $contact, JiraTicketNumber $jiraTicketNumber, ): array { + $revisionNote = (string) new ChangeRequestRevisionNote( + $entity->getComments(), + $contact->getDisplayName(), + $contact->getEmailAddress(), + $jiraTicketNumber, + ); $payload = [ 'metaDataId' => $entity->getId(), 'type' => 'oauth20_rs', 'pathUpdates' => $this->generateForChangeRequest($differences), 'auditData' => [ 'user' => $contact->getEmailAddress(), + 'notes' => $revisionNote, ], ]; - - $payload['note'] = (string) new ChangeRequestRevisionNote( - $entity->getComments(), - $contact->getDisplayName(), - $contact->getEmailAddress(), - $jiraTicketNumber, - ); - + $payload['note'] = $revisionNote; return $payload; } diff --git a/src/Surfnet/ServiceProviderDashboard/Domain/Entity/Entity/EntityCreationRevisionNote.php b/src/Surfnet/ServiceProviderDashboard/Domain/Entity/Entity/EntityCreationRevisionNote.php new file mode 100644 index 000000000..0a4850a86 --- /dev/null +++ b/src/Surfnet/ServiceProviderDashboard/Domain/Entity/Entity/EntityCreationRevisionNote.php @@ -0,0 +1,56 @@ +comments === null) { + $this->comments = 'No comment provided'; + } + + + return sprintf( + self::REVISION_NOTE_FORMAT, + $this->commonName, + $this->emailAddress, + $dateTime->format(DateTimeImmutable::ATOM), + $this->comments, + ); + } +} diff --git a/src/Surfnet/ServiceProviderDashboard/Domain/Repository/PublishEntityRepository.php b/src/Surfnet/ServiceProviderDashboard/Domain/Repository/PublishEntityRepository.php index 43798d4a5..f12abee6b 100644 --- a/src/Surfnet/ServiceProviderDashboard/Domain/Repository/PublishEntityRepository.php +++ b/src/Surfnet/ServiceProviderDashboard/Domain/Repository/PublishEntityRepository.php @@ -18,6 +18,7 @@ namespace Surfnet\ServiceProviderDashboard\Domain\Repository; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; interface PublishEntityRepository @@ -26,7 +27,12 @@ interface PublishEntityRepository * Publishes the Entity to a Service registry (like Manage, ..) This action might also result in the * sending of a mail message to a service desk who in turn can publish the entity in the registry. */ - public function publish(ManageEntity $entity, ?ManageEntity $pristineEntity, string $part = ''): mixed; + public function publish( + ManageEntity $entity, + ?ManageEntity $pristineEntity, + Contact $contact, + string $part = '', + ): mixed; /** * Push the metadata from Manage to Engineblock diff --git a/src/Surfnet/ServiceProviderDashboard/Domain/ValueObject/Ticket.php b/src/Surfnet/ServiceProviderDashboard/Domain/ValueObject/Ticket.php index fc6d0a8eb..800098383 100644 --- a/src/Surfnet/ServiceProviderDashboard/Domain/ValueObject/Ticket.php +++ b/src/Surfnet/ServiceProviderDashboard/Domain/ValueObject/Ticket.php @@ -31,7 +31,7 @@ class Ticket public function __construct( private readonly string $entityId, - private readonly string $manageId, + private readonly ?string $manageId, private readonly string $entityName, private readonly string $summaryTranslationKey, private readonly string $descriptionTranslationKey, @@ -95,7 +95,7 @@ public function getEntityId(): string return $this->entityId; } - public function getManageId(): string + public function getManageId(): ?string { return $this->manageId; } diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityAclController.php b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityAclController.php index 017272415..c427a4591 100644 --- a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityAclController.php +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityAclController.php @@ -67,6 +67,7 @@ public function idps(Request $request, string $serviceId, string $id): Response $entity, $selectedIdps, $selectedIdps, + $this->authorizationService->getContact() ); $form = $this->createForm(IdpEntityType::class, $command); @@ -106,7 +107,8 @@ public function acl(Request $request, string $serviceId, string $id): Response $command = new UpdateEntityAclCommand( $entity, $selectedIdps, - $entity->getAllowedIdentityProviders()->isAllowAll() + $entity->getAllowedIdentityProviders()->isAllowAll(), + $this->authorizationService->getContact(), ); $form = $this->createForm(AclEntityType::class, $command); diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityControllerTrait.php b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityControllerTrait.php index d06f7cb0d..d327d6bf6 100644 --- a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityControllerTrait.php +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityControllerTrait.php @@ -151,16 +151,15 @@ private function createPublishEntityCommandFromEntity( ?ManageEntity $entity, bool $isEntityChangeRequest, ): PublishEntityTestCommand|EntityChangeRequestCommand|PublishEntityProductionCommand { + $applicant = $this->authorizationService->getContact(); switch (true) { case $entity->getEnvironment() === Constants::ENVIRONMENT_TEST: - $publishEntityCommand = new PublishEntityTestCommand($entity); + $publishEntityCommand = new PublishEntityTestCommand($entity, $applicant); break; case $isEntityChangeRequest: - $applicant = $this->authorizationService->getContact(); $publishEntityCommand = new EntityChangeRequestCommand($entity, $applicant); break; case $entity->getEnvironment() === Constants::ENVIRONMENT_PRODUCTION: - $applicant = $this->authorizationService->getContact(); $publishEntityCommand = new PublishEntityProductionCommand($entity, $applicant); break; default: diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityResetSecretController.php b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityResetSecretController.php index 131ff3a04..508dcb723 100644 --- a/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityResetSecretController.php +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/DashboardBundle/Controller/EntityResetSecretController.php @@ -57,8 +57,8 @@ public function reset(Request $request, int $serviceId, string $manageId, string } // Verify the Entity Service Id is one of the logged in users services $this->authorizationService->assertServiceIdAllowed($entityServiceId); - - $resetOidcSecretCommand = new ResetOidcSecretCommand($manageEntity); + $applicant = $this->authorizationService->getContact(); + $resetOidcSecretCommand = new ResetOidcSecretCommand($manageEntity, $applicant); try { $this->commandBus->handle($resetOidcSecretCommand); } catch (Exception) { diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/Jira/Repository/DevelopmentIssueRepository.php b/src/Surfnet/ServiceProviderDashboard/Infrastructure/Jira/Repository/DevelopmentIssueRepository.php index c952f50d4..bae181918 100644 --- a/src/Surfnet/ServiceProviderDashboard/Infrastructure/Jira/Repository/DevelopmentIssueRepository.php +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/Jira/Repository/DevelopmentIssueRepository.php @@ -105,7 +105,7 @@ public function createIssueFrom(Ticket $ticket): Issue if ($this->failIssueCreation) { throw new JiraException('Unable to write the Jira issue (failure was requested by calling shouldFailCreateIssue)'); } - $issue = new Issue($ticket->getManageId(), $ticket->getIssueType(), Issue::STATUS_OPEN); + $issue = new Issue($ticket->getManageId() ?: "manage-id", $ticket->getIssueType(), Issue::STATUS_OPEN); $this->data[$ticket->getManageId()] = $issue; $this->storeData(); return $issue; @@ -117,7 +117,7 @@ public function createIssueFromConnectionRequest(Ticket $ticket): Issue if ($this->failIssueCreation) { throw new JiraException('Unable to write the Jira issue (failure was requested by calling shouldFailCreateIssue)'); } - $issue = new Issue($ticket->getManageId(), $ticket->getIssueType(), Issue::STATUS_OPEN); + $issue = new Issue($ticket->getManageId() ?: "manage-id", $ticket->getIssueType(), Issue::STATUS_OPEN); $this->data[$ticket->getManageId()] = $issue; $this->storeData(); return $issue; diff --git a/src/Surfnet/ServiceProviderDashboard/Infrastructure/Manage/Client/PublishEntityClient.php b/src/Surfnet/ServiceProviderDashboard/Infrastructure/Manage/Client/PublishEntityClient.php index e91f0441c..28885c931 100644 --- a/src/Surfnet/ServiceProviderDashboard/Infrastructure/Manage/Client/PublishEntityClient.php +++ b/src/Surfnet/ServiceProviderDashboard/Infrastructure/Manage/Client/PublishEntityClient.php @@ -21,6 +21,7 @@ use Psr\Log\LoggerInterface; use Surfnet\ServiceProviderDashboard\Application\Metadata\JsonGeneratorStrategy; use Surfnet\ServiceProviderDashboard\Application\ViewObject\Apis\ApiConfig; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; use Surfnet\ServiceProviderDashboard\Infrastructure\HttpClient\Exceptions\HttpException\HttpException; use Surfnet\ServiceProviderDashboard\Infrastructure\HttpClient\Exceptions\RuntimeException\PublishMetadataException; @@ -44,8 +45,12 @@ public function __construct( * * @SuppressWarnings(PHPMD.ElseExpression) */ - public function publish(ManageEntity $entity, ?ManageEntity $pristineEntity, string $updatedPart = ''): mixed - { + public function publish( + ManageEntity $entity, + ?ManageEntity $pristineEntity, + Contact $contact, + string $part = '' + ): mixed { try { if (!$entity->isManageEntity()) { $this->logger->info(sprintf('Creating new entity \'%s\' in manage', $entity->getId())); @@ -53,7 +58,8 @@ public function publish(ManageEntity $entity, ?ManageEntity $pristineEntity, str json_encode( $this->generator->generateForNewEntity( $entity, - $this->manageConfig->getPublicationStatus()->getStatus() + $this->manageConfig->getPublicationStatus()->getStatus(), + $contact, ) ), '/manage/api/internal/metadata' @@ -67,7 +73,7 @@ public function publish(ManageEntity $entity, ?ManageEntity $pristineEntity, str $entity, $diff, $this->manageConfig->getPublicationStatus()->getStatus(), - $updatedPart + $part ) ); diff --git a/tests/integration/Application/CommandHandler/Entity/PublishEntityProductionCommandHandlerTest.php b/tests/integration/Application/CommandHandler/Entity/PublishEntityProductionCommandHandlerTest.php index 29d463452..fe4b3a54f 100644 --- a/tests/integration/Application/CommandHandler/Entity/PublishEntityProductionCommandHandlerTest.php +++ b/tests/integration/Application/CommandHandler/Entity/PublishEntityProductionCommandHandlerTest.php @@ -108,14 +108,6 @@ public function test_it_can_publish() $manageEntity->shouldReceive('isManageEntity')->andReturnTrue(); $manageEntity->shouldReceive('getEnvironment')->andReturn('production'); - $this->publishEntityClient - ->shouldReceive('publish') - ->once() - ->with($manageEntity, $manageEntity) - ->andReturn([ - 'id' => '123', - ]); - $manageEntity ->shouldReceive('getMetaData->getEntityId') ->andReturn('https://app.example.com/'); @@ -147,6 +139,15 @@ public function test_it_can_publish() $this->entityService->shouldReceive('getPristineManageEntityById')->andReturn($manageEntity); $applicant = new Contact('john:doe', 'john@example.com', 'John Doe'); + + $this->publishEntityClient + ->shouldReceive('publish') + ->once() + ->with($manageEntity, $manageEntity, $applicant) + ->andReturn([ + 'id' => '123', + ]); + $command = new PublishEntityProductionCommand($manageEntity, $applicant); $this->commandHandler->handle($command); } @@ -162,14 +163,6 @@ public function test_it_can_republish() ->shouldReceive('getMetaData->getNameEn') ->andReturn('Test Entity Name'); - $this->publishEntityClient - ->shouldReceive('publish') - ->once() - ->with($manageEntity, $manageEntity) - ->andReturn([ - 'id' => '123', - ]); - $manageEntity ->shouldReceive('getMetaData->getEntityId') ->andReturn('https://app.example.com/'); @@ -204,6 +197,13 @@ public function test_it_can_republish() $applicant = new Contact('john:doe', 'john@example.com', 'John Doe'); + $this->publishEntityClient + ->shouldReceive('publish') + ->once() + ->with($manageEntity, $manageEntity, $applicant) + ->andReturn([ + 'id' => '123', + ]); $command = new PublishEntityProductionCommand($manageEntity, $applicant); $this->commandHandler->handle($command); } @@ -269,15 +269,6 @@ public function test_does_not_create_ticket_when_client_resetting() ->andReturn('Test Entity Name'); $manageEntity->shouldReceive('isManageEntity')->andReturnTrue(); $manageEntity->shouldReceive('getEnvironment')->andReturn('production'); - - $this->publishEntityClient - ->shouldReceive('publish') - ->once() - ->with($manageEntity, $manageEntity) - ->andReturn([ - 'id' => '123', - ]); - $manageEntity ->shouldReceive('getMetaData->getEntityId') ->andReturn('https://app.example.com/'); @@ -309,6 +300,13 @@ public function test_does_not_create_ticket_when_client_resetting() $this->entityService->shouldReceive('getPristineManageEntityById')->andReturn($manageEntity); $applicant = new Contact('john:doe', 'john@example.com', 'John Doe'); + $this->publishEntityClient + ->shouldReceive('publish') + ->once() + ->with($manageEntity, $manageEntity, $applicant) + ->andReturn([ + 'id' => '123', + ]); $command = new PublishEntityProductionCommand($manageEntity, $applicant); $command->markPublishClientReset(); $this->commandHandler->handle($command); diff --git a/tests/integration/Application/CommandHandler/Entity/PublishEntityTestCommandHandlerTest.php b/tests/integration/Application/CommandHandler/Entity/PublishEntityTestCommandHandlerTest.php index cce16526e..184e41acc 100644 --- a/tests/integration/Application/CommandHandler/Entity/PublishEntityTestCommandHandlerTest.php +++ b/tests/integration/Application/CommandHandler/Entity/PublishEntityTestCommandHandlerTest.php @@ -19,6 +19,7 @@ namespace Application\CommandHandler\Entity; use Surfnet\ServiceProviderDashboard\Application\Service\EntityServiceInterface; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact; use Surfnet\ServiceProviderDashboard\Infrastructure\Manage\Client\PublishEntityClient; use Surfnet\ServiceProviderDashboard\Infrastructure\Manage\Client\QueryClient; use Mockery as m; @@ -79,13 +80,6 @@ public function test_it_can_publish_to_manage() ->shouldReceive('info') ->times(1); - $this->client - ->shouldReceive('publish') - ->once() - ->with($manageEntity, $manageEntity) - ->andReturn([ - 'id' => '123', - ]); $manageEntity ->shouldReceive('getAllowedIdentityProviders->getAllowedIdentityProviders') ->andReturn([]); @@ -109,7 +103,14 @@ public function test_it_can_publish_to_manage() $this->entityService ->shouldReceive('getPristineManageEntityById') ->andReturn($manageEntity); - $command = new PublishEntityTestCommand($manageEntity); + $command = new PublishEntityTestCommand($manageEntity, m::mock(Contact::class)); + $this->client + ->shouldReceive('publish') + ->once() + ->with($manageEntity, $manageEntity, $command->getApplicant()) + ->andReturn([ + 'id' => '123', + ]); $this->commandHandler->handle($command); } @@ -147,12 +148,6 @@ public function test_it_handles_failing_publish() ->shouldReceive('error') ->times(1); - $this->client - ->shouldReceive('publish') - ->once() - ->with($manageEntity, $manageEntity) - ->andThrow(PublishMetadataException::class); - $this->requestStack ->shouldReceive('getSession->getFlashBag->add') ->with('error', 'entity.edit.error.publish'); @@ -161,7 +156,14 @@ public function test_it_handles_failing_publish() ->shouldReceive('getPristineManageEntityById') ->andReturn($manageEntity); - $command = new PublishEntityTestCommand($manageEntity); + $command = new PublishEntityTestCommand($manageEntity, m::mock(Contact::class)); + + $this->client + ->shouldReceive('publish') + ->once() + ->with($manageEntity, $manageEntity, $command->getApplicant()) + ->andThrow(PublishMetadataException::class); + $this->commandHandler->handle($command); } } diff --git a/tests/integration/Application/CommandHandler/Entity/ResetOidcSecretCommandHandlerTest.php b/tests/integration/Application/CommandHandler/Entity/ResetOidcSecretCommandHandlerTest.php index aad6b7cf2..924ba0ebb 100644 --- a/tests/integration/Application/CommandHandler/Entity/ResetOidcSecretCommandHandlerTest.php +++ b/tests/integration/Application/CommandHandler/Entity/ResetOidcSecretCommandHandlerTest.php @@ -149,6 +149,6 @@ private function buildCommand( ->shouldReceive('isExcludedFromPush') ->andReturn($isExcludedFromPush); - return new ResetOidcSecretCommand($manageEntity); + return new ResetOidcSecretCommand($manageEntity, m::mock(Contact::class)); } } diff --git a/tests/unit/Application/Metadata/JsonGeneratorStrategyTest.php b/tests/unit/Application/Metadata/JsonGeneratorStrategyTest.php index ec72dc951..e48bb44bc 100644 --- a/tests/unit/Application/Metadata/JsonGeneratorStrategyTest.php +++ b/tests/unit/Application/Metadata/JsonGeneratorStrategyTest.php @@ -25,6 +25,7 @@ use Surfnet\ServiceProviderDashboard\Application\Exception\JsonGeneratorStrategyNotFoundException; use Surfnet\ServiceProviderDashboard\Application\Metadata\GeneratorInterface; use Surfnet\ServiceProviderDashboard\Application\Metadata\JsonGeneratorStrategy; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact; use Surfnet\ServiceProviderDashboard\Domain\Entity\EntityDiff; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; @@ -72,11 +73,11 @@ public function test_generate_for_new_entity() $entity = m::mock(ManageEntity::class); $entity->shouldReceive('getProtocol->getProtocol')->andReturn('saml'); - $result = $this->strategy->generateForNewEntity($entity, 'prodaccepted'); + $result = $this->strategy->generateForNewEntity($entity, 'prodaccepted', m::mock(Contact::class)); $this->assertIsArray($result); $entity->shouldReceive('getProtocol->getProtocol')->andReturn('oidcng'); - $result = $this->strategy->generateForNewEntity($entity, 'prodaccepted'); + $result = $this->strategy->generateForNewEntity($entity, 'prodaccepted', m::mock(Contact::class)); $this->assertIsArray($result); } diff --git a/tests/unit/Application/Metadata/JsonGeneratorTest.php b/tests/unit/Application/Metadata/JsonGeneratorTest.php index 56cad6398..bec31b8cf 100644 --- a/tests/unit/Application/Metadata/JsonGeneratorTest.php +++ b/tests/unit/Application/Metadata/JsonGeneratorTest.php @@ -79,7 +79,10 @@ public function test_it_can_build_saml_entity_metadata_for_new_entities() $this->spDashboardMetadataGenerator ); - $metadata = $generator->generateForNewEntity($this->createManageEntity(), 'testaccepted'); + $contact = m::mock(Contact::class); + $contact->shouldReceive('getDisplayName')->andReturn('John Doe'); + $contact->shouldReceive('getEmailAddress')->andReturn('jd@example.com'); + $metadata = $generator->generateForNewEntity($this->createManageEntity(), 'testaccepted', $contact); $metadata = $metadata['data']; $this->assertEquals('saml20-sp', $metadata['type']); @@ -92,7 +95,7 @@ public function test_it_can_build_saml_entity_metadata_for_new_entities() $this->assertEquals('http://metadata', $metadata['metadataurl']); $this->assertEquals('testaccepted', $metadata['state']); $this->assertEquals('saml20-sp', $metadata['type']); - $this->assertEquals('revisionnote', $metadata['revisionnote']); + $this->assertMatchesRegularExpression('/Entity Created by user John Doe with email address "jd@example.com"\nVia the SPdashboard on .* \nComment: "revisionnote"/', $metadata['revisionnote']); $this->assertEquals(['arp' => 'arp'], $metadata['arp']); $fields = $metadata['metaDataFields']; @@ -155,8 +158,10 @@ public function test_it_can_build_saml_entity_data_for_new_entities() $this->privacyQuestionsMetadataGenerator, $this->spDashboardMetadataGenerator ); - - $data = $generator->generateForNewEntity($this->createManageEntity(), 'prodaccepted'); + $contact = m::mock(Contact::class); + $contact->shouldReceive('getDisplayName')->andReturn('John Doe'); + $contact->shouldReceive('getEmailAddress')->andReturn('jd@example.com'); + $data = $generator->generateForNewEntity($this->createManageEntity(), 'prodaccepted', $contact); $expected = array ( 'data' => @@ -198,11 +203,16 @@ public function test_it_can_build_saml_entity_data_for_new_entities() 'coin:exclude_from_push' => '0' ), 'metadataurl' => 'http://metadata', - 'revisionnote' => 'revisionnote', ), 'type' => 'saml20_sp', ); + // Test the revisionNote separately + $expectedRevisionNote = '/Entity Created by user John Doe with email address "jd@example.com"\nVia the SPdashboard on .* \nComment: "revisionnote"/'; + $actualrevisionNote = $data['data']['revisionnote']; + unset($data['data']['revisionnote']); + $this->assertMatchesRegularExpression($expectedRevisionNote, $actualrevisionNote); + $this->addEmptyAscLocations(1, '', $expected['data']['metaDataFields']); $this->assertEquals($expected, $data); } @@ -416,7 +426,10 @@ public function test_certificate_is_not_required() ->shouldReceive('isProduction') ->andReturn(false); - $data = $generator->generateForNewEntity($entity, 'prodaccepted'); + $contact = m::mock(Contact::class); + $contact->shouldReceive('getDisplayName')->andReturn('John Doe'); + $contact->shouldReceive('getEmailAddress')->andReturn('jd@example.com'); + $data = $generator->generateForNewEntity($entity, 'prodaccepted', $contact); $expected = array ( 'data' => @@ -456,10 +469,16 @@ public function test_certificate_is_not_required() 'coin:institution_guid' => '543b4e5b-76b5-453f-af1e-5648378bb266' ), 'metadataurl' => 'http://metadata', - 'revisionnote' => 'revisionnote', ), 'type' => 'saml20_sp', ); + + // Test the revisionNote separately + $expectedRevisionNote = '/Entity Created by user John Doe with email address "jd@example.com"\nVia the SPdashboard on .* \nComment: "revisionnote"/'; + $actualrevisionNote = $data['data']['revisionnote']; + unset($data['data']['revisionnote']); + $this->assertMatchesRegularExpression($expectedRevisionNote, $actualrevisionNote); + $this->addEmptyAscLocations(1, '', $expected['data']['metaDataFields']); $this->assertEquals($expected, $data); } diff --git a/tests/unit/Application/Metadata/OauthClientCredentialsClientJsonGeneratorTest.php b/tests/unit/Application/Metadata/OauthClientCredentialsClientJsonGeneratorTest.php index 9d2a776f4..f7ee094ab 100644 --- a/tests/unit/Application/Metadata/OauthClientCredentialsClientJsonGeneratorTest.php +++ b/tests/unit/Application/Metadata/OauthClientCredentialsClientJsonGeneratorTest.php @@ -85,8 +85,11 @@ public function test_it_generate_has_revision_note_for_a_new_entity() $this->spDashboardMetadataGenerator ); $entity = $this->createManageEntity(); - $data = $generator->generateForNewEntity($entity, 'prodaccepted'); - $this->assertSame('revisionnote', $data['data']['revisionnote']); + $contact = m::mock(Contact::class); + $contact->shouldReceive('getDisplayName')->andReturn('John Doe'); + $contact->shouldReceive('getEmailAddress')->andReturn('jd@example.com'); + $data = $generator->generateForNewEntity($entity, 'prodaccepted', $contact); + $this->assertMatchesRegularExpression('/Entity Created by user John Doe with email address "jd@example.com"\nVia the SPdashboard on .* \nComment: "revisionnote"/', $data['data']['revisionnote']); } private function createManageEntity() diff --git a/tests/unit/Application/Metadata/OidcngResourceServerJsonGeneratorTest.php b/tests/unit/Application/Metadata/OidcngResourceServerJsonGeneratorTest.php index b2a3389ef..5e2b24710 100644 --- a/tests/unit/Application/Metadata/OidcngResourceServerJsonGeneratorTest.php +++ b/tests/unit/Application/Metadata/OidcngResourceServerJsonGeneratorTest.php @@ -73,8 +73,16 @@ public function test_it_can_build_oidcng_entity_data_for_new_entities() $this->privacyQuestionsMetadataGenerator, $this->spDashboardMetadataGenerator ); + $contact = m::mock(Contact::class); + $contact->shouldReceive('getDisplayName')->andReturn('John Doe'); + $contact->shouldReceive('getEmailAddress')->andReturn('jd@example.com'); + $data = $generator->generateForNewEntity($this->createManageEntity(), 'testaccepted', $contact); + // Test the revisionNote separately + $expectedRevisionNote = '/Entity Created by user John Doe with email address "jd@example.com"\nVia the SPdashboard on .* \nComment: "revisionnote"/'; + $actualrevisionNote = $data['data']['revisionnote']; + unset($data['data']['revisionnote']); + $this->assertMatchesRegularExpression($expectedRevisionNote, $actualrevisionNote); - $data = $generator->generateForNewEntity($this->createManageEntity(), 'testaccepted'); $this->assertEquals( [ 'data' => [ @@ -82,7 +90,6 @@ public function test_it_can_build_oidcng_entity_data_for_new_entities() 'state' => 'testaccepted', 'entityid' => 'entityid', 'active' => true, - 'revisionnote' => 'revisionnote', 'metaDataFields' => [ 'description:en' => 'description en', 'description:nl' => 'description nl', diff --git a/tests/unit/Infrastructure/Manage/Client/PublishEntityClientTest.php b/tests/unit/Infrastructure/Manage/Client/PublishEntityClientTest.php index 82dd7a51a..6d947c737 100644 --- a/tests/unit/Infrastructure/Manage/Client/PublishEntityClientTest.php +++ b/tests/unit/Infrastructure/Manage/Client/PublishEntityClientTest.php @@ -28,6 +28,7 @@ use Psr\Log\NullLogger; use Surfnet\ServiceProviderDashboard\Application\Metadata\JsonGeneratorStrategy; use Surfnet\ServiceProviderDashboard\Application\ViewObject\Apis\ApiConfig as Config; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact; use Surfnet\ServiceProviderDashboard\Domain\Entity\EntityDiff; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; use Surfnet\ServiceProviderDashboard\Infrastructure\HttpClient\Exceptions\RuntimeException\PublishMetadataException; @@ -114,7 +115,7 @@ public function test_it_can_publish_to_manage() ->shouldReceive('generateForNewEntity') ->andReturn(json_decode($json, true)); - $response = $this->client->publish($entity, $entity); + $response = $this->client->publish($entity, $entity, m::mock(Contact::class)); $this->assertEquals('1', $response['id']); } @@ -148,7 +149,7 @@ public function test_it_can_update_to_manage() ->shouldReceive('generateForExistingEntity') ->andReturn(json_decode($json, true)); - $response = $this->client->publish($entity, $entity); + $response = $this->client->publish($entity, $entity, m::mock(Contact::class)); $this->assertEquals('1', $response['id']); } @@ -192,7 +193,7 @@ public function test_it_handles_failing_publish_action() ->shouldReceive('generateForNewEntity') ->andReturn(json_decode($json, true)); - $this->client->publish($entity, $entity); + $this->client->publish($entity, $entity, m::mock(Contact::class)); } public function test_it_can_push_to_engineblock() diff --git a/tests/webtests/EntityCreateOidcngTest.php b/tests/webtests/EntityCreateOidcngTest.php index e2e55dc90..6c4f5e244 100644 --- a/tests/webtests/EntityCreateOidcngTest.php +++ b/tests/webtests/EntityCreateOidcngTest.php @@ -20,6 +20,8 @@ use Facebook\WebDriver\Exception\NoSuchElementException; use Facebook\WebDriver\WebDriverBy; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Constants; +use Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\DataFixtures\ORM\WebTestFixtures; class EntityCreateOidcngTest extends WebTestCase { @@ -96,7 +98,6 @@ public function test_one_redirect_url_is_required() public function test_it_can_publish_the_form() { - $this->markTestSkipped('TODO: add test coverage for IdPs connection page'); $this->testPublicationClient->registerPublishResponse('https://entity-id.test', '{"id":"f1e394b2-08b1-4882-8b32-43876c15c743"}'); $formData = $this->buildValidFormData(); $crawler = self::$pantherClient->request('GET', "/entity/create/2/oidcng/test"); @@ -113,8 +114,26 @@ public function test_it_can_publish_the_form() $this->fillFormField($form, '#dashboard_bundle_entity_type_metadata_redirectUrls .collection-entry input', 'https://redirect-url.example.com'); $this->click($form, '.add_collection_entry'); $this->click($form, '#dashboard_bundle_entity_type_publishButton'); + // Now register the entity in the query client (it is not actuallly stored in Manage, so we need to provide + // test data + $this->registerManageEntity( + Constants::ENVIRONMENT_TEST, + 'oidc10_rp', + 'f1e394b2-08b1-4882-8b32-43876c15c743', + 'The C Team', + 'https://entity-id.test', + '', + WebTestFixtures::TEAMNAME_IBUILDINGS, + ); + $crawler = self::$pantherClient->reload(); + $this->assertOnPage('Connect some Idp\'s to your entity'); + + // Continue without selecting test IdPs + $form = $crawler + ->selectButton('Save') + ->form(); + $crawler = self::$pantherClient->submit($form); - $crawler = self::$pantherClient->refreshCrawler(); $label = $crawler->filter('.monospaced label')->first()->text(); $span = $crawler->filter('.monospaced pre')->first()->text(); // A secret should be displayed @@ -170,6 +189,7 @@ private function buildValidFormData() 'dashboard_bundle_entity_type[metadata][isPublicClient]' => true, 'dashboard_bundle_entity_type[metadata][grants]' => ['authorization_code'], 'dashboard_bundle_entity_type[metadata][accessTokenValidity]' => '3600', + 'dashboard_bundle_entity_type[metadata][typeOfService][]' => 'Research', 'dashboard_bundle_entity_type[attributes][displayNameAttribute][requested]' => true, 'dashboard_bundle_entity_type[attributes][displayNameAttribute][motivation]' => 'We really need it!', 'dashboard_bundle_entity_type[contactInformation][administrativeContact][firstName]' => 'John', diff --git a/tests/webtests/EntityCreateSamlTest.php b/tests/webtests/EntityCreateSamlTest.php index c1e5b681c..c782ad0c5 100644 --- a/tests/webtests/EntityCreateSamlTest.php +++ b/tests/webtests/EntityCreateSamlTest.php @@ -19,6 +19,8 @@ namespace Surfnet\ServiceProviderDashboard\Webtests; use Surfnet\ServiceProviderDashboard\Application\ViewObject\Attribute; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Constants; +use Surfnet\ServiceProviderDashboard\Infrastructure\DashboardBundle\DataFixtures\ORM\WebTestFixtures; use Symfony\Component\DomCrawler\Field\ChoiceFormField; use Facebook\WebDriver\WebDriverBy; @@ -164,7 +166,6 @@ public function test_it_can_requires_a_valid_acs_location_url() */ public function test_it_can_publish_the_form() { - $this->markTestSkipped('TODO: add test coverage for IdPs connection page'); $this->testPublicationClient->registerPublishResponse( 'https://entity-id.url', '{"id":"f1e394b2-08b1-4882-8b32-43876c15c743"}' @@ -188,14 +189,34 @@ public function test_it_can_publish_the_form() $formData = $this->buildValidFormData(); self::$pantherClient->submit($form, $formData); - $pageTitle = self::$pantherClient->getCrawler()->filter('h1')->first()->text(); + // Now register the entity in the query client (it is not actuallly stored in Manage, so we need to provide + // test data + $this->registerManageEntity( + Constants::ENVIRONMENT_TEST, + 'saml20_sp', + 'f1e394b2-08b1-4882-8b32-43876c15c743', + 'The C Team', + 'https://entity-id.test', + '', + WebTestFixtures::TEAMNAME_IBUILDINGS, + ); + $crawler = self::$pantherClient->reload(); + $this->assertOnPage('Connect some Idp\'s to your entity'); + // Continue without selecting test IdPs + $form = $crawler + ->selectButton('Save') + ->form(); + $crawler = self::$pantherClient->submit( + $form, + ['idp_entity[institutionEntities][]' => '0c3febd2-3f67-4b8a-b90d-ce56a3b0abb4'] + ); + + $pageTitle = $crawler->filter('h1')->first()->text(); self::assertEquals('Successfully published the entity to test', $pageTitle); } public function test_it_can_publish_multiple_acs_locations() { - $this->markTestSkipped('TODO: add test coverage for IdPs connection page'); - $this->testPublicationClient->registerPublishResponse( 'https://entity-id.url', '{"id":"f1e394b2-08b1-4882-8b32-43876c15c743"}' @@ -231,9 +252,26 @@ public function test_it_can_publish_multiple_acs_locations() $formData = $this->buildValidFormData(); self::$pantherClient->submit($form, $formData); - self::$pantherClient->followRedirects(); + // Now register the entity in the query client (it is not actuallly stored in Manage, so we need to provide + // test data + $this->registerManageEntity( + Constants::ENVIRONMENT_TEST, + 'saml20_sp', + 'f1e394b2-08b1-4882-8b32-43876c15c743', + 'The C Team', + 'https://entity-id.test', + '', + WebTestFixtures::TEAMNAME_IBUILDINGS, + ); + $crawler = self::$pantherClient->reload(); + $this->assertOnPage('Connect some Idp\'s to your entity'); + // Continue without selecting test IdPs + $form = $crawler + ->selectButton('Save') + ->form(); + $crawler = self::$pantherClient->submit($form); - $pageTitle = self::$pantherClient->getCrawler()->filter('h1')->first()->text(); + $pageTitle = $crawler->filter('h1')->first()->text(); self::assertEquals('Successfully published the entity to test', $pageTitle); } @@ -379,6 +417,7 @@ private function buildValidFormData(): array 'dashboard_bundle_entity_type[metadata][nameNl]' => 'The A Team', 'dashboard_bundle_entity_type[metadata][metadataUrl]' => 'https://metadata-url.net', 'dashboard_bundle_entity_type[metadata][entityId]' => 'https://entity-id.url', + 'dashboard_bundle_entity_type[metadata][typeOfService][]' => 'Research', 'dashboard_bundle_entity_type[metadata][certificate]' => file_get_contents( __DIR__ . '/fixtures/publish/valid.cer' ), diff --git a/tests/webtests/Manage/Client/FakePublishEntityClient.php b/tests/webtests/Manage/Client/FakePublishEntityClient.php index 7dac5ac50..b6b077630 100644 --- a/tests/webtests/Manage/Client/FakePublishEntityClient.php +++ b/tests/webtests/Manage/Client/FakePublishEntityClient.php @@ -19,6 +19,7 @@ namespace Surfnet\ServiceProviderDashboard\Webtests\Manage\Client; use RuntimeException; +use Surfnet\ServiceProviderDashboard\Domain\Entity\Contact; use Surfnet\ServiceProviderDashboard\Domain\Entity\ManageEntity; use Surfnet\ServiceProviderDashboard\Domain\Repository\PublishEntityRepository as PublishEntityRepositoryInterface; @@ -45,8 +46,12 @@ public function registerPushFail() $this->pushOk = false; } - public function publish(ManageEntity $entity, ?ManageEntity $pristineEntity, string $part = ''): mixed - { + public function publish( + ManageEntity $entity, + ?ManageEntity $pristineEntity, + Contact $contact, + string $part = '' + ): mixed { $entityId = $entity->getMetaData()->getEntityId(); $publishResponses = $this->read(); if (!array_key_exists($entityId, $publishResponses)) { diff --git a/tests/webtests/Manage/Client/FakeQueryClient.php b/tests/webtests/Manage/Client/FakeQueryClient.php index b4bf2f456..909921761 100644 --- a/tests/webtests/Manage/Client/FakeQueryClient.php +++ b/tests/webtests/Manage/Client/FakeQueryClient.php @@ -23,6 +23,7 @@ use Surfnet\ServiceProviderDashboard\Domain\Repository\QueryManageRepository; use Surfnet\ServiceProviderDashboard\Domain\ValueObject\InstitutionId; use function array_key_exists; +use function json_encode; class FakeQueryClient implements QueryManageRepository {