Skip to content

Commit

Permalink
Test the SURF conext representative page
Browse files Browse the repository at this point in the history
The missing web test coverage was added in this commit.

Some notes:
- For now all IdPs are allowed for every SP (via allowedall)
- Only one test idp is configured, that could be expanded upon
  • Loading branch information
MKodde committed Jun 18, 2024
1 parent eab70af commit 51a098e
Show file tree
Hide file tree
Showing 10 changed files with 201 additions and 26 deletions.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ administrator_teams="'urn:collab:group:dev.openconext.local:dev:openconext:local
jira_test_mode_storage_path='/var/www/html/var/issues.json'
authorization_attribute_name='eduPersonEntitlement'
surfconext_responsible_authorization='urn:mace:surfnet.nl:surfnet.nl:sab:role:SURFconext-verantwoordelijke'
test_idp_entity_ids='["http://mock-idp","test-idp-1"]'
13 changes: 10 additions & 3 deletions tests/webtests/Manage/Client/ClientResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ class ClientResult implements ClientResultInterface

private $teamName;

private string $institutionId;

public function __construct(
string $protocol,
string $id,
string $entityId,
?string $metadataUrl,
string $name,
?string $teamName
?string $teamName,
?string $institutionId,
) {
$this->id = $id;
$this->protocol = $protocol;
Expand All @@ -56,6 +59,7 @@ public function __construct(
$this->metadataUrl = $metadataUrl;
$this->name = $name;
$this->teamName = $teamName;
$this->institutionId = $institutionId;
if ($teamName === null) {
$this->teamName = 'urn:collab:group:vm.openconext.org:demo:openconext:org:surf.nl';
}
Expand Down Expand Up @@ -87,7 +91,8 @@ public function getEntityResult(): array
$this->metadataUrl,
$this->name,
str_replace('_', '-', $this->protocol),
$this->teamName
$this->teamName,
$this->institutionId
);
return json_decode($data, true);
}
Expand Down Expand Up @@ -116,7 +121,8 @@ public static function decode($data): self
$data['entityId'],
$data['metadataUrl'],
$data['name'],
$data['teamName']
$data['teamName'],
$data['institutionId'],
);
}

Expand All @@ -129,6 +135,7 @@ public function encode(): array
'metadataUrl' => $this->metadataUrl,
'name' => $this->name,
'teamName' => $this->teamName,
'institutionId' => $this->institutionId,
];
}
}
44 changes: 42 additions & 2 deletions tests/webtests/Manage/Client/FakeIdentityProviderClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@

