Beispiel #1
0
 public function testCheckTimestamp()
 {
     static::assertTrue($this->validator->checkTimestamp(time()));
     static::assertTrue($this->validator->checkTimestamp(time() + 180));
     static::assertTrue($this->validator->checkTimestamp(time() - 180));
     static::assertFalse($this->validator->checkTimestamp(time() + 181));
     static::assertFalse($this->validator->checkTimestamp(time() - 181));
 }
 /**
  * @param string            $uid
  * @param int               $timestamp Unix Timestamp
  * @param string            $signature
  * @param ResponseInterface $response
  *
  * @throws InvalidTimestampException
  * @throws InvalidUidSignatureException
  *
  * @return bool
  */
 private function assertUid($uid, $timestamp, $signature, ResponseInterface $response)
 {
     if (!$this->signature->checkTimestamp($timestamp)) {
         throw new InvalidTimestampException($timestamp, $response);
     }
     $expected = $this->signature->getUidSignature($uid, $timestamp, $this->secret);
     if ($signature !== $expected) {
         throw new InvalidUidSignatureException($uid, $expected, $signature, $response);
     }
     return true;
 }
Beispiel #3
0
 public function createAccountInfoHandler()
 {
     $handler = new MockHandler();
     for ($i = 0; $i < 1000; $i++) {
         $handler->append(function () {
             $uid = 'diofu90ifgdf';
             $timestamp = time();
             $signatureValidator = new Signature();
             $signature = $signatureValidator->calculateSignature($timestamp . '_' . $uid, 'secret');
             return new Response(200, [], sprintf('{
                 "UID": "%s",
                 "UIDSignature": "%s",
                 "signatureTimestamp": "%d",
                 "statusCode": 200,
                 "errorCode": 0,
                 "statusReason": "OK",
                 "callId": "123456",
                 "time": "2015-03-22T11:42:25.943Z"
             }', $uid, $signature, $timestamp));
         });
     }
     $this->gigya = new Gigya('key', 'secret', null, null, ['guzzle' => ['handler' => new HandlerStack($handler)]]);
 }
Beispiel #4
0
 public function testUidSignatureWhenIncorrectTimestampThrowsAnException()
 {
     $uid = 'diofu90ifgdf';
     $timestamp = time() - 181;
     $signatureValidator = new Signature();
     $signature = $signatureValidator->calculateSignature($timestamp . '_' . $uid, 'secret');
     $body = sprintf('{
         "UID": "%s",
         "UIDSignature": "%s",
         "signatureTimestamp": "%d",
         "statusCode": 200,
         "errorCode": 0,
         "statusReason": "OK",
         "callId": "123456",
         "time": "2015-03-22T11:42:25.943Z"
     }', $uid, $signature, $timestamp);
     $handler = $this->setupHandler($body);
     $client = new Gigya('key', 'secret', null, null, ['guzzle' => ['handler' => $handler]]);
     static::expectException(InvalidTimestampException::class);
     $client->accounts()->getAccountInfo(['uid' => $uid]);
 }