[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 require_once 'Twilio/Capability.php'; 4 5 class CapabilityTest extends PHPUnit_Framework_TestCase { 6 7 public function testNoPermissions() { 8 $token = new Services_Twilio_Capability('AC123', 'foo'); 9 $payload = JWT::decode($token->generateToken(), 'foo'); 10 $this->assertEquals($payload->iss, "AC123"); 11 $this->assertEquals($payload->scope, ''); 12 } 13 14 public function testInboundPermissions() { 15 $token = new Services_Twilio_Capability('AC123', 'foo'); 16 $token->allowClientIncoming("andy"); 17 $payload = JWT::decode($token->generateToken(), 'foo'); 18 19 $eurl = "scope:client:incoming?clientName=andy"; 20 $this->assertEquals($payload->scope, $eurl); 21 } 22 23 public function testOutboundPermissions() { 24 $token = new Services_Twilio_Capability('AC123', 'foo'); 25 $token->allowClientOutgoing("AP123"); 26 $payload = JWT::decode($token->generateToken(), 'foo');; 27 $eurl = "scope:client:outgoing?appSid=AP123"; 28 $this->assertContains($eurl, $payload->scope); 29 } 30 31 public function testOutboundPermissionsParams() { 32 $token = new Services_Twilio_Capability('AC123', 'foo'); 33 $token->allowClientOutgoing("AP123", array("foobar" => 3)); 34 $payload = JWT::decode($token->generateToken(), 'foo'); 35 36 $eurl = "scope:client:outgoing?appSid=AP123&appParams=foobar%3D3"; 37 $this->assertEquals($payload->scope, $eurl); 38 } 39 40 public function testEvents() { 41 $token = new Services_Twilio_Capability('AC123', 'foo'); 42 $token->allowEventStream(); 43 $payload = JWT::decode($token->generateToken(), 'foo'); 44 45 $event_uri = "scope:stream:subscribe?path=%2F2010" 46 . "-04-01%2FEvents¶ms="; 47 $this->assertEquals($payload->scope, $event_uri); 48 } 49 50 public function testEventsWithFilters() { 51 $token = new Services_Twilio_Capability('AC123', 'foo'); 52 $token->allowEventStream(array("foobar" => "hey")); 53 $payload = JWT::decode($token->generateToken(), 'foo'); 54 55 $event_uri = "scope:stream:subscribe?path=%2F2010-" 56 . "04-01%2FEvents¶ms=foobar%3Dhey"; 57 $this->assertEquals($payload->scope, $event_uri); 58 } 59 60 61 public function testDecode() { 62 $token = new Services_Twilio_Capability('AC123', 'foo'); 63 $token->allowClientOutgoing("AP123", array("foobar"=> 3)); 64 $token->allowClientIncoming("andy"); 65 $token->allowEventStream(); 66 67 $outgoing_uri = "scope:client:outgoing?appSid=" 68 . "AP123&appParams=foobar%3D3&clientName=andy"; 69 $incoming_uri = "scope:client:incoming?clientName=andy"; 70 $event_uri = "scope:stream:subscribe?path=%2F2010-04-01%2FEvents"; 71 72 $payload = JWT::decode($token->generateToken(), 'foo'); 73 $scope = $payload->scope; 74 75 $this->assertContains($outgoing_uri, $scope); 76 $this->assertContains($incoming_uri, $scope); 77 $this->assertContains($event_uri, $scope); 78 } 79 80 81 function testDecodeWithAuthToken() { 82 try { 83 $token = new Services_Twilio_Capability('AC123', 'foo'); 84 $payload = JWT::decode($token->generateToken(), 'foo'); 85 $this->assertSame($payload->iss, 'AC123'); 86 } catch (UnexpectedValueException $e) { 87 $this->assertTrue(false, "Could not decode with 'foo'"); 88 } 89 } 90 91 function testClientNameValidation() { 92 $this->setExpectedException('InvalidArgumentException'); 93 $token = new Services_Twilio_Capability('AC123', 'foo'); 94 $token->allowClientIncoming('@'); 95 $this->fail('exception should have been raised'); 96 } 97 98 function zeroLengthNameInvalid() { 99 $this->setExpectedException('InvalidArgumentException'); 100 $token = new Services_Twilio_Capability('AC123', 'foo'); 101 $token->allowClientIncoming(""); 102 $this->fail('exception should have been raised'); 103 } 104 105 106 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |