public function testAuthenticator401NotFound() { $identity = new Identity('foo', 'bar'); $response = $this->prophesize(ResponseInterface::class); $response->getStatusCode()->willReturn(401); $response->getReasonPhrase()->willReturn('Not Found'); $resultSetClient = $this->createResultSetClientProphecy(); $resultSetClient->execute($this->createCommand('foo')->withIdentity($identity))->willThrow(InvalidResponseException::fromUnsuccessfulResponse($response->reveal())); $authenticator = $this->createAuthenticator($resultSetClient->reveal(), $identity); $this->assertFalse($authenticator->authenticate('foo', 'bar')->isSuccess()); }
public function getAsset(string $assetUri) : StreamInterface { $assetUriParts = parse_url($assetUri); $uri = $this->uri->withUserInfo(''); if (array_key_exists('path', $assetUriParts)) { $uri = $uri->withPath($assetUriParts['path']); } if (array_key_exists('query', $assetUriParts)) { $uri = $uri->withQuery($assetUriParts['query']); } $request = (new Request($uri, 'GET'))->withAddedHeader('User-agent', 'SimpleFM'); $credentials = urldecode($this->uri->getUserInfo()); if ('' !== $credentials) { $request = $request->withAddedHeader('Authorization', sprintf('Basic %s', base64_encode($credentials))); } $response = $this->httpClient->sendRequest($request); if (200 !== (int) $response->getStatusCode()) { throw InvalidResponseException::fromUnsuccessfulResponse($response); } return $response->getBody(); }