class FakeIdentityProviderClient implements IdentityProviderRepository
{
private string $path = __DIR__ . '/../../../../var/webtest-idps.json';
/**
* @var ClientResult[]
*/
private $entities = [];

public function registerEntity(string $protocol, string $id, string $entityId, string $name)
public function registerEntity(string $protocol, string $id, string $entityId, string $name, string $institutionId = '')
{
$this->entities[$id] = new ClientResult($protocol, $id, $entityId, null, $name, null);
$this->entities[$id] = new ClientResult($protocol, $id, $entityId, null, $name, null, $institutionId);
$this->storeEntities();
}

/**
* @return IdentityProvider[]
*/
public function findAll()
{
$this->load();
$list = [];
foreach ($this->entities as $manageResult) {
$list[] = IdentityProviderFactory::fromManageResult($manageResult->getEntityResult());
Expand All @@ -50,6 +53,7 @@ public function findAll()

public function findByEntityId(EntityId $entityId): ?IdentityProvider
{
$this->load();
foreach ($this->entities as $manageResult) {
$entity = IdentityProviderFactory::fromManageResult($manageResult->getEntityResult());
if ($entity->getEntityId() === (string) $entityId) {
Expand All @@ -66,10 +70,46 @@ public function findByEntityId(EntityId $entityId): ?IdentityProvider
*/
public function findByInstitutionId(InstitutionId $institutionId): array
{
$this->load();
$list = [];
foreach ($this->entities as $manageResult) {
$list[] = IdentityProviderFactory::fromManageResult($manageResult->getEntityResult());
}
return $list;
}


private function read()
{
return json_decode(file_get_contents($this->path), true);
}

private function write(array $data)
{
file_put_contents($this->path, json_encode($data));
}

private function storeEntities()
{
// Also store the new entity in the on-file storage
$data = [];
foreach ($this->entities as $identifier => $entity) {
$data[$identifier] = $entity->encode();
}
$this->write($data);
}

private function load()
{
$data = $this->read();
foreach ($data as $id => $rawClientResult) {
if (array_key_exists('protocol', $rawClientResult)) {
$this->entities[$id] = ClientResult::decode($rawClientResult);
continue;
}
if (array_key_exists('json', $rawClientResult)) {
$this->entities[$id] = ClientResultRaw::decode($rawClientResult);
}
}
}
}
6 changes: 4 additions & 2 deletions tests/webtests/Manage/Client/FakeQueryClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ public function registerEntity(
string $entityId,
?string $metadataUrl,
string $name,
?string $teamName = null
?string $teamName = null,
?string $institutionId = '',
) {
$this->entities[$id] = new ClientResult($protocol, $id, $entityId, $metadataUrl, $name, $teamName);
$this->entities[$id] = new ClientResult($protocol, $id, $entityId, $metadataUrl, $name, $teamName, $institutionId);
$this->storeEntities();
}

Expand Down Expand Up @@ -142,6 +143,7 @@ public function findResourceServerByEntityId($entityId, $state)
$searchResults[] = ManageEntity::fromApiResponse($result);
}
}
return $searchResults;
}

public function findByManageIdAndProtocol(string $manageId, string $protocol) :? ManageEntity
Expand Down
1 change: 1 addition & 0 deletions tests/webtests/Manage/Client/template/ccc.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"OrganizationDisplayName:nl": "%5$s Organisation Name Dutch",
"OrganizationURL:nl": "%5$s Organisation Url Dutch",
"coin:service_team_id": "%7$s",
"coin:institution_id": "%8$s",
"isPublicClient": true
},
"allowedEntities": [],
Expand Down
1 change: 1 addition & 0 deletions tests/webtests/Manage/Client/template/oidc10.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"OrganizationDisplayName:nl": "%5$s Organisation Name Dutch",
"OrganizationURL:nl": "%5$s Organisation Url Dutch",
"coin:service_team_id": "%7$s",
"coin:institution_id": "%8$s",
"isPublicClient": true
},
"allowedEntities": [],
Expand Down
3 changes: 2 additions & 1 deletion tests/webtests/Manage/Client/template/saml20_idp.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"metaDataFields": {
"name:en": "%5$s Name English",
"name:nl": "%5$s Name Dutch",
"coin:service_team_id": "%7$s"
"coin:service_team_id": "%7$s",
"coin:institution_id": "%8$s"
},
"eid": 31
}
Expand Down
1 change: 1 addition & 0 deletions tests/webtests/Manage/Client/template/saml20_sp.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"OrganizationDisplayName:nl": "%5$s Organisation Name Dutch",
"OrganizationURL:nl": "%5$s Organisation Url Dutch",
"coin:service_team_id": "%7$s",
"coin:institution_id": "%8$s",
"logo:0:url": "%3$s\/images\/logo.png",
"logo:0:width": 100,
"logo:0:height": 100,
Expand Down
118 changes: 113 additions & 5 deletions tests/webtests/SurfConextResponsibleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,126 @@

