| @@ 48-63 (lines=16) @@ | ||
| 45 | * @expectedException \Emarref\Jwt\Exception\ExpiredException | |
| 46 | * @expectedExceptionMessage Token expired at "Sat, 08 Nov 2014 00:00:00 +0000" | |
| 47 | */ | |
| 48 | public function testExpired() | |
| 49 |     { | |
| 50 |         $dateTime = new \DateTime('Sat, 08 Nov 2014 00:00:00 +0000'); | |
| 51 | ||
| 52 |         $expirationClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Expiration')->getMock(); | |
| 53 | ||
| 54 | $expirationClaim->expects($this->exactly(3)) | |
| 55 |             ->method('getValue') | |
| 56 | ->will($this->returnValue($dateTime->getTimestamp())); | |
| 57 | ||
| 58 | $this->payload->expects($this->once()) | |
| 59 |             ->method('findClaimByName') | |
| 60 | ->will($this->returnValue($expirationClaim)); | |
| 61 | ||
| 62 | $this->verifier->verify($this->token); | |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * @expectedException \InvalidArgumentException | |
| @@ 69-82 (lines=14) @@ | ||
| 66 | * @expectedException \InvalidArgumentException | |
| 67 | * @expectedExceptionMessage Invalid expiration timestamp "foobar" | |
| 68 | */ | |
| 69 | public function testUnexpectedValue() | |
| 70 |     { | |
| 71 |         $expirationClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Expiration')->getMock(); | |
| 72 | ||
| 73 | $expirationClaim->expects($this->exactly(3)) | |
| 74 |                         ->method('getValue') | |
| 75 |                         ->will($this->returnValue('foobar')); | |
| 76 | ||
| 77 | $this->payload->expects($this->once()) | |
| 78 |                       ->method('findClaimByName') | |
| 79 | ->will($this->returnValue($expirationClaim)); | |
| 80 | ||
| 81 | $this->verifier->verify($this->token); | |
| 82 | } | |
| 83 | ||
| 84 | public function testValid() | |
| 85 |     { | |
| @@ 84-99 (lines=16) @@ | ||
| 81 | $this->verifier->verify($this->token); | |
| 82 | } | |
| 83 | ||
| 84 | public function testValid() | |
| 85 |     { | |
| 86 |         $future = new \DateTime('5 minutes', new \DateTimeZone('UTC')); | |
| 87 | ||
| 88 |         $expirationClaim = $this->getMockBuilder('Emarref\Jwt\Claim\Expiration')->getMock(); | |
| 89 | ||
| 90 | $expirationClaim->expects($this->once()) | |
| 91 |             ->method('getValue') | |
| 92 | ->will($this->returnValue($future->getTimestamp())); | |
| 93 | ||
| 94 | $this->payload->expects($this->once()) | |
| 95 |             ->method('findClaimByName') | |
| 96 | ->will($this->returnValue($expirationClaim)); | |
| 97 | ||
| 98 | $this->verifier->verify($this->token); | |
| 99 | } | |
| 100 | } | |
| 101 | ||
| @@ 51-67 (lines=17) @@ | ||
| 48 | * @expectedException \Emarref\Jwt\Exception\TooEarlyException | |
| 49 | * @expectedExceptionMessageRegExp /Token must not be processed before "[\w,:+\d ]+"/ | |
| 50 | */ | |
| 51 | public function testNotBefore() | |
| 52 |     { | |
| 53 |         $dateTime = new \DateTime('1 day'); | |
| 54 | ||
| 55 |         $notBeforeClaim = $this->getMockBuilder('Emarref\Jwt\Claim\NotBefore')->getMock(); | |
| 56 | ||
| 57 | $notBeforeClaim->expects($this->exactly(3)) | |
| 58 |             ->method('getValue') | |
| 59 | ->will($this->returnValue($dateTime->getTimestamp())); | |
| 60 | ||
| 61 | $this->payload->expects($this->once()) | |
| 62 |             ->method('findClaimByName') | |
| 63 | ->with(NotBefore::NAME) | |
| 64 | ->will($this->returnValue($notBeforeClaim)); | |
| 65 | ||
| 66 | $this->verifier->verify($this->token); | |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * @expectedException \InvalidArgumentException | |
| @@ 73-87 (lines=15) @@ | ||
| 70 | * @expectedException \InvalidArgumentException | |
| 71 | * @expectedExceptionMessage Invalid not before timestamp "foobar" | |
| 72 | */ | |
| 73 | public function testUnexpectedValue() | |
| 74 |     { | |
| 75 |         $notBeforeClaim = $this->getMockBuilder('Emarref\Jwt\Claim\NotBefore')->getMock(); | |
| 76 | ||
| 77 | $notBeforeClaim->expects($this->exactly(2)) | |
| 78 |                         ->method('getValue') | |
| 79 |                         ->will($this->returnValue('foobar')); | |
| 80 | ||
| 81 | $this->payload->expects($this->once()) | |
| 82 |                       ->method('findClaimByName') | |
| 83 | ->with(NotBefore::NAME) | |
| 84 | ->will($this->returnValue($notBeforeClaim)); | |
| 85 | ||
| 86 | $this->verifier->verify($this->token); | |
| 87 | } | |
| 88 | ||
| 89 | public function testValid() | |
| 90 |     { | |
| @@ 89-105 (lines=17) @@ | ||
| 86 | $this->verifier->verify($this->token); | |
| 87 | } | |
| 88 | ||
| 89 | public function testValid() | |
| 90 |     { | |
| 91 |         $past = new \DateTime('5 minutes ago', new \DateTimeZone('UTC')); | |
| 92 | ||
| 93 |         $notBeforeClaim = $this->getMockBuilder('Emarref\Jwt\Claim\NotBefore')->getMock(); | |
| 94 | ||
| 95 | $notBeforeClaim->expects($this->exactly(2)) | |
| 96 |             ->method('getValue') | |
| 97 | ->will($this->returnValue($past->getTimestamp())); | |
| 98 | ||
| 99 | $this->payload->expects($this->once()) | |
| 100 |             ->method('findClaimByName') | |
| 101 | ->with(NotBefore::NAME) | |
| 102 | ->will($this->returnValue($notBeforeClaim)); | |
| 103 | ||
| 104 | $this->verifier->verify($this->token); | |
| 105 | } | |
| 106 | } | |
| 107 | ||