Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add auth checking for Auth Tokens as well

  • Loading branch information...
commit 81f125e4c0f5b96ea5c90e0badce219c3ec65298 1 parent 37b6535
Kevin Burke authored
View
7 Services/Twilio.php
@@ -73,6 +73,13 @@ public function __construct(
"characters, like AC16db14d1d7166a09f4dc90f4e466f69f.",
E_USER_WARNING);
}
+ if (!preg_match('#^[A-Za-z0-9]{32}$#', $token)) {
+ trigger_error("It looks like you provided an invalid Auth Token.\n" .
+ "You can find your Auth Token at twilio.com/user/account.\n" .
+ "It should have 32 hexadecimal characters, like \n" .
+ "083c2ec9ac11508d30e313a4f408a0d6.",
+ E_USER_WARNING);
+ }
$_http->authenticate($sid, $token);
$this->http = $_http;
$this->accounts = new Services_Twilio_Rest_Accounts($this, "/{$this->version}/Accounts");
View
2  Services/Twilio/Capability.php
@@ -343,4 +343,4 @@ private static function handleJsonError($errno)
: 'Unknown JSON error: ' . $errno
);
}
-}
+}
View
2  Services/Twilio/RequestValidator.php
@@ -33,4 +33,4 @@ public function validate($expectedSignature, $url, $data = array())
== $expectedSignature;
}
-}
+}
View
30 tests/ResourcesTest.php
@@ -12,7 +12,7 @@ function testPartialApplication() {
'friendly_name' => '(510) 564-7903'
)))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$nums = $client->account->available_phone_numbers->getLocal('US');
$numsList = $nums->getList(array('AreaCode' => '510'));
foreach ($numsList as $num) {
@@ -30,7 +30,7 @@ function testPagePhoneNumberResource() {
'countries' => array(array('country_code' => 'CA'))
))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$page = $client->account->available_phone_numbers->getPage('0');
$this->assertEquals('CA', $page->countries[0]->country_code);
}
@@ -51,7 +51,7 @@ function testUpdateVoiceUrl()
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('voice_url' => 'foo'))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$client->account->sandbox->update('VoiceUrl', 'foo');
$this->assertEquals('foo', $client->account->sandbox->voice_url);
}
@@ -78,7 +78,7 @@ function testPost()
'validation_code' => 123456,
))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$request = $client->account->outgoing_caller_ids->create('+14158675309', array(
'FriendlyName' => 'My Home Phone Number',
));
@@ -103,7 +103,7 @@ function testPost()
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('sid' => 'AP123'))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$app = $client->account->applications->create('foo', array(
'VoiceUrl' => 'bar',
));
@@ -128,7 +128,7 @@ function testPost()
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('sid' => 'AC345'))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$account = $client->accounts->create(array(
'FriendlyName' => 'foo',
));
@@ -158,7 +158,7 @@ function testUpdateWithArray()
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('friendly_name' => 'Bar'))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$cn = $client->account->connect_apps->get('CN123');
$this->assertEquals('foo', $cn->friendly_name);
$cn->update(array('FriendlyName' => 'Bar'));
@@ -180,7 +180,7 @@ function testUpdateWithOneParam()
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('friendly_name' => 'Bar'))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$cn = $client->account->connect_apps->get('CN123');
$this->assertEquals('foo', $cn->friendly_name);
$cn->update('FriendlyName', 'Bar');
@@ -200,7 +200,7 @@ function testDelete() {
$http->shouldReceive('delete')->once()
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/Notifications/NO123.json')
->andReturn(array(204, array(), ''));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$client->account->notifications->delete('NO123');
}
@@ -222,7 +222,7 @@ function testCreateMessage() {
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('sid' => 'SM123'))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$sms = $client->account->sms_messages->create('+1222', '+44123', 'Hi there');
$this->assertSame('SM123', $sms->sid);
}
@@ -239,7 +239,7 @@ function testBadMessageThrowsException() {
'message' => 'Too long',
))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', null, $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', null, $http);
$sms = $client->account->sms_messages->create('+1222', '+44123',
str_repeat('hi', 81));
}
@@ -278,7 +278,7 @@ function testFront() {
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('call_sid' => 'CA123', 'position' => 0))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$queue = $client->account->queues->get('QQ123');
$firstMember = $queue->members->front();
$this->assertSame($firstMember->call_sid, 'CA123');
@@ -292,7 +292,7 @@ function testDequeueFront() {
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('call_sid' => 'CA123', 'position' => 0))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$queue = $client->account->queues->get('QQ123');
$firstMember = $queue->members->front();
$firstMember->dequeue('http://foo.com');
@@ -306,7 +306,7 @@ function testDequeueSid() {
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('call_sid' => 'CA123', 'position' => 0))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$queue = $client->account->queues->get('QQ123');
$firstMember = $queue->members->get('CA123');
$firstMember->dequeue('http://foo.com', 'GET');
@@ -330,7 +330,7 @@ function testCreate() {
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('sid' => 'QQ123', 'average_wait_time' => 0))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$queue = $client->account->queues->create('foo',
array('MaxSize' => 123));
$this->assertSame($queue->sid, 'QQ123');
View
64 tests/TwilioTest.php
@@ -5,7 +5,7 @@
class TwilioTest extends PHPUnit_Framework_TestCase {
protected $formHeaders = array('Content-Type' => 'application/x-www-form-urlencoded');
- protected $callParams = array('To' => '123', 'From' => '123', 'Url' => 'http://example.com');
+ protected $callParams = array('To' => '11111111111111111111111111111111', 'From' => '11111111111111111111111111111111', 'Url' => 'http://example.com');
protected $nginxError = array(500, array('Content-Type' => 'text/html'),
'<html>Nginx 500 error</html>'
);
@@ -48,7 +48,7 @@ function testNeedsRefining() {
'friendly_name' => 'Robert Paulson',
))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$this->assertEquals('AC11111111111111111111111111111111', $client->account->sid);
$this->assertEquals('Robert Paulson', $client->account->friendly_name);
}
@@ -56,24 +56,24 @@ function testNeedsRefining() {
function testAccessSidAvoidsNetworkCall() {
$http = m::mock(new Services_Twilio_TinyHttp);
$http->shouldReceive('get')->never();
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$client->account->sid;
}
function testOnlyOneClientCreated() {
- $client = new Services_Twilio('AC11111111111111111111111111111111', '456');
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111');
$client->account->client->sid = 'CL456';
$this->assertSame('CL456', $client->account->sandbox->client->sid);
}
function testNullVersionReturnsNewest() {
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', null);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', null);
$this->assertEquals('2010-04-01', $client->getVersion());
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', 'v1');
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', 'v1');
$this->assertEquals('2010-04-01', $client->getVersion());
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01');
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01');
$this->assertEquals('2010-04-01', $client->getVersion());
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2008-08-01');
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2008-08-01');
$this->assertEquals('2008-08-01', $client->getVersion());
}
@@ -88,7 +88,7 @@ function testObjectLoadsOnlyOnce() {
'status' => 'active',
))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$client->account->friendly_name;
$client->account->friendly_name;
$client->account->status;
@@ -102,7 +102,7 @@ function testSubresourceLoad() {
json_encode(array('status' => 'Completed'))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$this->assertEquals(
'Completed',
$client->account->calls->get('CA123')->status
@@ -117,7 +117,7 @@ function testSubresourceSubresource() {
json_encode(array('message_text' => 'Foo'))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$notifs = $client->account->calls->get('CA123')->notifications;
$this->assertEquals('Foo', $notifs->get('NO123')->message_text);
}
@@ -133,7 +133,7 @@ function testGetIteratorUsesFilters() {
'calls' => array(array('status' => 'Completed', 'sid' => 'CA123'))
))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$iterator = $client->account->calls->getIterator(
0, 10, array('StartTime>' => '2009-07-06'));
foreach ($iterator as $call) {
@@ -152,7 +152,7 @@ function testListResource() {
'calls' => array(array('status' => 'completed', 'sid' => 'CA123'))
))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$page = $client->account->calls->getPage(0, 10);
$call = current($page->getItems());
$this->assertEquals('completed', $call->status);
@@ -180,7 +180,7 @@ function testInstanceResourceUriConstructionFromList() {
'status' => 'completed'
))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$page = $client->account->calls->getPage(0, 10);
$call = current($page->getItems());
@@ -214,7 +214,7 @@ function testInstanceResourceUriConstructionFromGet() {
'uri' => 'junk_uri'
))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$number = $client->account->incoming_phone_numbers->get('PN123');
$this->assertSame($number->sms_method, 'POST');
@@ -232,7 +232,7 @@ function testIterateOverPage() {
'calls' => array(array('status' => 'Completed', 'sid' => 'CA123'))
))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$page = $client->account->calls->getPage(0, 10);
foreach ($page->getIterator() as $pageitems) {
$this->assertSame('CA123', $pageitems->sid);
@@ -248,7 +248,7 @@ function testAsymmetricallyNamedResources() {
array('status' => 'sent', 'sid' => 'SM123')
)))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$sms = current($client->account->sms_messages->getPage(0, 10)->getItems());
$this->assertEquals('sent', $sms->status);
}
@@ -263,7 +263,7 @@ function testParams() {
array('Content-Type' => 'application/json'),
'{"accounts":[]}'
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$client->accounts->getPage(0, 10, array(
'FriendlyName' => 'foo',
'Status' => 'active',
@@ -279,8 +279,8 @@ function testUpdate() {
array(200, array('Content-Type' => 'application/json'),
'{"sid":"CA123"}')
);
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
- $client->account->calls->create('123', '123', 'http://example.com');
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
+ $client->account->calls->create('11111111111111111111111111111111', '11111111111111111111111111111111', 'http://example.com');
}
function testModifyLiveCall() {
@@ -301,9 +301,9 @@ function testModifyLiveCall() {
'{"sid":"CA123"}'
)
);
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$calls = $client->account->calls;
- $call = $calls->create('123', '123', 'http://example.com');
+ $call = $calls->create('11111111111111111111111111111111', '11111111111111111111111111111111', 'http://example.com');
$call->hangup();
}
@@ -325,7 +325,7 @@ function testUnmute() {
)->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array())
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$conf = $client->account->conferences->get('CF123');
$page = $conf->participants->getPage(0, 10);
foreach ($page->getItems() as $participant) {
@@ -345,7 +345,7 @@ function testResourcePropertiesReflectUpdates() {
->andReturn(array(200, array('Content-Type' => 'application/json'),
json_encode(array('friendly_name' => 'bar'))
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$this->assertEquals('foo', $client->account->friendly_name);
$client->account->update('FriendlyName', 'bar');
$this->assertEquals('bar', $client->account->friendly_name);
@@ -367,7 +367,7 @@ function testArrayAccessForListResources() {
->andReturn(array(400, array('Content-Type' => 'application/json'),
'{"status":400,"message":"foo", "code": "20006"}'
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
foreach ($client->account->calls as $call) {
$this->assertEquals('CA123', $call->sid);
}
@@ -418,7 +418,7 @@ function testDeepPagingUsesAfterSid() {
->andReturn(array(400, array('Content-Type' => 'application/json'),
'{"status":400,"message":"foo", "code": "20006"}'
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
foreach ($client->account->calls->getIterator(0, 1) as $call) {
$this->assertSame($call->price, '-0.02000');
}
@@ -458,7 +458,7 @@ function testIteratorWithFiltersPagesCorrectly() {
'{"status":400,"message":"foo", "code": "20006"}'
));
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
foreach ($client->account->recordings->getIterator(0, 1, array('DateCreated>' => '2011-01-01')) as $recording) {
$this->assertSame($recording->duration, 7);
}
@@ -475,7 +475,7 @@ function testRetryOn500() {
json_encode(array('price' => 0.5))
)
);
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$message = $client->account->sms_messages->get('SM123');
$this->assertSame($message->price, 0.5);
}
@@ -490,7 +490,7 @@ function testDeleteOn500() {
->andReturn(
array(204, array('Content-Type' => 'application/json'), '')
);
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$client->account->sms_messages->delete('SM123');
}
@@ -509,7 +509,7 @@ function testSetExplicitRetryLimit() {
)
);
// retry twice
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http, 2);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http, 2);
$message = $client->account->sms_messages->get('SM123');
$this->assertSame($message->price, 0.5);
}
@@ -529,7 +529,7 @@ function testRetryLimitIsHonored() {
json_encode(array('price' => 0.5))
)
);
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$message = $client->account->sms_messages->get('SM123');
$this->assertSame($message->price, 0.5);
}
@@ -541,7 +541,7 @@ function testRetryIdempotentFunctionsOnly() {
->with('/2010-04-01/Accounts/AC11111111111111111111111111111111/SMS/Messages.json', $this->formHeaders,
'From=%2B14105551234&To=%2B14102221234&Body=bar')
->andReturn($this->nginxError);
- $client = new Services_Twilio('AC11111111111111111111111111111111', '123', '2010-04-01', $http);
+ $client = new Services_Twilio('AC11111111111111111111111111111111', '11111111111111111111111111111111', '2010-04-01', $http);
$message = $client->account->sms_messages->create('+14105551234',
'+14102221234', 'bar');
}
View
4 tests/TwimlTest.php
@@ -339,14 +339,14 @@ function testGeneration() {
$r = new Services_Twilio_Twiml();
$r->say('hello');
- $r->dial()->number('123', array('sendDigits' => '456'));
+ $r->dial()->number('11111111111111111111111111111111', array('sendDigits' => '456'));
$r->gather(array('timeout' => 15));
$doc = simplexml_load_string($r);
$this->assertEquals('Response', $doc->getName());
$this->assertEquals('hello', (string) $doc->Say);
$this->assertEquals('456', (string) $doc->Dial->Number['sendDigits']);
- $this->assertEquals('123', (string) $doc->Dial->Number);
+ $this->assertEquals('11111111111111111111111111111111', (string) $doc->Dial->Number);
$this->assertEquals('15', (string) $doc->Gather['timeout']);
}
Please sign in to comment.
Something went wrong with that request. Please try again.