-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
base: main
Are you sure you want to change the base?
Conversation
hasnain095
commented
Apr 4, 2023
- Added test for user token
- scoped the create_non_superuser test to session
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() |
There was a problem hiding this comment.
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"
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
💚 Upgrade black to fix pipeline (Kludex#78)
…api-microservices into feat/add-user-token-test
|
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
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- 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
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 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!
Considering adding FactoryBoy to avoid GitGuardian Security Check errors. |
users/tests/conftest.py
Outdated
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: |
There was a problem hiding this comment.
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.
@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 👀 |
Should be fixed now |
@Kludex can we close this now? |