diff --git a/tests/HmacSha1Test.php b/tests/HmacSha1Test.php new file mode 100644 index 0000000..0c2ec35 --- /dev/null +++ b/tests/HmacSha1Test.php @@ -0,0 +1,79 @@ +getSignatureMethod(); + $this->assertEquals('HMAC-SHA1', $hmacsha1->getName()); + } + + public function testBuildSignatureWithoutToken() + { + // Create instance of class to test + $hmacsha1 = $this->getSignatureMethod(); + + // Get mock objects + $request = $this->getRequest(); + $client = $this->getClient(); + + // Run method being tested + $signature = $hmacsha1->buildSignature($request, $client); + + // Check results + $this->assertEquals('RaZU4UG/wwJ/E5Df2/pePmwaS1Q=', $signature); + } + + public function testBuildSignatureWithToken() + { + // Create instance of class to test + $hmacsha1 = $this->getSignatureMethod(); + + // Get mock objects + $request = $this->getRequest(); + $client = $this->getClient(); + $token = $this->getToken(); + + // Run method being tested + $signature = $hmacsha1->buildSignature($request, $client, $token); + + // Check results + $this->assertEquals('1P/rfHzjnxBcNzngW9BEuT01goM=', $signature); + } + + private function getSignatureMethod() + { + return new HmacSha1; + } + + private function getRequest() + { + return m::mock('GaryJones\OAuth\Request', function ($mock) { + $mock->shouldReceive('getSignatureBaseString') + ->withNoArgs() + ->andReturn('POST&http%3A%2F%2Fexample.com%2Ffoobar&oauth_signature_method%3DHMAC-SHA1')->once(); + }); + } + + private function getClient() + { + return m::mock('GaryJones\OAuth\Client', function ($mock) { + $mock->shouldReceive('getSecret')->withNoArgs()->andReturn('secret')->once(); + }); + } + + private function getToken() + { + return m::mock('GaryJones\OAuth\Token', function ($mock) { + $mock->shouldReceive('getSecret')->withNoArgs()->andReturn('token_secret'); + }); + } +} diff --git a/tests/PlainTextTest.php b/tests/PlainTextTest.php new file mode 100644 index 0000000..e435b8b --- /dev/null +++ b/tests/PlainTextTest.php @@ -0,0 +1,75 @@ +getSignatureMethod(); + $this->assertEquals('PLAINTEXT', $plaintext->getName()); + } + + public function testBuildSignatureWithoutToken() + { + // Create instance of class to test + $plaintext = $this->getSignatureMethod(); + + // Get mock objects + $request = $this->getRequest(); + $client = $this->getClient(); + + // Run method being tested + $signature = $plaintext->buildSignature($request, $client); + + // Check results + $this->assertEquals('secret&', $signature); + } + + public function testBuildSignatureWithToken() + { + // Create instance of class to test + $plaintext = $this->getSignatureMethod(); + + // Get mock objects + $request = $this->getRequest(); + $client = $this->getClient(); + $token = $this->getToken(); + + // Run method being tested + $signature = $plaintext->buildSignature($request, $client, $token); + + // Check results + $this->assertEquals('secret&token_secret', $signature); + } + + private function getSignatureMethod() + { + return new PlainText; + } + + private function getRequest() + { + return m::mock('GaryJones\OAuth\Request'); + } + + private function getClient() + { + return m::mock('GaryJones\OAuth\Client', function ($mock) { + $mock->shouldReceive('getSecret')->withNoArgs()->andReturn('secret')->once(); + }); + } + + private function getToken() + { + return m::mock('GaryJones\OAuth\Token', function ($mock) { + $mock->shouldReceive('getSecret')->withNoArgs()->andReturn('token_secret'); + }); + } +} diff --git a/tests/RequestTest.php b/tests/RequestTest.php new file mode 100644 index 0000000..6306ca7 --- /dev/null +++ b/tests/RequestTest.php @@ -0,0 +1,36 @@ +assertEquals('FOO', $request->getNormalizedHttpMethod()); + } + + public function testHttpUrlCanBeNormalized() + { + $request = new Request('foo', 'bar'); + $this->assertEquals('http://bar', $request->getNormalizedHttpUrl()); + $request = new Request('foo', 'example.com:80'); + $this->assertEquals('http://example.com', $request->getNormalizedHttpUrl()); + $request = new Request('foo', 'example.com:81'); + $this->assertEquals('http://example.com:81', $request->getNormalizedHttpUrl()); + $request = new Request('foo', 'https://example.com'); + $this->assertEquals('https://example.com', $request->getNormalizedHttpUrl()); + $request = new Request('foo', 'https://example.com:443'); + $this->assertEquals('https://example.com', $request->getNormalizedHttpUrl()); + $request = new Request('foo', 'http://example.com/foobar'); + $this->assertEquals('http://example.com/foobar', $request->getNormalizedHttpUrl()); + $request = new Request('foo', 'example.org:80/foobar'); + $this->assertEquals('http://example.org/foobar', $request->getNormalizedHttpUrl()); + } +}