/** * @test * * Test to ensure header is created with identifiable information with a verifier */ public function verifyHeaderHasIdentifiableInformationWithVerifier() { $this->signature->setHttpMethod('get'); $this->signature->setResourceURL('https://example.com/api'); $this->signature->setVerifier('12345abc'); $this->signature->setCallback('https://my.site/callback'); $header = new Header(); $header->setSignature($this->signature); $headerString = $header->createAuthorizationHeader(true); $this->assertContains('oauth_token="ACCESS_TOKEN"', $headerString, 'Access token not set'); $this->assertContains('Authorization:', $headerString, 'Authorization prefix missing'); $this->assertContains('oauth_version="1.0"', $headerString, 'OAuth version missing'); $this->assertContains('oauth_signature_method="HMAC-SHA1"', $headerString, 'Signature method missing'); $this->assertContains('oauth_verifier="12345abc"', $headerString, 'Verifier Missing'); }
/** * @test * * Ensure verifier can be set */ public function ensureVerifierCanBeSet() { $verifier = '12345abc'; $signature = $this->signature->setVerifier($verifier); $this->assertEquals($verifier, $this->signature->getVerifier()); $this->assertSame($signature, $this->signature); }
/** * Test to ensure the get method for sent DMs is being called correctly */ public function testEnsureGetMethodIsCalledCorrectlyForSentDMS() { $signature = new HmacSha1($this->consumer, $this->access); $signature->setHttpMethod('GET'); $signature->setResourceURL('https://api.twitter.com/1.1/direct_messages/sent.json'); $signature->setTimestamp(1114234234234); $signature->setNonce('testNonce'); $header = new Header(); $header->setSignature($signature); $expectedHeader = $header->createAuthorizationHeader(); $this->client->setSignature($signature); $this->client->expects($this->once())->method('makeGetRequest')->with('direct_messages/sent.json', []); $tweet = new DirectMessage($this->client); $tweet->retrieveLatestSentMessages(); }
/** * Accessor method for setting a preconfigured signature which will set the other * properties from the data contained in the signature * * @param HmacSha1 $signature */ public function setSignature(HmacSha1 $signature) { $this->signature = $signature; $this->resourceUrl = $signature->getResourceURL(); $this->httpMethod = $signature->getHttpMethod(); $this->nonce = $signature->getNonce(); $this->timestamp = $signature->getTimestamp(); $this->verifier = $signature->getVerifier(); $this->postFields = $signature->getPostFields(); }
/** * test to ensure the set properties are in the header */ public function testEnsureHeaderIsBeingCreated() { $timestamp = 1420302568; $nonce = '3e448845e49f46fc47335a8537333ada'; $signature = new HmacSha1($this->consumerToken, $this->accessToken); $signature->setResourceURL('http://api.twitter.com/1.1/statuses/show/460095281871073282.json'); $signature->setHttpMethod('GET'); $signature->setNonce($nonce); $signature->setTimestamp($timestamp); $matchSignature = rawurlencode($signature->sign()); $this->twitter->setResourceUrl('http://api.twitter.com/1.1/statuses/show/460095281871073282.json'); $this->twitter->setHttpMethod('GET'); $this->twitter->setNonce($nonce); $this->twitter->setTimestamp($timestamp); $header = $this->twitter->getAuthorizationHeader(); $this->assertGreaterThan(0, strpos($header, $matchSignature), $matchSignature . ' is not in ' . $header); $this->assertGreaterThan(0, strpos($header, $this->accessToken->getIdentifier())); }
/** * Test to ensure delete is being called correctly */ public function testEnsureDeleteIsHitCorrectly() { $signature = new HmacSha1($this->consumer, $this->access); $signature->setHttpMethod('POST'); $signature->setResourceURL('https://api.twitter.com/1.1/statuses/destroy/1.json'); $signature->setTimestamp(1114234234234); $signature->setNonce('testNonce'); $header = new Header(); $header->setSignature($signature); $expectedHeader = $header->createAuthorizationHeader(); $this->client->setSignature($signature); $this->client->expects($this->once())->method('makePostRequest')->with('statuses/destroy/1.json'); $tweet = new Tweet($this->client); $tweet->delete(1); }