/** * Test if result contains consumerKey and validationUrl */ public function testIfConsumerKeyIsReplace() { $property = self::getPrivateProperty('consumer_key'); $accessRules = json_decode(' [ { "method": "GET", "path": "/*" }, { "method": "POST", "path": "/*" }, { "method": "PUT", "path": "/*" }, { "method": "DELETE", "path": "/*" } ] '); $credentials = $this->api->requestCredentials($accessRules); $consumer_key = $property->getValue($this->api); $this->assertEquals($consumer_key, $credentials["consumerKey"]); $this->assertNotEquals($consumer_key, $this->consumer_key); }
/** * Test invalid applicationKey */ public function testInvalidApplicationKey() { $this->setExpectedException('\\GuzzleHttp\\Exception\\ClientException'); $delay = 10; $mock = new Mock(["HTTP/1.1 401 Unauthorized\r\nContent-Type: application/json; charset=utf-8\r\nContent-Length: 37\r\n\r\n{\"message\":\"Invalid application key\"}"]); $this->client->getEmitter()->attach($mock); $property = self::getPrivateProperty('consumer_key'); $api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client); $accessRules = array(json_decode(' { "method": "GET", "path": "/*" } ')); $credentials = $api->requestCredentials($accessRules); $consumer_key = $property->getValue($api); $this->assertEquals($consumer_key, $credentials["consumerKey"]); $this->assertNotEquals($consumer_key, $this->consumer_key); }
/** * Test invalid applicationKey */ public function testInvalidApplicationKey() { $this->setExpectedException('\\GuzzleHttp\\Exception\\ClientException'); $handlerStack = $this->client->getConfig('handler'); $handlerStack->push(Middleware::mapResponse(function (Response $response) { $body = $response->getBody(); $body->write('{\\"message\\":\\"Invalid application key\\"}'); return $response->withStatus(401, 'POUET')->withHeader('Content-Type', 'application/json; charset=utf-8')->withHeader('Content-Length', 37)->withBody($body); })); $property = self::getPrivateProperty('consumer_key'); $api = new Api($this->application_key, $this->application_secret, $this->endpoint, $this->consumer_key, $this->client); $accessRules = [json_decode(' { "method": "GET", "path": "/*" } ')]; $credentials = $api->requestCredentials($accessRules); $consumer_key = $property->getValue($api); $this->assertEquals($consumer_key, $credentials["consumerKey"]); $this->assertNotEquals($consumer_key, $this->consumer_key); }