Skip to content

Commit

Permalink
add tests for pkce
Browse files Browse the repository at this point in the history
Closes #27.
  • Loading branch information
lilioid committed Dec 26, 2024
1 parent d20a789 commit 31e393a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_pkce.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from simple_openid_connect import pkce


def test_get_code_challenge():
PKCE_PAIRS = [
# (verifier, challenge) pairs
(
"X1mcNAU_lfu25acaJoCQSyo4YyZc1NwaxWw7tNL7mffK0AXCS-lNBtisryb2",
"V_nSilRCu0pt3eR-cH7LWru-rYwlTr3J2143tiwloCA",
),
(
"9ok-JCOrX1OkmCFy8wGq2UBTGgFkeEg5IGffzgKNfDrpO-AOJ-83J9IhXOqj",
"ET7UYFBGIHCdYh9bLyeLqWiKEr3t3JCxMRNacq3NCGk",
),
(
"zDv_Uz7QRoYRgIdieHac1UIlDNPPQb8qVIwgLzFu66kHo2g92UfkoU8Vi91z",
"iWLceDSH1e3G7NJ5eieiqpk9IgXPTgSUd8ivdbRZKII",
),
]
for verifier, challenge in PKCE_PAIRS:
assert (
pkce.get_code_challenge(verifier) == challenge
), "get_code_challenge() produced an unexpected challenge"


def test_gen_pair_is_actual_pair():
for _ in range(100):
verifier, challenge = pkce.generate_pkce_pair()
assert challenge == pkce.get_code_challenge(
verifier
), "pkce.generate_pkce_pair() returned a pair whose challenge cannot be reproduced from the verifier"

0 comments on commit 31e393a

Please sign in to comment.