Skip to content
Snippets Groups Projects
Commit c667e9e0 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst
Browse files

Complete test coverage for getHostedMetadata()

parent 9dfd04fe
No related branches found
No related tags found
No related merge requests found
......@@ -481,6 +481,7 @@ class SPTest extends ClearStateTestCase
$md = $as->getHostedMetadata();
$this->assertArrayHasKey('contacts', $md);
$this->assertIsArray($md['contacts']);
$this->assertCount(2, $md['contacts']);
$contacts = $md['contacts'];
$contact = $md['contacts'][0];
......@@ -502,6 +503,74 @@ class SPTest extends ClearStateTestCase
$this->assertArrayNotHasKey('attributes', $contact);
}
/**
* A globally set tech contact also appears in SP hosted metadata
*/
public function testMetadataHostedContactsIncludesGlobalTechContact(): void
{
Configuration::loadFromArray([
'technicalcontact_email' => 'someone.somewhere@example.org',
'technicalcontact_name' => 'Someone von Somewhere',
], '[ARRAY]', 'simplesaml');
$spId = 'myhosted-sp';
$info = ['AuthId' => $spId];
$config = ['contacts' => [
[
'contactType' => 'technical',
'emailAddress' => 'j.doe@example.edu',
'givenName' => 'Jane',
'surName' => 'Doe',
],
]];
$as = new SpTester($info, $config);
$md = $as->getHostedMetadata();
$this->assertArrayHasKey('contacts', $md);
$this->assertIsArray($md['contacts']);
$this->assertCount(2, $md['contacts']);
$contacts = $md['contacts'];
$contact = $md['contacts'][0];
$this->assertIsArray($contact);
$this->assertEquals('technical', $contact['contactType']);
$this->assertEquals('Doe', $contact['surName']);
$contact = $md['contacts'][1];
$this->assertIsArray($contact);
$this->assertEquals('technical', $contact['contactType']);
$this->assertEquals('someone.somewhere@example.org', $contact['emailAddress']);
$this->assertEquals('Someone von Somewhere', $contact['givenName']);
$this->assertArrayNotHasKey('surName', $contact);
}
/**
* The special value na@example.org global tech contact is not included in SP metadata
*/
public function testMetadataHostedContactsSkipsNAGlobalTechContact(): void
{
Configuration::loadFromArray([
'technicalcontact_email' => 'na@example.org',
'technicalcontact_name' => 'Someone von Somewhere',
], '[ARRAY]', 'simplesaml');
$spId = 'myhosted-sp';
$info = ['AuthId' => $spId];
$config = ['contacts' => [
[
'contactType' => 'technical',
'emailAddress' => 'j.doe@example.edu',
'surName' => 'Doe',
],
]];
$as = new SpTester($info, $config);
$md = $as->getHostedMetadata();
$this->assertCount(1, $md['contacts']);
$this->assertEquals('j.doe@example.edu', $md['contacts'][0]['emailAddress']);
}
/**
* Contacts in SP hosted of unknown type throws Exceptiona
*/
......@@ -696,6 +765,7 @@ class SPTest extends ClearStateTestCase
$config = [
'WantAssertionsSigned' => true,
'redirect.sign' => true,
'sign.authnrequest' => true,
];
$as = new SpTester($info, $config);
......@@ -704,10 +774,12 @@ class SPTest extends ClearStateTestCase
$this->assertArrayHasKey('redirect.validate', $md);
$this->assertTrue($md['saml20.sign.assertion']);
$this->assertTrue($md['redirect.validate']);
$this->assertArrayNotHasKey('validate.authnrequest', $md);
$config = [
'WantAssertionsSigned' => false,
'redirect.sign' => false,
'sign.authnrequest' => false,
];
$as = new SpTester($info, $config);
......@@ -716,6 +788,17 @@ class SPTest extends ClearStateTestCase
$this->assertArrayHasKey('redirect.validate', $md);
$this->assertFalse($md['saml20.sign.assertion']);
$this->assertFalse($md['redirect.validate']);
$this->assertArrayNotHasKey('validate.authnrequest', $md);
$config = [
'sign.authnrequest' => true,
];
$as = new SpTester($info, $config);
$md = $as->getHostedMetadata();
$this->assertArrayNotHasKey('redirect.validate', $md);
$this->assertArrayHasKey('validate.authnrequest', $md);
$this->assertTrue($md['validate.authnrequest']);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment