/**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('ably', function ($app) {
         AblyRest::setLibraryFlavourString('laravel');
         return new AblyRest(config('ably'));
     });
 }
Example #2
0
 /**
  * Creates a new AblyRest instance
  *
  * @param array|null $clientOptions
  *
  * @return \Ably\AblyRest
  */
 protected function createInstance($clientOptions)
 {
     AblyRest::setLibraryFlavourString('laravel');
     return new AblyRest($clientOptions);
 }
Example #3
0
 /**
  * Verify that the token string is Base64 encoded and used in the `Authorization: Bearer` header
  */
 public function testHTTPHeadersToken()
 {
     $fakeToken = 'fakeToken';
     $ably = new AblyRest(['token' => $fakeToken, 'httpClass' => 'authTest\\HttpMock']);
     $ably->get("/dummy_test");
     $this->assertRegExp('/Authorization\\s*:\\s*Bearer\\s+' . base64_encode($fakeToken) . '/i', $ably->http->headers[0]);
 }
Example #4
0
 /**
  * Verify that time fails without valid host
  */
 public function testTimeFailsWithInvalidHost()
 {
     $ablyInvalidHost = new AblyRest(['key' => 'fake.key:veryFake', 'restHost' => 'this.host.does.not.exist']);
     $this->setExpectedException('Ably\\Exceptions\\AblyRequestException');
     $reportedTime = $ablyInvalidHost->time();
 }
Example #5
0
 /**
  * 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
 }
Example #6
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');
 }
Example #7
0
 /**
  * Test that Response handles various returned structures properly
  */
 public function testRequestReturnValues()
 {
     $ably = new AblyRest(['key' => 'fake.key:totallyFake', 'httpClass' => 'tests\\HttpMockReturnData']);
     // array of objects
     $ably->http->setResponseJSONString('[{"test":"one"},{"test":"two"},{"test":"three"}]');
     $res1 = $ably->request('GET', '/get_test_json');
     $this->assertEquals('[{"test":"one"},{"test":"two"},{"test":"three"}]', json_encode($res1->items));
     // array with single object
     $ably->http->setResponseJSONString('[{"test":"yes"}]');
     $res2 = $ably->request('GET', '/get_test_json');
     $this->assertEquals('[{"test":"yes"}]', json_encode($res2->items));
     // single object - should be returned as array with single object
     $ably->http->setResponseJSONString('{"test":"yes"}');
     $res3 = $ably->request('GET', '/get_test_json');
     $this->assertEquals('[{"test":"yes"}]', json_encode($res3->items));
     // not an object or array - should be returned as empty array
     $ably->http->setResponseJSONString('"invalid"');
     $res4 = $ably->request('GET', '/get_test_json');
     $this->assertEquals('[]', json_encode($res4->items));
 }