From 1ddc27e792ef2dfdff06685700afee451d276d28 Mon Sep 17 00:00:00 2001 From: sephster Date: Fri, 21 Sep 2018 20:12:05 +0100 Subject: [PATCH] Add code challenge verifier tests --- .../CodeChallengeVerifiers/PlainVerifier.php | 24 ++++++++++++ tests/CodeChallengeVerifiers/S256Verifier.php | 37 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tests/CodeChallengeVerifiers/PlainVerifier.php create mode 100644 tests/CodeChallengeVerifiers/S256Verifier.php diff --git a/tests/CodeChallengeVerifiers/PlainVerifier.php b/tests/CodeChallengeVerifiers/PlainVerifier.php new file mode 100644 index 00000000..4939c88c --- /dev/null +++ b/tests/CodeChallengeVerifiers/PlainVerifier.php @@ -0,0 +1,24 @@ +assertEquals('plain', $verifier->getMethod()); + } + + public function testVerifyCodeChallenge() + { + $verifier = new PlainVerifier(); + + $this->assertTrue($verifier->verifyCodeChallenge('foo', 'foo'); + $this->assertFalse($verifier->verifyCodeChallenge('foo', 'bar'); + } +} diff --git a/tests/CodeChallengeVerifiers/S256Verifier.php b/tests/CodeChallengeVerifiers/S256Verifier.php new file mode 100644 index 00000000..2bf14353 --- /dev/null +++ b/tests/CodeChallengeVerifiers/S256Verifier.php @@ -0,0 +1,37 @@ +assertEquals('S256', $verifier->getMethod()); + } + + public function testVerifyCodeChallengeSucceeds() + { + $codeChallenge = $this->createCodeChallenge('foo'); + $verifier = new S256Verifier(); + + $this->assertTrue($verifier->verifyCodeChallenge('foo', $codeChallenge)); + } + + public function testVerifyCodeChallengeFails() + { + $codeChallenge = $this->createCodeChallenge('bar'); + $verifier = new S256Verifier(); + + $this->assertFalse($verifier->verifyCodeChallenge('foo', $codeChallenge)); + } + + private function createCodeChallenge($codeVerifier) + { + return strtr(rtrim(base64_encode(hash('sha256', $codeVerifier, true)), '='), '+/', '-_'); + } +}