-
Notifications
You must be signed in to change notification settings - Fork 0
feat(core): bind browser context origin before observation #117
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
seonghobae
merged 8 commits into
feat/browser-protocol-runtime-adapter-version-binding
from
feat/browser-context-origin-binding
Aug 26, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
48ec0a3
test(core): require browser context origin binding
seonghobae 34993ea
style(core): apply canonical context origin test formatting
seonghobae 2e799ee
feat(core): bind current browser context origin
seonghobae 4f5e9b0
test(core): make controlled origin parsing error-compatible
seonghobae 481ea74
merge: align browser context origin binding with current protocol dis…
seonghobae e2c24bf
merge: align browser origin binding with authority retirement
seonghobae f474174
merge: align context origin binding with current protocol dispatch
seonghobae d7cc599
docs: record browser context origin binding
seonghobae 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
91 changes: 91 additions & 0 deletions
91
crates/originweave-core/tests/browser_context_origin_binding.rs
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,91 @@ | ||
| use std::error::Error; | ||
| use std::io; | ||
|
|
||
| use originweave_core::{ | ||
| BrowserAuthorityRegistry, BrowserRegistryError, BrowserSessionId, BrowsingContextId, | ||
| DocumentEpoch, Origin, | ||
| }; | ||
|
|
||
| fn first_origin() -> Result<Origin, Box<dyn Error>> { | ||
| Origin::parse("http://127.0.0.1:43127") | ||
| .map_err(|_error| io::Error::other("controlled first origin must be valid").into()) | ||
| } | ||
|
|
||
| fn second_origin() -> Result<Origin, Box<dyn Error>> { | ||
| Origin::parse("http://localhost:43127") | ||
| .map_err(|_error| io::Error::other("controlled second origin must be valid").into()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn context_origin_can_be_bound_before_node_discovery() -> Result<(), Box<dyn Error>> { | ||
| let mut registry = BrowserAuthorityRegistry::new(); | ||
| let session = registry.register_session("webdriver-session")?; | ||
| let context = registry.register_context(session, "top-level-context")?; | ||
| let origin = first_origin()?; | ||
|
|
||
| let epoch = registry.bind_context_origin(session, context, &origin)?; | ||
| assert_eq!(epoch, DocumentEpoch::new(1)?); | ||
| assert_eq!( | ||
| registry.bind_context_origin(session, context, &origin)?, | ||
| epoch | ||
| ); | ||
|
|
||
| let node = registry.bind_node(session, context, &origin, "backend-node-17")?; | ||
| assert_eq!(node.document_epoch(), epoch); | ||
| assert_eq!(node.origin(), &origin); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn context_origin_change_requires_document_rotation() -> Result<(), Box<dyn Error>> { | ||
| let mut registry = BrowserAuthorityRegistry::new(); | ||
| let session = registry.register_session("webdriver-session")?; | ||
| let context = registry.register_context(session, "top-level-context")?; | ||
| let first = first_origin()?; | ||
| let second = second_origin()?; | ||
|
|
||
| registry.bind_context_origin(session, context, &first)?; | ||
| assert_eq!( | ||
| registry.bind_context_origin(session, context, &second), | ||
| Err(BrowserRegistryError::OriginChangedWithoutDocumentAdvance) | ||
| ); | ||
|
|
||
| let next_epoch = registry.advance_document(context)?; | ||
| assert_eq!(next_epoch, DocumentEpoch::new(2)?); | ||
| assert_eq!( | ||
| registry.bind_context_origin(session, context, &second)?, | ||
| next_epoch | ||
| ); | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn context_origin_binding_rejects_cross_session_and_unknown_authority() -> Result<(), Box<dyn Error>> | ||
| { | ||
| let mut registry = BrowserAuthorityRegistry::new(); | ||
| let owner = registry.register_session("owner-session")?; | ||
| let attacker = registry.register_session("attacker-session")?; | ||
| let context = registry.register_context(owner, "top-level-context")?; | ||
| let origin = first_origin()?; | ||
|
|
||
| assert_eq!( | ||
| registry.bind_context_origin(attacker, context, &origin), | ||
| Err(BrowserRegistryError::ContextSessionMismatch { | ||
| expected: owner, | ||
| actual: attacker, | ||
| }) | ||
| ); | ||
|
|
||
| let unknown_session = BrowserSessionId::new(999)?; | ||
| assert_eq!( | ||
| registry.bind_context_origin(unknown_session, context, &origin), | ||
| Err(BrowserRegistryError::UnknownBrowserSession) | ||
| ); | ||
|
|
||
| let unknown_context = BrowsingContextId::new(999)?; | ||
| assert_eq!( | ||
| registry.bind_context_origin(owner, unknown_context, &origin), | ||
| Err(BrowserRegistryError::UnknownBrowsingContext) | ||
| ); | ||
| Ok(()) | ||
| } |
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.