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/add user token test #80

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

hasnain095
Copy link
Contributor

  • Added test for user token
  • scoped the create_non_superuser test to session

@hasnain095
Copy link
Contributor Author

Closed previous pull request, this resolves issue #49

@@ -53,3 +56,27 @@ async def superuser_token_headers(client: AsyncClient) -> Dict[str, str]:
res = await client.post("/api/v1/login/", data=login_data)
access_token = res.json()["access_token"]
return {"Authorization": f"Bearer {access_token}"}


@pytest.fixture()
Copy link
Owner

Choose a reason for hiding this comment

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

Can it be a scope="session"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Facing an issue when changing this fixture's scope to "session", the user_token_header fixture is function scoped and causes a ScopeMismatch error. If we set the scope of user_token_header as "session" too, then it causes an issue with accessing the "function" scoped fixture "client" with "session" scoped fixture "create_non_superuser".

My opinion is to create a class, and scope all related fixtures to "class". This way we can add any test related to the users into that class.

Copy link
Owner

Choose a reason for hiding this comment

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

The client fixture can be session as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That leads to making the "session" and "connection" fixtures be scoped to the session. I've made these changes already, and all tests passed.

@gitguardian
Copy link

gitguardian bot commented Apr 4, 2023

⚠️ GitGuardian has uncovered 4 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id Secret Commit Filename
- Generic Password b68e839 users/tests/conftest.py View secret
- Generic Password 76e806e users/tests/conftest.py View secret
- Generic Password 43d5267 users/tests/conftest.py View secret
- Generic Password eabf791 users/tests/conftest.py View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Our GitHub checks need improvements? Share your feedbacks!

users/tests/conftest.py Outdated Show resolved Hide resolved
users/tests/conftest.py Outdated Show resolved Hide resolved
@hasnain095
Copy link
Contributor Author

Considering adding FactoryBoy to avoid GitGuardian Security Check errors.

hashed_password = get_password_hash(password)
result = await session.execute(select(User).where(User.email == email))
user: Optional[User] = result.scalars().first()
if user is None:
Copy link
Owner

Choose a reason for hiding this comment

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

This is never going to happen cause there will be a rollback on each test.

Sorry, I didn't notice before.

@hasnain095
Copy link
Contributor Author

@Kludex can we close this PR or you want some other changes?

@Kludex
Copy link
Owner

Kludex commented Apr 6, 2023

@Kludex can we close this PR or you want some other changes?

This cannot happen: #80 (comment)

Because we rollback, so we need to remove that conditional 👀

@hasnain095
Copy link
Contributor Author

Should be fixed now

@hasnain095
Copy link
Contributor Author

@Kludex can we close this now?

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.

None yet

2 participants