← Back
Editing: AuthPayloadTest.php
<?php namespace GoDaddy\Auth\Tests; use GoDaddy\Auth\AuthPayload; use PHPUnit\Framework\TestCase; class AuthPayloadTest extends TestCase { public function testLevel0() { $auth = new AuthPayload(); $this->assertFalse($auth->isExpired(0)); } public function testLevelGt3() { $auth = new AuthPayload(); $this->assertTrue($auth->isExpired(4)); $this->assertTrue($auth->isExpired(5)); } public function testLevel1() { // New policy: Level 1 = 30 days persistent / 12 hours non-persistent // Persistent token with fresh VAT (9 minutes old) should not expire $auth = new AuthPayload(); $auth->vat = $auth->iat = time() - 9 * 60; $auth->per = true; $this->assertFalse($auth->isExpired(1)); // Persistent token 30 days old minus 1 minute should not expire $auth = new AuthPayload(); $auth->iat = time() - 60 * 60 * 24 * 30 + 60; $auth->per = true; $this->assertFalse($auth->isExpired(1)); // Persistent token 30 days old plus 1 minute should expire $auth = new AuthPayload(); $auth->iat = time() - 60 * 60 * 24 * 30 - 60; $auth->per = true; $this->assertTrue($auth->isExpired(1)); // Non-persistent token 12 hours old minus 1 minute should not expire $auth = new AuthPayload(); $auth->iat = time() - 60 * 60 * 12 + 60; $auth->per = false; $this->assertFalse($auth->isExpired(1)); // Non-persistent token 12 hours old plus 1 minute should expire $auth = new AuthPayload(); $auth->iat = time() - 60 * 60 * 12 - 60; $auth->per = false; $this->assertTrue($auth->isExpired(1)); } public function testLevel2() { // New policy: Level 2 = 30 days persistent / 12 hours non-persistent // Persistent token 30 days old minus 1 minute should not expire $auth = new AuthPayload(); $auth->per = true; $auth->iat = time() - 60 * 60 * 24 * 30 + 60; $this->assertFalse($auth->isExpired(2)); // Persistent token 30 days old plus 1 minute should expire $auth = new AuthPayload(); $auth->per = true; $auth->iat = time() - 60 * 60 * 24 * 30 - 60; $this->assertTrue($auth->isExpired(2)); // Non-persistent token 12 hours old minus 1 minute should not expire $auth = new AuthPayload(); $auth->iat = time() - 60 * 60 * 12 + 60; $auth->per = false; $this->assertFalse($auth->isExpired(2)); // Non-persistent token 12 hours old plus 1 minute should expire $auth = new AuthPayload(); $auth->iat = time() - 60 * 60 * 12 - 60; $auth->per = false; $this->assertTrue($auth->isExpired(2)); } public function testLevel3() { $auth = new AuthPayload(); $this->assertTrue($auth->isExpired(3)); $auth->iat = time() - 30 * 60; $this->assertTrue($auth->isExpired(3)); $auth->hbi = time() - 90 * 60; $this->assertTrue($auth->isExpired(3)); $auth->hbi = time() - 30 * 60; $this->assertFalse($auth->isExpired(3)); } }
Save File
Cancel