Skip to content

Commit

Permalink
Add tests for ID token verification
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Jan 16, 2018
1 parent 3586a27 commit b3bd435
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/Firebase/Integration/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function testUserWithEmailAndPassword()

$this->assertSame($email, $user->getEmail());
$this->assertFalse($user->hasVerifiedEmail());
$this->auth->verifyIdToken((string) $user->getIdToken()); // should not throw an exception
$this->assertNotEmpty($user->getRefreshToken());

$this->auth->deleteUser($user);
Expand Down Expand Up @@ -137,4 +136,30 @@ public function testListUsers()

$this->assertTrue($noExceptionHasBeenThrown = true);
}

public function testVerifyIdToken()
{
$user = $this->auth->createAnonymousUser();

$idToken = $user->getIdToken();

$this->auth->verifyIdToken($idToken);

$this->auth->deleteUser($user);

$this->assertTrue($noExceptionHasBeenThrown = true);
}

public function testVerifyIdTokenString()
{
$user = $this->auth->createAnonymousUser();

$idToken = $user->getIdToken();

$this->auth->verifyIdToken((string) $idToken);

$this->auth->deleteUser($user);

$this->assertTrue($noExceptionHasBeenThrown = true);
}
}
15 changes: 15 additions & 0 deletions tests/Firebase/Unit/Auth/IdTokenVerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Kreait\Firebase\Auth\IdTokenVerifier;
use Kreait\Firebase\Exception\Auth\InvalidIdToken;
use Kreait\Tests\Firebase\Unit\UnitTestCase;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Token;

class IdTokenVerifierTest extends UnitTestCase
Expand Down Expand Up @@ -54,4 +55,18 @@ public function testItReturnsTheTokenOnSuccess()

$this->assertSame($token, $this->verifier->verify($token));
}

public function testItCanHandleATokenAsString()
{
$token = (new Builder())->getToken();
$tokenString = (string) $token;

$this->base
->expects($this->once())
->method('verifyIdToken')
->with($tokenString)
->willReturn($token);

$this->assertSame($token, $this->verifier->verify($tokenString));
}
}

0 comments on commit b3bd435

Please sign in to comment.