public function xtestGetRepository()
 {
     $this->givenAClient();
     $this->app['store']->add('https://github.com/vendor/library', 'vendor/library', 'owner', 'A test repo', 'javascript', 'npm', 'Europe/London', false);
     $this->client->request('GET', '/repositories/vendor/library');
     $this->thenTheResponseIs(200);
 }
Beispiel #2
0
 public function testGetAllReturnsSuccess()
 {
     $this->givenAClient();
     $this->client->request('PUT', '/tokens/xxx', ['token' => 'secret']);
     $this->client->request('PUT', '/tokens/yyy', ['token' => 'another secret']);
     $this->client->request('PUT', '/tokens/abc', ['token' => 'string q']);
     $this->client->request('GET', '/tokens');
     $this->thenTheResponseIsSuccess();
     $this->assertResponseContents(json_encode(['xxx', 'yyy', 'abc']));
 }
 public function handle($accessToken, array $options = [])
 {
     $options = array_merge(['debug_endpoint' => '', 'cache' => true], $options);
     // Both options are required.
     if (!$options['debug_endpoint']) {
         throw new ServerErrorException(['error_description' => 'The authorization server encountered an unexpected condition that prevented it from fulfilling the request.']);
     }
     $accessTokenManager = $this->modelManagerFactory->getModelManager('access_token');
     // Get cached access_token and return if exists.
     if ($options['cache']) {
         $stored = $accessTokenManager->readModelOneBy(['accessToken' => $accessToken]);
         if ($stored !== null && $stored->getExpires() > new \DateTime()) {
             return $stored;
         }
     }
     // Fetch meta data of supplied access token by query debug endpoint.
     if (strpos($options['debug_endpoint'], '/') === 0) {
         // For relative URL, use Symfony test client to simulates and
         // HTTP client like a browser and makes requests.
         $client = new \Symfony\Component\HttpKernel\Client($this->httpKernel);
         $crawler = $client->request('GET', $options['debug_endpoint'], [], [], ['HTTP_Authorization' => implode(' ', ['Bearer', $accessToken])]);
         $content = $client->getResponse()->getContent();
     } else {
         // For absolute URL, use Guzzle client to create request.
         $client = new \GuzzleHttp\Client();
         $crawler = $client->get($options['debug_endpoint'], ['headers' => ['Authorization' => implode(' ', ['Bearer', $accessToken])]]);
         $content = $crawler->getBody();
     }
     $response = json_decode($content, true);
     // Throw exception if error return.
     if (isset($response['error'])) {
         throw new InvalidRequestException(['error_description' => 'The request includes an invalid parameter value.']);
     }
     // Create a new access token with fetched meta data.
     $class = $accessTokenManager->getClassName();
     $accessTokenCached = new $class();
     $accessTokenCached->setAccessToken($response['access_token'])->setTokenType($response['token_type'])->setClientId($response['client_id'])->setUsername($response['username'])->setExpires(new \DateTime('@' . $response['expires']))->setScope($response['scope']);
     $accessTokenCached = $accessTokenManager->createModel($accessTokenCached);
     return $accessTokenCached;
 }