public function testDeleteExistingOne() { $resource_server = ResourceServer::where('host', '=', $this->current_host)->first(); $new_id = $resource_server->id; $response = $this->action("DELETE", "ApiResourceServerController@delete", $parameters = array('id' => $new_id), array(), array(), array()); $this->assertResponseStatus(204); $response = $this->action("GET", "ApiResourceServerController@get", $parameters = array('id' => $new_id), array(), array(), array()); $this->assertResponseStatus(404); }
public function testUpdateStatus() { $resource_server = ResourceServer::where('host', '=', $this->current_host)->first(); $data = array('name' => 'test-api', 'description' => 'test api', 'active' => true, 'resource_server_id' => $resource_server->id); $response = $this->action("POST", "ApiController@create", $data); $this->assertResponseStatus(201); $content = $response->getContent(); $json_response = json_decode($content); $this->assertTrue(isset($json_response->api_id) && !empty($json_response->api_id)); $new_id = $json_response->api_id; //update status $response = $this->action("PUT", "ApiController@activate", array('id' => $new_id)); $this->assertResponseStatus(200); $content = $response->getContent(); $json_response = json_decode($content); $this->assertTrue($json_response === 'ok'); $response = $this->action("GET", "ApiController@get", $parameters = array('id' => $new_id)); $this->assertResponseStatus(200); $content = $response->getContent(); $updated_values = json_decode($content); $this->assertTrue($updated_values->active == true); }
/** * Checks if current_ip has access rights on the given $access_token * @param AccessToken $access_token * @param $current_ip * @return bool */ public function checkAccessTokenAudience(AccessToken $access_token, $current_ip) { $current_audience = $access_token->getAudience(); $current_audience = explode(' ', $current_audience); if (!is_array($current_audience)) { $current_audience = array($current_audience); } return \ResourceServer::where('active', '=', true)->where('ip', '=', $current_ip)->whereIn('host', $current_audience)->count() > 0; }