public function test_validate_authentication() { $data = array("username" => "Lord_Gaav", "password" => "123StrongPassword", "local_user" => "gaav", "token" => ""); $validator = new AuthenticationValidator($data); $this->assertFalse($validator->validates()); $this->assertCount(1, $validator->getErrors()); $data['token'] = "0123456789012345678901234567890123456789"; $validator = new AuthenticationValidator($data); $this->assertTrue($validator->validates()); $this->assertEmpty($validator->getErrors()); }
/** * Corresponds to session logout. * * ### Response: ### * * ~~~ * true * ~~~ * * ### Errors: ### * * * 500 - Missing or token with invalid format. * * 500 - Could not destroy token. * * 403 - Invalid token. * * @access public * @param mixed $request Request parameters * @param string $token Authentication token * @return Response True if session was terminated, error message otherwise. */ public function delete($request, $token = null) { $response = new FormattedResponse($request); $data = $request->parseData(); if (!isset($token)) { $response->code = Response::BADREQUEST; $response->error = "Token was missing or invalid."; $response->error_detail = "MISSING_REQUIRED_PARAMETERS"; return $response; } $validator = new AuthenticationValidator(); $validator->token = $token; if (!$validator->validates()) { $response->code = Response::BADREQUEST; $response->error = $validator->getFormattedErrors(); $response->error_detail = $validator->getErrorDetails(); return $response; } $t = $this->backend->retrieveToken($token); if ($t == null) { $response->code = Response::FORBIDDEN; $response->error = "Token was invalid."; $response->error_detail = "AUTH_INVALID_TOKEN"; return $response; } if (!$this->backend->destroyToken($t)) { $response->code = Response::INTERNALSERVERERROR; $response->error = "Token could not be destroyed."; $response->error_detail = "INTERNAL_SERVER_ERROR"; return $response; } $response->code = Response::OK; $response->body = true; $response->log_message = "Token was successfully invalidated."; return $response; }