Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F430406
CapabilityTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
CapabilityTest.php
View Options
<?php
require_once
'Twilio/Capability.php'
;
class
CapabilityTest
extends
PHPUnit_Framework_TestCase
{
public
function
testNoPermissions
()
{
$token
=
new
Services_Twilio_Capability
(
'AC123'
,
'foo'
);
$payload
=
JWT
::
decode
(
$token
->
generateToken
(),
'foo'
);
$this
->
assertEquals
(
$payload
->
iss
,
"AC123"
);
$this
->
assertEquals
(
$payload
->
scope
,
''
);
}
public
function
testInboundPermissions
()
{
$token
=
new
Services_Twilio_Capability
(
'AC123'
,
'foo'
);
$token
->
allowClientIncoming
(
"andy"
);
$payload
=
JWT
::
decode
(
$token
->
generateToken
(),
'foo'
);
$eurl
=
"scope:client:incoming?clientName=andy"
;
$this
->
assertEquals
(
$payload
->
scope
,
$eurl
);
}
public
function
testOutboundPermissions
()
{
$token
=
new
Services_Twilio_Capability
(
'AC123'
,
'foo'
);
$token
->
allowClientOutgoing
(
"AP123"
);
$payload
=
JWT
::
decode
(
$token
->
generateToken
(),
'foo'
);;
$eurl
=
"scope:client:outgoing?appSid=AP123"
;
$this
->
assertContains
(
$eurl
,
$payload
->
scope
);
}
public
function
testOutboundPermissionsParams
()
{
$token
=
new
Services_Twilio_Capability
(
'AC123'
,
'foo'
);
$token
->
allowClientOutgoing
(
"AP123"
,
array
(
"foobar"
=>
3
));
$payload
=
JWT
::
decode
(
$token
->
generateToken
(),
'foo'
);
$eurl
=
"scope:client:outgoing?appSid=AP123&appParams=foobar%3D3"
;
$this
->
assertEquals
(
$payload
->
scope
,
$eurl
);
}
public
function
testEvents
()
{
$token
=
new
Services_Twilio_Capability
(
'AC123'
,
'foo'
);
$token
->
allowEventStream
();
$payload
=
JWT
::
decode
(
$token
->
generateToken
(),
'foo'
);
$event_uri
=
"scope:stream:subscribe?path=%2F2010"
.
"-04-01%2FEvents¶ms="
;
$this
->
assertEquals
(
$payload
->
scope
,
$event_uri
);
}
public
function
testEventsWithFilters
()
{
$token
=
new
Services_Twilio_Capability
(
'AC123'
,
'foo'
);
$token
->
allowEventStream
(
array
(
"foobar"
=>
"hey"
));
$payload
=
JWT
::
decode
(
$token
->
generateToken
(),
'foo'
);
$event_uri
=
"scope:stream:subscribe?path=%2F2010-"
.
"04-01%2FEvents¶ms=foobar%3Dhey"
;
$this
->
assertEquals
(
$payload
->
scope
,
$event_uri
);
}
public
function
testDecode
()
{
$token
=
new
Services_Twilio_Capability
(
'AC123'
,
'foo'
);
$token
->
allowClientOutgoing
(
"AP123"
,
array
(
"foobar"
=>
3
));
$token
->
allowClientIncoming
(
"andy"
);
$token
->
allowEventStream
();
$outgoing_uri
=
"scope:client:outgoing?appSid="
.
"AP123&appParams=foobar%3D3&clientName=andy"
;
$incoming_uri
=
"scope:client:incoming?clientName=andy"
;
$event_uri
=
"scope:stream:subscribe?path=%2F2010-04-01%2FEvents"
;
$payload
=
JWT
::
decode
(
$token
->
generateToken
(),
'foo'
);
$scope
=
$payload
->
scope
;
$this
->
assertContains
(
$outgoing_uri
,
$scope
);
$this
->
assertContains
(
$incoming_uri
,
$scope
);
$this
->
assertContains
(
$event_uri
,
$scope
);
}
function
testDecodeWithAuthToken
()
{
try
{
$token
=
new
Services_Twilio_Capability
(
'AC123'
,
'foo'
);
$payload
=
JWT
::
decode
(
$token
->
generateToken
(),
'foo'
);
$this
->
assertSame
(
$payload
->
iss
,
'AC123'
);
}
catch
(
UnexpectedValueException
$e
)
{
$this
->
assertTrue
(
false
,
"Could not decode with 'foo'"
);
}
}
function
testClientNameValidation
()
{
$this
->
setExpectedException
(
'InvalidArgumentException'
);
$token
=
new
Services_Twilio_Capability
(
'AC123'
,
'foo'
);
$token
->
allowClientIncoming
(
'@'
);
$this
->
fail
(
'exception should have been raised'
);
}
function
zeroLengthNameInvalid
()
{
$this
->
setExpectedException
(
'InvalidArgumentException'
);
$token
=
new
Services_Twilio_Capability
(
'AC123'
,
'foo'
);
$token
->
allowClientIncoming
(
""
);
$this
->
fail
(
'exception should have been raised'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 3, 10:28 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
56395
Default Alt Text
CapabilityTest.php (3 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment