-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add pre-request time travel support #28
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
75a5277
first attempt at kinde instrumentation
sohankshirsagar a5aba3f
add pre-request time travel support
sohankshirsagar 24407af
use published schemas
sohankshirsagar c4c26e9
update uv.lock
sohankshirsagar 58f9853
disabled uv cache to fix lock file parsing
sohankshirsagar 29534df
pin uv version
sohankshirsagar 3acb762
update uv.lock
sohankshirsagar 41da685
regenerate uv.lock
sohankshirsagar 3e0cf16
add debugging
sohankshirsagar bcb8167
merge main
sohankshirsagar fe8cc25
hopefully fix uv.lock issue
sohankshirsagar 7c89708
address bug bot comments
sohankshirsagar d45a0f7
address bug bot comment
sohankshirsagar 33a6014
merge main
sohankshirsagar ebd26d2
remove kinde instrumentation
sohankshirsagar 4a6c066
address bug bot comment
sohankshirsagar 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
Some comments aren't visible on the classic Files Changed page.
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
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,5 @@ | ||
| """Kinde SDK instrumentation for bypassing authentication in replay mode.""" | ||
|
|
||
| from .instrumentation import KindeInstrumentation | ||
|
|
||
| __all__ = ["KindeInstrumentation"] |
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,71 @@ | ||
| """Instrumentation for Kinde SDK authentication. | ||
|
|
||
| Patches is_authenticated() to always return True in REPLAY mode, | ||
| allowing tests to bypass authentication checks during replay. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from ..base import InstrumentationBase | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class KindeInstrumentation(InstrumentationBase): | ||
| """Instrumentation for the Kinde SDK authentication library. | ||
|
|
||
| Patches OAuth.is_authenticated() to: | ||
| - Return True in REPLAY mode (bypass authentication) | ||
| - Call the original method in RECORD and DISABLED modes | ||
|
|
||
| Since SmartOAuth and AsyncOAuth delegate to OAuth.is_authenticated(), | ||
| patching OAuth covers all authentication entry points. | ||
| """ | ||
|
|
||
| def __init__(self, enabled: bool = True) -> None: | ||
| super().__init__( | ||
| name="KindeInstrumentation", | ||
| module_name="kinde_sdk.auth.oauth", | ||
| supported_versions="*", | ||
| enabled=enabled, | ||
| ) | ||
|
|
||
| def patch(self, module: Any) -> None: | ||
| """Patch the kinde_sdk.auth.oauth module. | ||
|
|
||
| Patches OAuth.is_authenticated() to return True in REPLAY mode. | ||
| """ | ||
| if not hasattr(module, "OAuth"): | ||
| logger.warning("kinde_sdk.auth.oauth.OAuth not found, skipping instrumentation") | ||
| return | ||
|
|
||
| original_is_authenticated = module.OAuth.is_authenticated | ||
|
|
||
| def patched_is_authenticated(oauth_self) -> bool: | ||
| """Patched is_authenticated method. | ||
|
|
||
| Args: | ||
| oauth_self: OAuth instance | ||
|
|
||
| Returns: | ||
| True in REPLAY mode, otherwise delegates to original method | ||
| """ | ||
| # Lazy imports to avoid circular dependency | ||
| from ...core.drift_sdk import TuskDrift | ||
| from ...core.types import TuskDriftMode | ||
|
|
||
| sdk = TuskDrift.get_instance() | ||
|
|
||
| # In REPLAY mode, always return True to bypass authentication | ||
| if sdk.mode == TuskDriftMode.REPLAY: | ||
| logger.debug("[KindeInstrumentation] REPLAY mode: returning True for is_authenticated") | ||
| return True | ||
|
|
||
| # In RECORD or DISABLED mode, call the original method | ||
| return original_is_authenticated(oauth_self) | ||
|
|
||
| module.OAuth.is_authenticated = patched_is_authenticated | ||
| logger.info("kinde_sdk.auth.oauth.OAuth.is_authenticated instrumented") |
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
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.