-
-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing functional tests (closes #21).
- Loading branch information
Showing
4 changed files
with
118 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
use Lcobucci\JWT\Signature; | ||
use Lcobucci\JWT\Signer\Ecdsa\Sha256; | ||
use Lcobucci\JWT\EcdsaKeys; | ||
use Lcobucci\JWT\Signer\Ecdsa\Sha512; | ||
|
||
/** | ||
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> | ||
|
@@ -22,6 +23,19 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase | |
{ | ||
use EcdsaKeys; | ||
|
||
/** | ||
* @var Sha256 | ||
*/ | ||
private $signer; | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function createSigner() | ||
{ | ||
$this->signer = new Sha256(); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
|
@@ -44,7 +58,7 @@ public function builderCanGenerateAToken() | |
->setAudience('http://client.abc.com') | ||
->setIssuer('http://api.abc.com') | ||
->set('user', $user) | ||
->sign(new Sha256(), $this->privateEcdsa()) | ||
->sign($this->signer, $this->privateEcdsa()) | ||
->getToken(); | ||
|
||
$this->assertAttributeInstanceOf(Signature::class, 'signature', $token); | ||
|
@@ -68,7 +82,6 @@ public function builderCanGenerateAToken() | |
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Parsing\Decoder | ||
* @covers Lcobucci\JWT\Signer\Factory | ||
*/ | ||
public function parserCanReadAToken(Token $generated) | ||
{ | ||
|
@@ -89,14 +102,35 @@ public function parserCanReadAToken(Token $generated) | |
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Claim\Factory | ||
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Signer\Factory | ||
* @covers Lcobucci\JWT\Signer\OpenSSL | ||
* @covers Lcobucci\JWT\Signer\Ecdsa | ||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256 | ||
*/ | ||
public function verifyShouldReturnFalseWhenKeyIsNotRight(Token $token) | ||
{ | ||
$this->assertFalse($token->verify($this->otherPublicEcdsa())); | ||
$this->assertFalse($token->verify($this->signer, $this->otherPublicEcdsa())); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @depends builderCanGenerateAToken | ||
* | ||
* @covers Lcobucci\JWT\Builder | ||
* @covers Lcobucci\JWT\Parser | ||
* @covers Lcobucci\JWT\Token | ||
* @covers Lcobucci\JWT\Signature | ||
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Claim\Factory | ||
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Signer\OpenSSL | ||
* @covers Lcobucci\JWT\Signer\Ecdsa | ||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256 | ||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha512 | ||
*/ | ||
public function verifyShouldReturnFalseWhenAlgorithmIsDifferent(Token $token) | ||
{ | ||
$this->assertFalse($token->verify(new Sha512(), $this->publicEcdsa())); | ||
} | ||
|
||
/** | ||
|
@@ -111,13 +145,12 @@ public function verifyShouldReturnFalseWhenKeyIsNotRight(Token $token) | |
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Claim\Factory | ||
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Signer\Factory | ||
* @covers Lcobucci\JWT\Signer\OpenSSL | ||
* @covers Lcobucci\JWT\Signer\Ecdsa | ||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256 | ||
*/ | ||
public function verifyShouldReturnTrueWhenKeyIsRight(Token $token) | ||
{ | ||
$this->assertTrue($token->verify($this->publicEcdsa())); | ||
$this->assertTrue($token->verify($this->signer, $this->publicEcdsa())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,27 @@ | |
use Lcobucci\JWT\Token; | ||
use Lcobucci\JWT\Signature; | ||
use Lcobucci\JWT\Signer\Hmac\Sha256; | ||
use Lcobucci\JWT\Signer\Hmac\Sha512; | ||
|
||
/** | ||
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> | ||
* @since 2.1.0 | ||
*/ | ||
class HmacTokenTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Sha256 | ||
*/ | ||
private $signer; | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function createSigner() | ||
{ | ||
$this->signer = new Sha256(); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
|
@@ -40,7 +54,7 @@ public function builderCanGenerateAToken() | |
->setAudience('http://client.abc.com') | ||
->setIssuer('http://api.abc.com') | ||
->set('user', $user) | ||
->sign(new Sha256(), 'testing') | ||
->sign($this->signer, 'testing') | ||
->getToken(); | ||
|
||
$this->assertAttributeInstanceOf(Signature::class, 'signature', $token); | ||
|
@@ -64,7 +78,6 @@ public function builderCanGenerateAToken() | |
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Parsing\Decoder | ||
* @covers Lcobucci\JWT\Signer\Factory | ||
*/ | ||
public function parserCanReadAToken(Token $generated) | ||
{ | ||
|
@@ -85,13 +98,34 @@ public function parserCanReadAToken(Token $generated) | |
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Claim\Factory | ||
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Signer\Factory | ||
* @covers Lcobucci\JWT\Signer\Hmac | ||
* @covers Lcobucci\JWT\Signer\Hmac\Sha256 | ||
*/ | ||
public function verifyShouldReturnFalseWhenKeyIsNotRight(Token $token) | ||
{ | ||
$this->assertFalse($token->verify('testing1')); | ||
$this->assertFalse($token->verify($this->signer, 'testing1')); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @depends builderCanGenerateAToken | ||
* | ||
* @covers Lcobucci\JWT\Builder | ||
* @covers Lcobucci\JWT\Parser | ||
* @covers Lcobucci\JWT\Token | ||
* @covers Lcobucci\JWT\Signature | ||
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Claim\Factory | ||
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Signer\OpenSSL | ||
* @covers Lcobucci\JWT\Signer\Hmac | ||
* @covers Lcobucci\JWT\Signer\Hmac\Sha256 | ||
* @covers Lcobucci\JWT\Signer\Hmac\Sha512 | ||
*/ | ||
public function verifyShouldReturnFalseWhenAlgorithmIsDifferent(Token $token) | ||
{ | ||
$this->assertFalse($token->verify(new Sha512(), 'testing')); | ||
} | ||
|
||
/** | ||
|
@@ -106,12 +140,11 @@ public function verifyShouldReturnFalseWhenKeyIsNotRight(Token $token) | |
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Claim\Factory | ||
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Signer\Factory | ||
* @covers Lcobucci\JWT\Signer\Hmac | ||
* @covers Lcobucci\JWT\Signer\Hmac\Sha256 | ||
*/ | ||
public function verifyShouldReturnTrueWhenKeyIsRight(Token $token) | ||
{ | ||
$this->assertTrue($token->verify('testing')); | ||
$this->assertTrue($token->verify($this->signer, 'testing')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
use Lcobucci\JWT\Signature; | ||
use Lcobucci\JWT\Signer\Rsa\Sha256; | ||
use Lcobucci\JWT\RsaKeys; | ||
use Lcobucci\JWT\Signer\Rsa\Sha512; | ||
|
||
/** | ||
* @author Luís Otávio Cobucci Oblonczyk <[email protected]> | ||
|
@@ -22,6 +23,19 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase | |
{ | ||
use RsaKeys; | ||
|
||
/** | ||
* @var Sha256 | ||
*/ | ||
private $signer; | ||
|
||
/** | ||
* @before | ||
*/ | ||
public function createSigner() | ||
{ | ||
$this->signer = new Sha256(); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
|
@@ -44,7 +58,7 @@ public function builderCanGenerateAToken() | |
->setAudience('http://client.abc.com') | ||
->setIssuer('http://api.abc.com') | ||
->set('user', $user) | ||
->sign(new Sha256(), $this->privateRsa()) | ||
->sign($this->signer, $this->privateRsa()) | ||
->getToken(); | ||
|
||
$this->assertAttributeInstanceOf(Signature::class, 'signature', $token); | ||
|
@@ -68,7 +82,6 @@ public function builderCanGenerateAToken() | |
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Parsing\Decoder | ||
* @covers Lcobucci\JWT\Signer\Factory | ||
*/ | ||
public function parserCanReadAToken(Token $generated) | ||
{ | ||
|
@@ -89,14 +102,35 @@ public function parserCanReadAToken(Token $generated) | |
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Claim\Factory | ||
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Signer\Factory | ||
* @covers Lcobucci\JWT\Signer\OpenSSL | ||
* @covers Lcobucci\JWT\Signer\Rsa | ||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256 | ||
*/ | ||
public function verifyShouldReturnFalseWhenKeyIsNotRight(Token $token) | ||
{ | ||
$this->assertFalse($token->verify($this->encryptedPublicRsa())); | ||
$this->assertFalse($token->verify($this->signer, $this->encryptedPublicRsa())); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @depends builderCanGenerateAToken | ||
* | ||
* @covers Lcobucci\JWT\Builder | ||
* @covers Lcobucci\JWT\Parser | ||
* @covers Lcobucci\JWT\Token | ||
* @covers Lcobucci\JWT\Signature | ||
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Claim\Factory | ||
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Signer\OpenSSL | ||
* @covers Lcobucci\JWT\Signer\Rsa | ||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256 | ||
* @covers Lcobucci\JWT\Signer\Rsa\Sha512 | ||
*/ | ||
public function verifyShouldReturnFalseWhenAlgorithmIsDifferent(Token $token) | ||
{ | ||
$this->assertFalse($token->verify(new Sha512(), $this->publicRsa())); | ||
} | ||
|
||
/** | ||
|
@@ -111,13 +145,12 @@ public function verifyShouldReturnFalseWhenKeyIsNotRight(Token $token) | |
* @covers Lcobucci\JWT\Parsing\Encoder | ||
* @covers Lcobucci\JWT\Claim\Factory | ||
* @covers Lcobucci\JWT\Claim\Basic | ||
* @covers Lcobucci\JWT\Signer\Factory | ||
* @covers Lcobucci\JWT\Signer\OpenSSL | ||
* @covers Lcobucci\JWT\Signer\Rsa | ||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256 | ||
*/ | ||
public function verifyShouldReturnTrueWhenKeyIsRight(Token $token) | ||
{ | ||
$this->assertTrue($token->verify($this->publicRsa())); | ||
$this->assertTrue($token->verify($this->signer, $this->publicRsa())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters