-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from NightJar/main
- Loading branch information
Showing
4 changed files
with
150 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace SilverStripe\SAML\Tests\Services; | ||
|
||
use SilverStripe\Control\Director; | ||
use SilverStripe\Core\Config\Config; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\SAML\Services\SAMLConfiguration; | ||
|
||
class SAMLConfigurationTest extends SapphireTest | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$config = Config::modify(); | ||
$config->set(Director::class, 'alternate_base_url', 'https://running.test'); | ||
|
||
$config->set(SAMLConfiguration::class, 'extra_acs_base', [ | ||
'https://example.running.test/' | ||
]); | ||
|
||
$config->set(SAMLConfiguration::class, 'SP', [ | ||
'entityId' => "https://running.test", | ||
'privateKey' => __DIR__ . '/fakeCertificate.pem', | ||
'x509cert' => __DIR__ . '/fakeCertificate.pem', | ||
]); | ||
$config->set(SAMLConfiguration::class, 'IdP', [ | ||
'entityId' => "idp.example.com", | ||
'singleSignOnService' => "https://idp.example.com/test/saml2", | ||
'x509cert' => __DIR__ . '/fakeCertificate.pem', | ||
]); | ||
|
||
$config->set(SAMLConfiguration::class, 'strict', true); | ||
$config->set(SAMLConfiguration::class, 'debug', false); | ||
$config->set(SAMLConfiguration::class, 'Security', [ | ||
'signatureAlgorithm' => "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", | ||
]); | ||
} | ||
|
||
public function provideBaseUrls(): array | ||
{ | ||
return [ | ||
[ | ||
null, | ||
'https://running.test/saml/acs', | ||
'SP.EntityId should be used by default' | ||
], | ||
[ | ||
'https://example.running.test/', | ||
'https://example.running.test/saml/acs', | ||
'Extra ACS should work when the loaded (or specified) domain matches' | ||
], | ||
[ | ||
'https://not-legit.running.test/', | ||
'https://running.test/saml/acs', | ||
'Unlisted ACS base should result in the SP.EntityId being used instead', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideBaseUrls | ||
* | ||
* @param string $baseUrl | ||
* @param string $expectedOut | ||
* @return void | ||
*/ | ||
public function testAcsBaseIsSetCorrectly($baseUrl, $expectedOut, $message) | ||
{ | ||
if (isset($baseUrl)) { | ||
Config::modify()->set(Director::class, 'alternate_base_url', $baseUrl); | ||
} | ||
$samlConfig = (new SAMLConfiguration())->asArray(); | ||
$this->assertSame( | ||
$expectedOut, | ||
$samlConfig['sp']['assertionConsumerService']['url'], | ||
$message | ||
); | ||
} | ||
} |
Empty file.