Ejemplo n.º 1
0
 /**
  * @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');
 }
Ejemplo n.º 2
0
 /**
  * @test
  *
  * Ensure empty callback and verifier don't get put into the base string
  */
 public function ensureEmptyVerifierAndCallbackAreRemoved()
 {
     $this->signature->setHttpMethod('post');
     $this->signature->setResourceUrl('https://example.com/api/user');
     $baseString = rawurldecode($this->signature->createBaseString());
     $array = [];
     parse_str($baseString, $array);
     // might be an assertion to check for missing array key...
     $this->assertFalse(isset($array['oauth_verifier']));
     $this->assertFalse(isset($array['oauth_callback']));
 }
Ejemplo n.º 3
0
 /**
  * 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();
 }
Ejemplo n.º 4
0
 /**
  * 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()));
 }
Ejemplo n.º 5
0
 /**
  * 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);
 }