-
Notifications
You must be signed in to change notification settings - Fork 26
feat: configurable API-key header (api_key_header) #74
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
Fuseboxlab
wants to merge
1
commit into
makeplane:main
Choose a base branch
from
Fuseboxlab:feat/api-key-header
base: main
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.
+54
−2
Open
Changes from all commits
Commits
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
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,44 @@ | ||
| """Unit tests for the configurable API-key header (no network, no env).""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from plane.api.base_resource import BaseResource | ||
| from plane.api.v2._kernel.transport import V2Transport | ||
| from plane.client import PlaneClient | ||
| from plane.config import Configuration | ||
| from plane.errors.errors import ConfigurationError | ||
|
|
||
|
|
||
| def test_default_header_is_x_api_key() -> None: | ||
| config = Configuration(base_path="https://api.plane.so", api_key="k") | ||
| headers = BaseResource(config, "/workspaces/")._headers() | ||
| assert headers["X-Api-Key"] == "k" | ||
|
|
||
|
|
||
| def test_custom_header_replaces_x_api_key_in_v1_and_v2() -> None: | ||
| config = Configuration( | ||
| base_path="http://gateway/plane-api", api_key="k", api_key_header="X-Gravitee-Api-Key" | ||
| ) | ||
| for headers in (BaseResource(config, "/workspaces/")._headers(), V2Transport(config)._headers()): | ||
| assert headers["X-Gravitee-Api-Key"] == "k" | ||
| assert "X-Api-Key" not in headers | ||
|
|
||
|
|
||
| def test_plane_client_passes_the_header_through() -> None: | ||
| client = PlaneClient(base_url="http://gateway", api_key="k", api_key_header="X-Custom-Key") | ||
| assert client.config.api_key_header == "X-Custom-Key" | ||
| assert client.work_items._headers()["X-Custom-Key"] == "k" | ||
|
|
||
|
|
||
| def test_blank_header_is_refused() -> None: | ||
| with pytest.raises(ConfigurationError): | ||
| Configuration(base_path="https://api.plane.so", api_key="k", api_key_header=" ") | ||
|
|
||
|
|
||
| def test_access_token_ignores_the_header_setting() -> None: | ||
| config = Configuration(base_path="https://api.plane.so", access_token="t", api_key_header="X-Other") | ||
| headers = BaseResource(config, "/workspaces/")._headers() | ||
| assert headers["Authorization"] == "Bearer t" | ||
| assert "X-Other" not in headers |
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.
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.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: makeplane/plane-python-sdk
Length of output: 8465
Reject invalid HTTP header names during configuration.
A value such as
X Custom Keypasses the current check. Whenapi_keyis set, both request builders use it as the header name. Requests can then fail during HTTP header serialization before the server receives the request. The defaultX-Api-Keyremains valid, so this affects callers that explicitly configure an invalid name. Validate the stripped name as an HTTP header field name and raiseConfigurationErrorduring configuration.🤖 Prompt for AI Agents
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: makeplane/plane-python-sdk
Length of output: 4239
🏁 Script executed:
Repository: makeplane/plane-python-sdk
Length of output: 7796
Reserve
Content-Typefor request metadata.When
api_key_headerisContent-Type, both builders overwriteapplication/json. Case variants are also normalized byrequestsas the same header name, and the later API-key value wins. RejectContent-Typecase-insensitively.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents