Skip to content

Commit aabb27b

Browse files
committed
Simplified testcase for outh pkce
1 parent 6e0711e commit aabb27b

File tree

2 files changed

+9
-52
lines changed

2 files changed

+9
-52
lines changed

web/tests/functional/authentication/test_authentication.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,8 @@ def try_login(self, provider, username, password):
234234

235235
# PKCE attack case
236236
if username == "user_pkce":
237-
env.change_oauth_session_data(
238-
session_alchemy=session_factory,
239-
code_verifier="dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk",
240-
state=state
241-
)
237+
code="wrong_code"
238+
auth_string = f"{link}?code={code}&state={state}"
242239

243240
self.session_token = auth_client.performLogin(
244241
"oauth", provider + "@" + auth_string)
@@ -272,11 +269,15 @@ def test_oauth_token_session(self):
272269
"""
273270
session_factory = env.create_sqlalchemy_session(self._test_workspace)
274271

275-
self.try_login("github", "admin_github", "admin")
272+
session = self.try_login("github", "admin_github", "admin")
273+
self.assertTrue(session, "Authentication failed")
274+
276275
result = env.validate_oauth_token_session(session_factory, "github1",)
277276
self.assertTrue(result, "Access_token wasn't inserted in Database")
278277

279-
self.try_login("google", "user_google", "user")
278+
session = self.try_login("google", "user_google", "user")
279+
self.assertTrue(session, "Authentication failed")
280+
280281
result = env.validate_oauth_token_session(session_factory, "google3",)
281282
self.assertTrue(result, "Access_token wasn't inserted in Database")
282283

web/tests/libtest/env.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -584,48 +584,4 @@ def insert_oauth_session(session_alchemy,
584584
print(f"State {state} inserted successfully.")
585585
except Exception as exc:
586586
print(f"Failed to insert state {state}: {exc}")
587-
raise exc
588-
589-
590-
def change_oauth_session_data(session_alchemy,
591-
provider: str = None,
592-
code_verifier: str = None,
593-
state: str = None,
594-
expires_at: datetime = None):
595-
"""
596-
Change the session data of an existing OAuth session in the database
597-
for session integrity tests.
598-
"""
599-
try:
600-
with DBSession(session_alchemy) as session:
601-
602-
oauth_session = session.query(OAuthSession).filter(
603-
OAuthSession.state == state).first()
604-
605-
if oauth_session:
606-
if provider is not None:
607-
if not isinstance(provider, str):
608-
raise TypeError(
609-
"The OAuth provider field must be string")
610-
oauth_session.provider = provider
611-
if code_verifier is not None:
612-
if not isinstance(code_verifier, str):
613-
raise TypeError(
614-
"The OAuth code_verifier field must be string")
615-
oauth_session.code_verifier = code_verifier
616-
if state is not None:
617-
if not isinstance(state, str):
618-
raise TypeError(
619-
"The OAuth state field must be string")
620-
oauth_session.state = state
621-
if expires_at is not None:
622-
print(f"TYPE OF DATE: {type(expires_at)}")
623-
if not isinstance(expires_at, datetime.datetime):
624-
raise TypeError(
625-
"The OAuth expires_at field must be datetime")
626-
oauth_session.expires_at = expires_at
627-
628-
session.commit()
629-
except Exception as exc:
630-
print(f"Failed to update state {state}: {exc}")
631-
raise exc
587+
raise exc

0 commit comments

Comments
 (0)