44
55namespace SimpleSAML \Test \Module \exampleattributeserver \Controller ;
66
7+ use Mockery \Adapter \Phpunit \MockeryTestCase ;
8+
9+ use Nyholm \Psr7 \ServerRequest ;
710use PHPUnit \Framework \Attributes \CoversClass ;
811use PHPUnit \Framework \TestCase ;
12+ use SimpleSAML \SAML2 \Binding \SOAP ;
913use SimpleSAML \Configuration ;
1014use SimpleSAML \HTTP \RunnableResponse ;
1115use SimpleSAML \Metadata \MetaDataStorageHandler ;
1216use SimpleSAML \Module \exampleattributeserver \Controller \AttributeServer ;
1317use SimpleSAML \XMLSecurity \TestUtils \PEMCertificatesMock ;
1418use Symfony \Component \HttpFoundation \Request ;
19+ use SAML2 \Message ;
1520
1621/**
1722 * Set of tests for the controllers in the "exampleattributeserver" module.
1823 *
1924 * @package simplesamlphp/simplesamlphp-module-exampleattributeserver
2025 */
2126#[CoversClass(AttributeServer::class)]
22- class ExampleAttributeServerTest extends TestCase
27+ class ExampleAttributeServerTest extends MockeryTestCase
2328{
2429 /** @var \SimpleSAML\Configuration */
2530 protected static Configuration $ config ;
@@ -52,9 +57,22 @@ public static function setUpBeforeClass(): void
5257 */
5358 public function testMain (): void
5459 {
55- $ _SERVER ['REQUEST_URI ' ] = '/module.php/exampleattributeserver/attributeserver ' ;
56- $ _SERVER ['HTTP_HOST ' ] = 'example.org ' ;
57- $ request = Request::createFromGlobals ();
60+ $ soap = $ this ->getStubWithInput (<<<SOAP
61+ <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
62+ <SOAP-ENV:Body>
63+ <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">
64+ <saml:Issuer Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">https://example.org/</saml:Issuer>
65+ <saml:Subject>
66+ <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified">urn:example:subject</saml:NameID>
67+ </saml:Subject>
68+ <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"/>
69+ <saml:Attribute Name="urn:oid:2.5.4.4" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri" FriendlyName="sn"/>
70+ <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"/>
71+ </samlp:AttributeQuery>
72+ </SOAP-ENV:Body>
73+ </SOAP-ENV:Envelope>
74+ SOAP );
75+
5876
5977 $ mdh = $ this ->createMock (MetaDataStorageHandler::class);
6078 $ mdh ->method ('getMetaDataCurrentEntityID ' )->willReturn ('https://example.org/ ' );
@@ -67,9 +85,23 @@ public function testMain(): void
6785
6886 $ c = new AttributeServer (self ::$ config );
6987 $ c ->setMetadataStorageHandler ($ mdh );
70- $ response = $ c ->main ($ request );
88+
89+ $ request = new ServerRequest ('' , '' );
90+ $ response = $ c ->main ($ soap , $ request );
7191
7292 $ this ->assertInstanceOf (RunnableResponse::class, $ response );
7393 $ this ->assertTrue ($ response ->isSuccessful ());
7494 }
95+
96+ /**
97+ * @return \SimpleSAML\SAML2\Binding\SOAP
98+ */
99+ private function getStubWithInput ($ input ): SOAP
100+ {
101+ $ stub = $ this ->getMockBuilder (SOAP ::class)->onlyMethods (['getInputStream ' ])->getMock ();
102+ $ stub ->expects ($ this ->once ())
103+ ->method ('getInputStream ' )
104+ ->willReturn ($ input );
105+ return $ stub ;
106+ }
75107}
0 commit comments