Skip to content

Commit

Permalink
Added some more tests and assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Brecht-Precht committed Feb 6, 2017
1 parent ae7ac51 commit 8069b78
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class SharedSecretQrCodeProviderTest extends \PHPUnit_Framework_TestCase
{

const SHARED_SECRET ='9nxnvWgVw5Ca2YLUIkou2CkV2K15QI';
const SHARED_SECRET = '9nxnvWgVw5Ca2YLUIkou2CkV2K15QI';
const EXPECTED_HOTP_BASE32_SHARED_SECRET_URL = 'otpauth://hotp/Awesome%20Application?secret=GM4TMZJXHA3GKNZWGU3TMNZVGY3TOMZVGQZTMMJTGI2TSNDDGU2TIOJWMI3GMNZVGMZDIMZWMI2TMMZSGRRDGMJTGU2TCNBZ&issuer=Markenwerk';
const EXPECTED_TOTP_BASE32_SHARED_SECRET_URL = 'otpauth://totp/Awesome%20Application?secret=GM4TMZJXHA3GKNZWGU3TMNZVGY3TOMZVGQZTMMJTGI2TSNDDGU2TIOJWMI3GMNZVGMZDIMZWMI2TMMZSGRRDGMJTGU2TCNBZ&issuer=Markenwerk';
const EXPECTED_HOTP_SHARED_SECRET_URL = 'otpauth://hotp/Awesome%20Application?secret=396e786e765767567735436132594c55496b6f7532436b56324b31355149&issuer=Markenwerk';
Expand All @@ -35,6 +35,12 @@ public function testHotpBase32ProvideQrCode()
// Test QR code output file exists
$this->assertFileExists($qrCodeOutputPath);

// Test QR code measurements
$this->assertEquals(41, $sharedSecretQrCodeProvider->getQrCode()->getWidth());
$this->assertEquals(41, $sharedSecretQrCodeProvider->getQrCode()->getHeight());
$this->assertEquals(43, count($sharedSecretQrCodeProvider->getQrCode()->getRows()));
$this->assertEquals(43, count($sharedSecretQrCodeProvider->getQrCode()->getRow(0)->getPoints()));

// Test QR code output file mesaurement
$imageSize = getimagesize($qrCodeOutputPath);
$this->assertEquals($sharedSecretQrCodeProvider->getQrRenderer()->getWidth(), $imageSize[0]);
Expand All @@ -60,6 +66,12 @@ public function testTotpBase32ProvideQrCode()
// Test QR code output file exists
$this->assertFileExists($qrCodeOutputPath);

// Test QR code measurements
$this->assertEquals(41, $sharedSecretQrCodeProvider->getQrCode()->getWidth());
$this->assertEquals(41, $sharedSecretQrCodeProvider->getQrCode()->getHeight());
$this->assertEquals(43, count($sharedSecretQrCodeProvider->getQrCode()->getRows()));
$this->assertEquals(43, count($sharedSecretQrCodeProvider->getQrCode()->getRow(0)->getPoints()));

// Test QR code output file mesaurement
$imageSize = getimagesize($qrCodeOutputPath);
$this->assertEquals($sharedSecretQrCodeProvider->getQrRenderer()->getWidth(), $imageSize[0]);
Expand All @@ -85,6 +97,12 @@ public function testHotpProvideQrCode()
// Test QR code output file exists
$this->assertFileExists($qrCodeOutputPath);

// Test QR code measurements
$this->assertEquals(41, $sharedSecretQrCodeProvider->getQrCode()->getWidth());
$this->assertEquals(41, $sharedSecretQrCodeProvider->getQrCode()->getHeight());
$this->assertEquals(43, count($sharedSecretQrCodeProvider->getQrCode()->getRows()));
$this->assertEquals(43, count($sharedSecretQrCodeProvider->getQrCode()->getRow(0)->getPoints()));

// Test QR code output file mesaurement
$imageSize = getimagesize($qrCodeOutputPath);
$this->assertEquals($sharedSecretQrCodeProvider->getQrRenderer()->getWidth(), $imageSize[0]);
Expand All @@ -110,6 +128,12 @@ public function testTotpProvideQrCode()
// Test QR code output file exists
$this->assertFileExists($qrCodeOutputPath);

// Test QR code measurements
$this->assertEquals(41, $sharedSecretQrCodeProvider->getQrCode()->getWidth());
$this->assertEquals(41, $sharedSecretQrCodeProvider->getQrCode()->getHeight());
$this->assertEquals(43, count($sharedSecretQrCodeProvider->getQrCode()->getRows()));
$this->assertEquals(43, count($sharedSecretQrCodeProvider->getQrCode()->getRow(0)->getPoints()));

// Test QR code output file mesaurement
$imageSize = getimagesize($qrCodeOutputPath);
$this->assertEquals($sharedSecretQrCodeProvider->getQrRenderer()->getWidth(), $imageSize[0]);
Expand Down
3 changes: 3 additions & 0 deletions test/Validation/Oath/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public function testValidateTotp()
$isValid = $validator->validate(self::TOTP, self::SHARED_SECRET);
$this->assertEquals(false, $isValid);
$this->assertEquals($isValid, $validator->isValid());
$this->assertEquals(30, $validator->getValidPeriod());
$this->assertEquals(6, $validator->getPasswordLength());
}

public function testValidateHotp()
Expand All @@ -29,6 +31,7 @@ public function testValidateHotp()
$isValid = $validator->validate(self::HOTP, self::SHARED_SECRET, self::COUNTER);
$this->assertEquals(false, $isValid);
$this->assertEquals($isValid, $validator->isValid());
$this->assertEquals(6, $validator->getPasswordLength());
}

}
3 changes: 3 additions & 0 deletions test/Validation/YubicoOtp/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public function testValidateMalformed()
$this->assertEquals(false, $isValid);
$isValid = $validator->validate('12345678', self::PUBLIC_ID);
$this->assertEquals(false, $isValid);
// Malformed
$validator->validate('ccccccfcttfikkgitudletutjneikkrfcugnuhikdbhj', 'abc');
$this->assertEquals(false, $validator->isValid());
// Wellformed
$validator->validate('ccccccfcttfikkgitudletutjneikkrfcugnuhikdbhj', self::PUBLIC_ID);
$this->assertEquals(false, $validator->isValid());
Expand Down

0 comments on commit 8069b78

Please sign in to comment.