-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[INFRA-501] fix(security): enforce project membership on every workspace-level asset route #9657
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
Open
mguptahub
wants to merge
3
commits into
preview
Choose a base branch
from
infra-501/asset-project-access-structural
base: preview
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+900
−33
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
83d5bda
[INFRA-501] fix(security): enforce project membership on every worksp…
mguptahub 0effe3c
[INFRA-501] fix(security): stop the external-id dedup echo disclosing…
mguptahub 8d992ae
[INFRA-501] test: pin absence of the asset identifier fields on a den…
mguptahub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| # SPDX-License-Identifier: AGPL-3.0-only | ||
| # See the LICENSE file for details. | ||
|
|
||
| """Shared fixtures for the external-API contract tests. | ||
|
|
||
| Every test in this package authenticates with the ``api_token`` fixture, whose | ||
| token string is a constant. ``ApiKeyRateThrottle.get_cache_key`` keys on that | ||
| string, so all of these tests share one throttle bucket for the whole run -- | ||
| ``API_KEY_RATE_LIMIT`` defaults to 60/minute, and the suite finishes well inside | ||
| a minute. Once the package as a whole crosses 60 requests, whichever test issues | ||
| the next one fails with 429, which shows up as an unrelated test breaking in a | ||
| file nobody touched. | ||
|
|
||
| Resetting the bucket around each test keeps the failure attributable and stops | ||
| the package having an effective cap on how many API calls its tests may make in | ||
| total. Only this throttle's key is removed, mirroring the narrowly-scoped | ||
| ``_clear_auth_throttle_keys`` helper in the app authentication tests, rather than | ||
| calling ``cache.clear()`` and disturbing unrelated cached state. | ||
| """ | ||
|
|
||
| import pytest | ||
| from django.core.cache import cache | ||
|
|
||
|
|
||
| def _clear_api_key_throttle_keys(): | ||
| """Delete only ApiKeyRateThrottle history keys from the shared cache. | ||
|
|
||
| ``ApiKeyRateThrottle`` overrides ``get_cache_key`` to return | ||
| ``f"{self.scope}:{api_key}"``, so its entries are ``api_key:<token>`` and do | ||
| not carry DRF's usual ``throttle_`` prefix. | ||
| """ | ||
| cache.delete_pattern("api_key:*") | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _reset_api_key_throttle_cache(): | ||
| """Give every external-API contract test a clean throttle bucket.""" | ||
| _clear_api_key_throttle_keys() | ||
| yield | ||
| _clear_api_key_throttle_keys() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.