expectException(TwoFactorAuthException::class); $tfa->createSecret(); } public function testCreateSecretOverrideSecureDoesNotThrowOnInsecureRNG(): void { $rng = new TestRNGProvider(); $tfa = new TwoFactorAuth('Test', 6, 30, Algorithm::Sha1, null, $rng); $this->assertEquals('ABCDEFGHIJKLMNOP', $tfa->createSecret(80, false)); } public function testCreateSecretDoesNotThrowOnSecureRNGProvider(): void { $rng = new TestRNGProvider(true); $tfa = new TwoFactorAuth('Test', 6, 30, Algorithm::Sha1, null, $rng); $this->assertEquals('ABCDEFGHIJKLMNOP', $tfa->createSecret()); } public function testCreateSecretGeneratesDesiredAmountOfEntropy(): void { $rng = new TestRNGProvider(true); $tfa = new TwoFactorAuth('Test', 6, 30, Algorithm::Sha1, null, $rng); $this->assertEquals('A', $tfa->createSecret(5)); $this->assertEquals('AB', $tfa->createSecret(6)); $this->assertEquals('ABCDEFGHIJKLMNOPQRSTUVWXYZ', $tfa->createSecret(128)); $this->assertEquals('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', $tfa->createSecret(160)); $this->assertEquals('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJKLMNOPQRSTUVWXYZ234567', $tfa->createSecret(320)); $this->assertEquals('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567ABCDEFGHIJKLMNOPQRSTUVWXYZ234567A', $tfa->createSecret(321)); } }