Skip to content

test(auth): overhaul auth tests and certificate parser with full cove…#290

Open
zennintoji29-create wants to merge 1 commit intoEswaramuthu:mainfrom
zennintoji29-create:feature/improve-auth-tests
Open

test(auth): overhaul auth tests and certificate parser with full cove…#290
zennintoji29-create wants to merge 1 commit intoEswaramuthu:mainfrom
zennintoji29-create:feature/improve-auth-tests

Conversation

@zennintoji29-create
Copy link
Copy Markdown

…rage

  • Restructure test_auth.py and test_protected_routes.py into classes
  • Add cross-role, logout, edge-case and session integrity tests
  • Refactor certificate_parser.py to return typed ParsedCertificate
  • Add logging, datetime parsing, and whitespace normalisation to parser
  • Apply type hints and docstrings throughout per CONTRIBUTING guidelines

Which issue does this PR close?

  • Closes #.

Rationale for this change

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

…rage

- Restructure test_auth.py and test_protected_routes.py into classes
- Add cross-role, logout, edge-case and session integrity tests
- Refactor certificate_parser.py to return typed ParsedCertificate
- Add logging, datetime parsing, and whitespace normalisation to parser
- Apply type hints and docstrings throughout per CONTRIBUTING guidelines
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 10, 2026

@zennintoji29-create is attempting to deploy a commit to the 007's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown

Thanks for creating a PR for your Issue! ☺️

We'll review it as soon as possible.
In the meantime, please double-check the file changes and ensure that all commits are accurate.

If there are any unresolved review comments, feel free to resolve them. 🙌🏼


# ── Session seed helpers ──────────────────────────────────────────────────────

def _seed_student_session(client, student_id: str = "S12345") -> None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Code: ⚠️ Duplicate Code Detected (Similarity: 92%)

This function _seed_student_session duplicates existing code.

📍 Original Location:

tests/conftest.py:91-98

Function: auth_student_client

💡 Recommendation:
Replace _seed_student_session with a call to the auth_student_client fixture (inject it as a test parameter). Alternatively, keep the helper but have it delegate to the conftest fixture to avoid the duplicated session-key dictionary.

Consider importing and reusing the existing function instead of duplicating the logic.


def test_authenticated_teacher_access(client):
"""Test that authenticated teacher can access their dashboard."""
def _seed_teacher_session(client, teacher_id: str = "T001") -> None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Code: ⚠️ Duplicate Code Detected (Similarity: 92%)

This function _seed_teacher_session duplicates existing code.

📍 Original Location:

tests/conftest.py:100-108

Function: auth_teacher_client

💡 Recommendation:
Use the auth_teacher_client fixture from conftest instead of the duplicate helper function.

Consider importing and reusing the existing function instead of duplicating the logic.

Comment on lines +48 to +53
# ── Unauthenticated redirect tests ────────────────────────────────────────────

class TestUnauthenticatedRedirects:
"""All protected routes must redirect an anonymous visitor to login."""

def test_student_dashboard_redirects_to_login(self, client) -> None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Code: ⚠️ Duplicate Code Detected (Similarity: 95%)

This function TestUnauthenticatedRedirects.test_student_dashboard_redirects_to_login duplicates existing code.

📍 Original Location:

tests/test_protected_routes.py:2-6

Function: test_student_dashboard_protected

💡 Recommendation:
Remove the existing test_student_dashboard_protected and keep the PR version inside the TestUnauthenticatedRedirects class for better organisation. No logic changes needed.

Consider importing and reusing the existing function instead of duplicating the logic.

Comment on lines +55 to +60
response = client.get("/student-dashboard", follow_redirects=False)

assert response.status_code == 302
assert "/student" in response.location

def test_teacher_dashboard_redirects_to_login(self, client) -> None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate Code: ⚠️ Duplicate Code Detected (Similarity: 95%)

This function TestUnauthenticatedRedirects.test_teacher_dashboard_redirects_to_login duplicates existing code.

📍 Original Location:

tests/test_protected_routes.py:8-12

Function: test_teacher_dashboard_protected

💡 Recommendation:
Remove test_teacher_dashboard_protected from the repo and keep the PR version. No logic changes needed.

Consider importing and reusing the existing function instead of duplicating the logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant