From 5c7f2f17f9c471d306955df457c7cab4e5c6ed3b Mon Sep 17 00:00:00 2001 From: Snap Date: Thu, 16 Apr 2015 14:51:26 -0700 Subject: Google's OpenID Connect method $google_client_id & $google_client_secret must be added to db.inc.php! --- .../tests/general/RestTest.php | 161 +++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 includes/google-api-php-client-master/tests/general/RestTest.php (limited to 'includes/google-api-php-client-master/tests/general/RestTest.php') diff --git a/includes/google-api-php-client-master/tests/general/RestTest.php b/includes/google-api-php-client-master/tests/general/RestTest.php new file mode 100644 index 0000000..caed129 --- /dev/null +++ b/includes/google-api-php-client-master/tests/general/RestTest.php @@ -0,0 +1,161 @@ +rest = new Google_Http_REST(); + } + + public function testDecodeResponse() + { + $url = 'http://localhost'; + $client = $this->getClient(); + $response = new Google_Http_Request($url); + $response->setResponseHttpCode(204); + $decoded = $this->rest->decodeHttpResponse($response, $client); + $this->assertEquals(null, $decoded); + + + foreach (array(200, 201) as $code) { + $headers = array('foo', 'bar'); + $response = new Google_Http_Request($url, 'GET', $headers); + $response->setResponseBody('{"a": 1}'); + + $response->setResponseHttpCode($code); + $decoded = $this->rest->decodeHttpResponse($response, $client); + $this->assertEquals(array("a" => 1), $decoded); + } + + $response = new Google_Http_Request($url); + $response->setResponseHttpCode(500); + + $error = ""; + try { + $this->rest->decodeHttpResponse($response, $client); + } catch (Exception $e) { + $error = $e->getMessage(); + + } + $this->assertEquals(trim($error), "Error calling GET http://localhost: (500)"); + } + + + public function testDecodeEmptyResponse() + { + $url = 'http://localhost'; + + $response = new Google_Http_Request($url, 'GET', array()); + $response->setResponseBody('{}'); + + $response->setResponseHttpCode(200); + $decoded = $this->rest->decodeHttpResponse($response); + $this->assertEquals(array(), $decoded); + } + + public function testCreateRequestUri() + { + $basePath = "http://localhost"; + $restPath = "/plus/{u}"; + + // Test Path + $params = array(); + $params['u']['type'] = 'string'; + $params['u']['location'] = 'path'; + $params['u']['value'] = 'me'; + $value = $this->rest->createRequestUri($basePath, $restPath, $params); + $this->assertEquals("http://localhost/plus/me", $value); + + // Test Query + $params = array(); + $params['u']['type'] = 'string'; + $params['u']['location'] = 'query'; + $params['u']['value'] = 'me'; + $value = $this->rest->createRequestUri($basePath, '/plus', $params); + $this->assertEquals("http://localhost/plus?u=me", $value); + + // Test Booleans + $params = array(); + $params['u']['type'] = 'boolean'; + $params['u']['location'] = 'path'; + $params['u']['value'] = '1'; + $value = $this->rest->createRequestUri($basePath, $restPath, $params); + $this->assertEquals("http://localhost/plus/true", $value); + + $params['u']['location'] = 'query'; + $value = $this->rest->createRequestUri($basePath, '/plus', $params); + $this->assertEquals("http://localhost/plus?u=true", $value); + + // Test encoding + $params = array(); + $params['u']['type'] = 'string'; + $params['u']['location'] = 'query'; + $params['u']['value'] = '@me/'; + $value = $this->rest->createRequestUri($basePath, '/plus', $params); + $this->assertEquals("http://localhost/plus?u=%40me%2F", $value); + } + + /** + * @expectedException Google_Service_Exception + */ + public function testBadErrorFormatting() + { + $request = new Google_Http_Request("/a/b"); + $request->setResponseHttpCode(500); + $request->setResponseBody( + '{ + "error": { + "code": 500, + "message": null + } + }' + ); + Google_Http_Rest::decodeHttpResponse($request); + } + + /** + * @expectedException Google_Service_Exception + */ + public function tesProperErrorFormatting() + { + $request = new Google_Http_Request("/a/b"); + $request->setResponseHttpCode(401); + $request->setResponseBody( + '{ + error: { + errors: [ + { + "domain": "global", + "reason": "authError", + "message": "Invalid Credentials", + "locationType": "header", + "location": "Authorization", + } + ], + "code": 401, + "message": "Invalid Credentials" + }' + ); + Google_Http_Rest::decodeHttpResponse($request); + } +} -- cgit v1.2.3