44
55namespace SimpleSAML \Test \Module \exampleattributeserver \Controller ;
66
7+ use Mockery \Adapter \Phpunit \MockeryTestCase ;
8+ use Nyholm \Psr7 \ServerRequest ;
79use PHPUnit \Framework \Attributes \CoversClass ;
8- use PHPUnit \Framework \TestCase ;
910use SimpleSAML \Configuration ;
1011use SimpleSAML \HTTP \RunnableResponse ;
1112use SimpleSAML \Metadata \MetaDataStorageHandler ;
1213use SimpleSAML \Module \exampleattributeserver \Controller \AttributeServer ;
14+ use SimpleSAML \SAML2 \Binding \SOAP ;
1315use SimpleSAML \XMLSecurity \TestUtils \PEMCertificatesMock ;
14- use Symfony \Component \HttpFoundation \Request ;
1516
1617/**
1718 * Set of tests for the controllers in the "exampleattributeserver" module.
1819 *
1920 * @package simplesamlphp/simplesamlphp-module-exampleattributeserver
2021 */
2122#[CoversClass(AttributeServer::class)]
22- class ExampleAttributeServerTest extends TestCase
23+ class ExampleAttributeServerTest extends MockeryTestCase
2324{
2425 /** @var \SimpleSAML\Configuration */
2526 protected static Configuration $ config ;
@@ -52,9 +53,22 @@ public static function setUpBeforeClass(): void
5253 */
5354 public function testMain (): void
5455 {
55- $ _SERVER ['REQUEST_URI ' ] = '/module.php/exampleattributeserver/attributeserver ' ;
56- $ _SERVER ['HTTP_HOST ' ] = 'example.org ' ;
57- $ request = Request::createFromGlobals ();
56+ $ soap = $ this ->getStubWithInput (<<<SOAP
57+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
58+ <SOAP-ENV:Body>
59+ <samlp:AttributeQuery xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="aaf23196-1773-2113-474a-fe114412ab72" Version="2.0" IssueInstant="2017-09-06T11:49:27Z">
60+ <saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">https://example.org/</saml:Issuer>
61+ <saml:Subject>
62+ <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified">urn:example:subject</saml:NameID>
63+ </saml:Subject>
64+ <saml:Attribute Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.7" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" FriendlyName="entitlements"/>
65+ <saml:Attribute Name="urn:oid:2.5.4.4" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" FriendlyName="sn"/>
66+ <saml:Attribute Name="urn:oid:2.16.840.1.113730.3.1.39" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" FriendlyName="preferredLanguage"/>
67+ </samlp:AttributeQuery>
68+ </SOAP-ENV:Body>
69+ </SOAP-ENV:Envelope>
70+ SOAP );
71+
5872
5973 $ mdh = $ this ->createMock (MetaDataStorageHandler::class);
6074 $ mdh ->method ('getMetaDataCurrentEntityID ' )->willReturn ('https://example.org/ ' );
@@ -67,9 +81,23 @@ public function testMain(): void
6781
6882 $ c = new AttributeServer (self ::$ config );
6983 $ c ->setMetadataStorageHandler ($ mdh );
70- $ response = $ c ->main ($ request );
84+
85+ $ request = new ServerRequest ('' , '' );
86+ $ response = $ c ->main ($ soap , $ request );
7187
7288 $ this ->assertInstanceOf (RunnableResponse::class, $ response );
7389 $ this ->assertTrue ($ response ->isSuccessful ());
7490 }
91+
92+ /**
93+ * @return \SimpleSAML\SAML2\Binding\SOAP
94+ */
95+ private function getStubWithInput ($ input ): SOAP
96+ {
97+ $ stub = $ this ->getMockBuilder (SOAP ::class)->onlyMethods (['getInputStream ' ])->getMock ();
98+ $ stub ->expects ($ this ->once ())
99+ ->method ('getInputStream ' )
100+ ->willReturn ($ input );
101+ return $ stub ;
102+ }
75103}
0 commit comments