Skip to content

Commit

Permalink
Merge pull request #68 from centerorbit/master
Browse files Browse the repository at this point in the history
Fixing broken Gcm token validation.
  • Loading branch information
Ph3nol committed Jul 9, 2015
2 parents f2dd06a + d34c80b commit b751213
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Sly/NotificationPusher/Adapter/Gcm.php
Expand Up @@ -49,7 +49,7 @@ class Gcm extends BaseAdapter
*/
public function supports($token)
{
return (bool) preg_match('/^[0-9a-zA-Z\-\_]+$/i', $token);
return is_string($token) && $token != '';
}

/**
Expand Down
12 changes: 10 additions & 2 deletions tests/units/Sly/NotificationPusher/Adapter/Gcm.php
Expand Up @@ -21,6 +21,8 @@
class Gcm extends Units\Test
{
const GCM_TOKEN_EXAMPLE = 'AAA91bG9ISdL94D55C69NplFlxicy0iFUFTyWh3AAdMfP9npH5r_JQFTo27xpX1jfqGf-aSe6xZAsfWRefjazJpqFt03Isanv-Fi97020EKLye0ApTkHsw_0tJJzgA2Js0NsG1jLWsiJf63YSF8ropAcRp4BSxVBBB';
// The format of GCM tokens apparently have changed, this string looks similar to new format:
const ALT_GCM_TOKEN_EXAMPLE = 'AAA91bG9ISd:L94D55C69NplFlxicy0iFUFTyWh3AAdMfP9npH5r_JQFTo27xpX1jfqGf-aSe6xZAsfWRefjazJpqFt03Isanv-Fi97020EKLye0ApTkHsw_0tJJzgA2Js0NsG1jLWsiJf63YSF8ropA';

public function testConstruct()
{
Expand Down Expand Up @@ -49,12 +51,18 @@ public function testSupports()
$this->if($this->mockGenerator()->orphanize('__construct'))
->and($this->mockClass('\Sly\NotificationPusher\Adapter\Gcm', '\Mock'))
->and($object = new \Mock\Gcm())
->boolean($object->supports('*()*'))
->boolean($object->supports('')) // Test empty string
->isFalse()
->boolean($object->supports('ABC*()*'))
->boolean($object->supports(2)) // Test a number
->isFalse()
->boolean($object->supports(array())) // Test an array
->isFalse()
->boolean($object->supports(json_decode('{}'))) // Tests an object
->isFalse()
->boolean($object->supports(self::GCM_TOKEN_EXAMPLE))
->isTrue()
->boolean($object->supports(self::ALT_GCM_TOKEN_EXAMPLE))
->isTrue()
;
}

Expand Down

0 comments on commit b751213

Please sign in to comment.