예제 #1
0
파일: TokenTest.php 프로젝트: ably/ably-php
 /**
  * Automatic token renewal on expiration (unknown time) should fail with no means of renewal
  */
 public function testFailingTokenRenewalUnknownExpiration()
 {
     $ablyKeyAuth = self::$ably;
     $tokenParams = ['ttl' => 2 * 1000];
     $tokenDetails = $ablyKeyAuth->auth->requestToken($tokenParams);
     $options = array_merge(self::$defaultOptions, ['token' => $tokenDetails->token]);
     $ablyTokenAuth = new AblyRest($options);
     $channel = $ablyTokenAuth->channel('testchannel');
     $channel->publish('test', 'test');
     // this should work
     sleep(3);
     $this->setExpectedException('Ably\\Exceptions\\AblyException', '', 40101);
     $channel->publish('test', 'test');
     // this should fail
 }
예제 #2
0
 /**
  * Encryption key mismatch - publish message with key1, retrieve history with key2
  */
 public function testEncryptionKeyMismatch()
 {
     $errorLogged = false;
     $ably = new AblyRest(array_merge(self::$defaultOptions, ['key' => self::$testApp->getAppKeyDefault()->string, 'logHandler' => function ($level, $args) use(&$errorLogged) {
         if ($level == Log::ERROR) {
             $errorLogged = true;
         }
     }]));
     $payload = 'This is a test message';
     $options = ['cipher' => ['key' => 'fake key 1xxxxxx']];
     $encrypted1 = $ably->channel('persisted:mismatch3', $options);
     $encrypted1->publish('test', $payload);
     $options2 = ['cipher' => ['key' => 'fake key 2xxxxxx']];
     $encrypted2 = $ably->channel('persisted:mismatch3', $options2);
     $messages = $encrypted2->history();
     $msg = $messages->items[0];
     $this->assertTrue($errorLogged, 'Expected an error to be logged');
     $this->assertEquals('utf-8/cipher+aes-128-cbc/base64', $msg->originalEncoding, 'Expected the original message to be encrypted + base64 encoded');
     $this->assertEquals('utf-8/cipher+aes-128-cbc', $msg->encoding, 'Expected to receive the message still encrypted, but base64 decoded');
 }