Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(auth): Add Redis caching for pending user registration and implement token verification logic #1181

Open
wants to merge 39 commits into
base: dev
Choose a base branch
from

Conversation

mantle-bearer
Copy link

Add Unit and Integration Tests for Authentication Routes

Description

This PR adds unit tests for the /register and /register-super-admin routes and integration tests for the /verify-token route. It also includes a mocked Redis client to simulate pending user cache during the verification process.

Related Issue (Link to issue ticket) #1010

Motivation and Context

  • Ensure the /register and /register-super-admin routes handle user and admin registration correctly.
  • Verify the /verify-token route processes cached user data from Redis and creates user records in the database.
  • Strengthen test coverage for core authentication flows, reducing the risk of regression.

How Has This Been Tested?

  • Added unit tests for:
    • Normal user registration (/register)
    • Admin registration (/register-super-admin)
  • Did manual integration tests for:
    • Token verification (/verify-token)
    • Redis token matching
    • User creation upon successful token verification

Screenshots (if appropriate):

  • ✅ Successful user registration response

image

Successful user email sent to user

  • ✅ Successful admin registration response

image

  • ✅ Verification token match (valid token)
    image

  • ❌ Verification token mismatch (invalid token)

image

  • ❌ Expired or missing Redis token error

image

  • Redis CLI output displaying cached user data for both verified and after unverified user
    image

  • All three tests passed
    image

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

mantle-bearer and others added 20 commits March 1, 2025 02:02
@samuelogboye
Copy link
Contributor

samuelogboye commented Mar 1, 2025

This might break prod if redis is not set up in other environments

Copy link
Author

@mantle-bearer mantle-bearer left a comment

Choose a reason for hiding this comment

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

I have resolved all the conversation as requested.

Here are the commit messages for you to quickly confirm and approve my PR

  1. No longer exposing sensitive credentials in .env.sample 201fc52e74c94951084160b74a95e516b3b0a824

  2. I have removed the unused create_registration_access_toke() method in this commit 446c2b85c902bf5438c69cb5d5f7a37c5f1f32b1

  3. I replaced the direct Redis client initialization with a lazy-initialization approach
    a827a66ac155ec7460f4f925442009ec5b5bea1f

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.

2 participants