diff --git a/spec/drupol/EuloginBundle/Protocol/CasHelper.php b/spec/drupol/EuloginBundle/Protocol/CasHelper.php deleted file mode 100644 index ce42ade..0000000 --- a/spec/drupol/EuloginBundle/Protocol/CasHelper.php +++ /dev/null @@ -1,247 +0,0 @@ - - - username - - -EOF; - - break; - case 'http://local/cas/serviceValidate?service=service&ticket=ticket-failure': - $body = <<< 'EOF' - - - - -EOF; - - break; - case 'http://local/cas/proxyValidate?service=service&ticket=ticket': - case 'http://local/cas/proxyValidate?ticket=PT-ticket&service=http%3A%2F%2Ffrom': - case 'http://local/cas/proxyValidate?ticket=ST-ticket&service=http%3A%2F%2Ffrom': - case 'http://local/cas/proxyValidate?service=http%3A%2F%2Flocal%2Fcas%2FproxyValidate%3Fservice%3Dservice&ticket=ticket': - case 'http://local/cas/proxyValidate?service=http%3A%2F%2Flocal%2Fcas%2FproxyValidate%3Fservice%3Dservice%26renew%3Dtrue&ticket=ticket&renew=true': - case 'http://local/cas/proxyValidate?service=http%3A%2F%2Flocal%2Fcas%2FserviceValidate%3Fservice%3Dservice&ticket=ticket': - case 'http://local/cas/proxyValidate?service=http%3A%2F%2Flocal%2Fcas%2FserviceValidate%3Fservice%3Dservice%26renew%3Dtrue&ticket=ticket&renew=true': - $body = <<< 'EOF' - - - username - - http://app/proxyCallback.php - - - -EOF; - - break; - case 'http://local/cas/serviceValidate?ticket=ST-ticket-pgt&service=http%3A%2F%2Ffrom': - $body = <<< 'EOF' - - - username - pgtIou - - -EOF; - - break; - case 'http://local/cas/serviceValidate?ticket=ST-ticket-pgt-pgtiou-not-found&service=http%3A%2F%2Ffrom': - $body = <<< 'EOF' - - - username - unknownPgtIou - - -EOF; - - break; - case 'http://local/cas/proxyValidate?ticket=ST-ticket-pgt-pgtiou-pgtid-null&service=http%3A%2F%2Ffrom': - $body = <<< 'EOF' - - - username - pgtIouWithPgtIdNull - - -EOF; - - break; - case 'http://local/cas/proxyValidate?service=service&ticket=ST-ticket-pgt': - case 'http://local/cas/proxyValidate?ticket=ST-ticket-pgt&service=http%3A%2F%2Ffrom': - case 'http://local/cas/proxyValidate?service=http%3A%2F%2Flocal%2Fcas%2FproxyValidate%3Fservice%3Dhttp%253A%252F%252Ffrom&ticket=PT-ticket-pgt': - $body = <<< 'EOF' - - - username - pgtIou - - http://app/proxyCallback.php - - - -EOF; - - break; - case 'http://local/cas/serviceValidate?service=http%3A%2F%2Flocal%2Fcas%2FserviceValidate%3Fservice%3Dservice%26format%3DJSON&ticket=ticket&format=JSON': - $body = <<< 'EOF' -{ - "serviceResponse": { - "authenticationSuccess": { - "user": "username" - } - } -} -EOF; - - break; - case 'http://local/cas/proxyValidate?service=http%3A%2F%2Ffrom&ticket=PT-ticket': - $body = <<< 'EOF' - - - username - pgtIou - - http://app/proxyCallback.php - - - -EOF; - - break; - case 'http://local/cas/proxy?targetService=targetService&pgt=pgt': - $body = <<< 'EOF' - - - - PT-214-A3OoEPNr4Q9kNNuYzmfN8azU31aDUsuW8nk380k7wDExT5PFJpxR1TrNI3q3VGzyDdi0DpZ1LKb8IhPKZKQvavW-8hnfexYjmLCx7qWNsLib1W-DCzzoLVTosAUFzP3XDn5dNzoNtxIXV9KSztF9fYhwHvU0 - - -EOF; - - break; - case 'http://local/cas/proxy?targetService=targetService&pgt=pgt-error-in-getCredentials': - $body = <<< 'EOF' - - - - TODO: Find something to put here. - - -EOF; - - break; - case 'http://local/cas/serviceValidate?service=http%3A%2F%2Ffrom&ticket=BAD-http-query': - case 'http://local/cas/proxyValidate?service=http%3A%2F%2Ffrom&ticket=BAD-http-query': - case 'http://local/cas/proxyValidate?service=http%3A%2F%2Flocal%2Fcas%2FproxyValidate%3Fservice%3Dservice%26error%3DTestClientException&ticket=ticket&error=TestClientException': - case 'http://local/cas/proxy?targetService=targetService&pgt=pgt&error=TestClientException': - throw new TestClientException(); - - break; - } - - return new MockResponse($body, $info); - }; - - return new MockHttpClient($callback); - } - - /** - * @return \drupol\psrcas\Configuration\Properties - */ - public static function getTestProperties(): CasProperties - { - return new CasProperties([ - 'base_url' => 'http://local/cas', - 'protocol' => [ - 'login' => [ - 'path' => '/login', - 'allowed_parameters' => [ - 'service', - 'custom', - 'renew', - 'gateway', - ], - ], - 'logout' => [ - 'path' => '/logout', - 'allowed_parameters' => [ - 'service', - 'custom', - ], - ], - 'serviceValidate' => [ - 'path' => '/serviceValidate', - 'allowed_parameters' => [ - 'ticket', - 'service', - 'custom', - ], - 'default_parameters' => [ - 'format' => 'XML', - ], - ], - 'proxyValidate' => [ - 'path' => '/proxyValidate', - 'allowed_parameters' => [ - 'ticket', - 'service', - 'custom', - ], - 'default_parameters' => [ - 'format' => 'XML', - ], - ], - 'proxy' => [ - 'path' => '/proxy', - 'allowed_parameters' => [ - 'targetService', - 'pgt', - ], - ], - ], - ]); - } - - /** - * @return \drupol\psrcas\Configuration\Properties - */ - public static function getTestPropertiesWithPgtUrl(): CasProperties - { - $properties = self::getTestProperties()->all(); - - $properties['protocol']['serviceValidate']['default_parameters']['pgtUrl'] = 'https://from/proxyCallback.php'; - - return new CasProperties($properties); - } -} diff --git a/spec/drupol/EuloginBundle/Protocol/EuloginSpec.php b/spec/drupol/EuloginBundle/Protocol/EuloginSpec.php deleted file mode 100644 index 6afe962..0000000 --- a/spec/drupol/EuloginBundle/Protocol/EuloginSpec.php +++ /dev/null @@ -1,123 +0,0 @@ -withServerRequest($request) - ->handleProxyCallback() - ->shouldReturnAnInstanceOf(ResponseInterface::class); - - $this - ->withServerRequest($request) - ->handleProxyCallback() - ->getBody() - ->__toString() - ->shouldReturn(''); - - $this - ->withServerRequest($request) - ->handleProxyCallback() - ->getStatusCode() - ->shouldReturn(200); - - $request = new ServerRequest('GET', 'http://local/proxycallback?pgtId=pgtId'); - - $this - ->withServerRequest($request) - ->handleProxyCallback() - ->getStatusCode() - ->shouldReturn(500); - - $request = new ServerRequest('GET', 'http://local/proxycallback?pgtIou=pgtIou'); - - $this - ->withServerRequest($request) - ->handleProxyCallback() - ->getStatusCode() - ->shouldReturn(500); - } - - public function let(LoggerInterface $logger, CacheItemPoolInterface $cache, CacheItemInterface $cacheItemPgtIou, CacheItemInterface $cacheItemPgtIdNull) - { - $properties = CasHelper::getTestProperties(); - $client = new Psr18Client(CasHelper::getHttpClientMock()); - - $psr17Factory = new Psr17Factory(); - $creator = new ServerRequestCreator( - $psr17Factory, // ServerRequestFactory - $psr17Factory, // UriFactory - $psr17Factory, // UploadedFileFactory - $psr17Factory // StreamFactory - ); - $serverRequest = $creator->fromGlobals(); - - $cacheItemPgtIou - ->set('pgtId') - ->willReturn($cacheItemPgtIou); - - $cacheItemPgtIou - ->expiresAfter(300) - ->willReturn($cacheItemPgtIou); - - $cacheItemPgtIou - ->get() - ->willReturn('pgtIou'); - - $cache - ->hasItem('unknownPgtIou') - ->willReturn(false); - - $cache - ->save($cacheItemPgtIou) - ->willReturn(true); - - $cache - ->hasItem('pgtIou') - ->willReturn(false); - - $cache - ->getItem('pgtIou') - ->willReturn($cacheItemPgtIou); - - $cache - ->hasItem('pgtIouWithPgtIdNull') - ->willReturn(true); - - $cacheItemPgtIdNull - ->set(null) - ->willReturn($cacheItemPgtIdNull); - - $cacheItemPgtIdNull - ->expiresAfter(300) - ->willReturn($cacheItemPgtIdNull); - - $cacheItemPgtIdNull - ->get() - ->willReturn(null); - - $cache - ->getItem('pgtIouWithPgtIdNull') - ->willReturn($cacheItemPgtIdNull); - - $this - ->beConstructedWith($serverRequest, $properties, $client, $psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory, $cache, $logger); - } -}