class SurfConextResponsibleTest extends WebTestCase
{
private string $institutionId = 'ACME Corporation';
public function setUp(): void
{
parent::setUp();

$this->loadFixtures();
$this->teamsQueryClient->registerTeam('demo:openconext:org:surf.nl', 'data');
$this->logInSurfConextResponsible('ACME Corporation');
$this->teamsQueryClient->registerTeam('demo:openconext:org:acme.nl', 'data');
}

public function test_after_login_i_am_on_connections_page()
{
$crawler = self::$pantherClient->getCrawler();
self::assertEquals('/connections', $crawler->getBaseHref());
$this->logInSurfConextResponsible($this->institutionId);
$url = self::$pantherClient->getCurrentURL();
$urlParts = parse_url($url);
self::assertEquals('/connections', $urlParts['path']);
self::assertOnPage('No entities found'); // At this point there should be no entities
}

public function test_entities_are_listed_on_the_page()
{
$this->registerManageEntity(
'test',
'saml20_sp',
'aee8f00d-428a-4fbc-9cf8-ad2f3b2af589',
'ACME Anvil',
'http://acme-anvil',
'https://acme-anvil.example.com/metadata',
'demo:openconext:org:acme.nl',
$this->institutionId,
);
$this->logInSurfConextResponsible($this->institutionId);
$this->assertOnPage('ACME Anvil Name English');
// When logging in with only the SURF representative, we do not know the service the entity is associated with
$this->assertOnPage('Unknown service name');
}

public function test_entities_are_listed_on_the_page_with_connected_idp()
{
$this->registerManageEntity(
'test',
'saml20_sp',
'aee8f00d-428a-4fbc-9cf8-ad2f3b2af589',
'ACME Anvil',
'http://acme-anvil',
'https://acme-anvil.example.com/metadata',
'demo:openconext:org:acme.nl',
$this->institutionId,
);
$this->registerManageEntity(
'test',
'saml20_idp',
'1d4abec3-3f67-4b8a-b90d-ce56a3b0abc5',
'Test IdP',
'test-idp-1',
'https://test-idp/metadata',
'demo:openconext:org:acme.nl',
$this->institutionId,
);
$this->logInSurfConextResponsible($this->institutionId);
$this->assertOnPage('ACME Anvil Name English');
$this->assertOnPage('Test IdP Name Dutch');
}

public function test_entities_are_listed_on_the_page_with_connected_idp_with_multiple_sps()
{
$this->registerManageEntity(
'test',
'saml20_sp',
'aee8f00d-428a-4fbc-9cf8-ad2f3b2af589',
'ACME Anvil 1',
'http://acme-anvil-1',
'https://acme-anvil.example.com/metadata',
'demo:openconext:org:acme.nl',
$this->institutionId,
);
$this->registerManageEntity(
'test',
'saml20_sp',
'bee8f00d-428a-4fbc-9cf8-ad2f3b2af589',
'ACME Anvil 2',
'http://acme-anvil-2',
'https://acme-anvil.example.com/metadata',
'demo:openconext:org:acme.nl',
$this->institutionId,
);
$this->registerManageEntity(
'test',
'saml20_sp',
'cee8f00d-428a-4fbc-9cf8-ad2f3b2af589',
'ACME Anvil 3',
'http://acme-anvil-3',
'https://acme-anvil.example.com/metadata',
'demo:openconext:org:acme.nl',
$this->institutionId,
);
$this->registerManageEntity(
'test',
'saml20_sp',
'fee8f00d-428a-4fbc-9cf8-ad2f3b2af589',
'Should not be on page',
'http://foobar',
'https://foobar.example.com/metadata',
'demo:openconext:org:acme.nl',
'not-acme',
);
$this->registerManageEntity(
'test',
'saml20_idp',
'1d4abec3-3f67-4b8a-b90d-ce56a3b0abc5',
'Test IdP',
'test-idp-1',
'https://test-idp/metadata',
'demo:openconext:org:acme.nl',
$this->institutionId,
);
$this->logInSurfConextResponsible($this->institutionId);
$this->assertOnPage('ACME Anvil 1 Name English');
$this->assertOnPage('ACME Anvil 2 Name English');
$this->assertOnPage('ACME Anvil 3 Name English');
// The fourth SP should not show up on the page
$this->assertNotOnPage('Should not be on page');
$this->assertOnPage('Test IdP Name Dutch');
}
}
Loading

0 comments on commit 51a098e

Please sign in to comment.