-
Notifications
You must be signed in to change notification settings - Fork 0
Add backwards compatibility tests and fix concurrent mutation data loss #59
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 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f6a4a67
Fix clippy lints in db tests and common test infra
xumaple 021630a
Add backwards compatibility tests for persistent test user
xumaple a68f226
Move backcompat constants into common::backcompat module
xumaple 1a40c91
Rework backcompat tests to use real client-side crypto
xumaple 7ab770c
Add all test suites to CI workflow
xumaple 0eadf47
Run all integration test files with cargo test --tests
xumaple 0fed3f0
Address PR review: trim comments, verify decryption, remove dead cleanup
xumaple 880eb4c
Fix stale count in change_master_password, run concurrency tests 10x …
xumaple 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| //! One-time setup for the backwards-compatibility test user. | ||
| //! | ||
| //! This test is `#[ignore]`d so it only runs when explicitly requested: | ||
| //! | ||
| //! ```sh | ||
| //! cargo test --test backcompat_setup -- --ignored --features test-helpers | ||
| //! ``` | ||
| //! | ||
| //! It creates a permanent user with known credentials and stored passwords. | ||
| //! If the user already exists (duplicate → 404 under uniform error policy), | ||
| //! the test succeeds gracefully. | ||
|
|
||
| mod common; | ||
|
|
||
| use axum::body::Body; | ||
| use common::backcompat::{BACKCOMPAT_PW, BACKCOMPAT_USER, OLD_RAW_USER, EXPECTED_PASSWORDS}; | ||
| use common::{app, body_string, run, WithAuth}; | ||
| use http::{Request, StatusCode}; | ||
| use tower::ServiceExt; | ||
|
|
||
| #[test] | ||
| #[ignore] | ||
| fn setup_backcompat_user() { | ||
| run(async { | ||
| // 0. Clean up the old broken user that was created with the raw | ||
| // (unhashed) username. Ignore errors — the user may not exist. | ||
| let req = Request::builder() | ||
| .method("DELETE") | ||
| .uri("/api/v2/user") | ||
| .header("x-username", OLD_RAW_USER) | ||
| .header("x-password", "unused") | ||
| .body(Body::empty()) | ||
| .unwrap(); | ||
| let res = app().oneshot(req).await.unwrap(); | ||
| eprintln!( | ||
| "Old user cleanup: status {}", | ||
| res.status() | ||
| ); | ||
|
|
||
| // 1. Create the user with hashed credentials (as the frontend would | ||
| // send after `encryptMaster()`). If it already exists the API | ||
| // returns 404 (uniform error responses), which we treat as success. | ||
| let req = Request::builder() | ||
| .method("POST") | ||
| .uri("/api/v2/user") | ||
| .auth(BACKCOMPAT_USER, BACKCOMPAT_PW) | ||
| .body(Body::empty()) | ||
| .unwrap(); | ||
| let res = app().oneshot(req).await.unwrap(); | ||
| let status = res.status(); | ||
| let body = body_string(res).await; | ||
| match status { | ||
| StatusCode::OK => eprintln!("Created backcompat user"), | ||
| StatusCode::NOT_FOUND => { | ||
| eprintln!("Backcompat user already exists (got 404): {body}"); | ||
| } | ||
| other => panic!("Unexpected status {other} creating backcompat user: {body}"), | ||
| } | ||
|
|
||
| // 2. Verify we can authenticate as the backcompat user. | ||
| let req = Request::builder() | ||
| .method("GET") | ||
| .uri("/api/v2/user/verify") | ||
| .auth(BACKCOMPAT_USER, BACKCOMPAT_PW) | ||
| .body(Body::empty()) | ||
| .unwrap(); | ||
| let res = app().oneshot(req).await.unwrap(); | ||
| assert_eq!( | ||
| res.status(), | ||
| StatusCode::OK, | ||
| "backcompat user must be verifiable after creation" | ||
| ); | ||
|
|
||
| // 3. Add stored passwords with AES-encrypted values (encrypted with | ||
| // SHA-256 of the plaintext password as key). If a key already | ||
| // exists the API returns 404 (duplicate key → uniform error), | ||
| // which we skip gracefully. | ||
| for (key, enc_pw) in EXPECTED_PASSWORDS { | ||
| let req = Request::builder() | ||
| .method("POST") | ||
| .uri(format!("/api/v2/passwords/{key}")) | ||
| .auth(BACKCOMPAT_USER, BACKCOMPAT_PW) | ||
| .header("content-type", "application/json") | ||
| .body(Body::from(format!( | ||
| r#"{{"encrypted_password":"{enc_pw}"}}"# | ||
| ))) | ||
| .unwrap(); | ||
| let res = app().oneshot(req).await.unwrap(); | ||
| let status = res.status(); | ||
| match status { | ||
| StatusCode::OK => eprintln!("Added key '{key}'"), | ||
| StatusCode::NOT_FOUND => { | ||
| eprintln!("Key '{key}' already exists (got 404), skipping"); | ||
| } | ||
| other => { | ||
| let body = body_string(res).await; | ||
| panic!("Unexpected status {other} adding key '{key}': {body}"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| eprintln!("Backcompat setup complete."); | ||
| }); | ||
| } |
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,95 @@ | ||
| //! Backwards-compatibility tests for the permanent backcompat test user. | ||
| //! | ||
| //! These tests verify that a user created by `backcompat_setup.rs` can still | ||
| //! authenticate and retrieve their stored passwords. This guards against | ||
| //! breaking changes to auth, encryption, or data format. | ||
| //! | ||
| //! ## Prerequisites | ||
| //! | ||
| //! Run the setup once before these tests: | ||
| //! | ||
| //! ```sh | ||
| //! cargo test --test backcompat_setup -- --ignored --features test-helpers | ||
| //! ``` | ||
| //! | ||
| //! ## Running | ||
| //! | ||
| //! ```sh | ||
| //! cargo test --test backcompat_tests --features test-helpers | ||
| //! ``` | ||
|
|
||
| mod common; | ||
|
|
||
| use axum::body::Body; | ||
| use common::backcompat::{BACKCOMPAT_PW, BACKCOMPAT_USER, EXPECTED_KEYS, EXPECTED_PASSWORDS}; | ||
| use common::{app, body_string, parse_json, run, WithAuth}; | ||
| use http::{Request, StatusCode}; | ||
| use tower::ServiceExt; | ||
|
|
||
| // ── Tests ─────────────────────────────────────────────────────────────────── | ||
|
|
||
| #[test] | ||
| fn test_backcompat_user_can_authenticate() { | ||
| run(async { | ||
| let req = Request::builder() | ||
| .method("GET") | ||
| .uri("/api/v2/user/verify") | ||
| .auth(BACKCOMPAT_USER, BACKCOMPAT_PW) | ||
| .body(Body::empty()) | ||
| .unwrap(); | ||
| let res = app().oneshot(req).await.unwrap(); | ||
| assert_eq!( | ||
| res.status(), | ||
| StatusCode::OK, | ||
| "backcompat user should authenticate with known credentials" | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_backcompat_user_keys_exist() { | ||
| run(async { | ||
| let req = Request::builder() | ||
| .method("GET") | ||
| .uri("/api/v2/keys") | ||
| .auth(BACKCOMPAT_USER, BACKCOMPAT_PW) | ||
| .body(Body::empty()) | ||
| .unwrap(); | ||
| let res = app().oneshot(req).await.unwrap(); | ||
| assert_eq!(res.status(), StatusCode::OK); | ||
|
|
||
| let keys: Vec<String> = parse_json(&body_string(res).await); | ||
| for expected_key in EXPECTED_KEYS { | ||
| assert!( | ||
| keys.contains(&(*expected_key).to_string()), | ||
| "expected key '{expected_key}' not found in keys: {keys:?}" | ||
| ); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_backcompat_user_passwords_retrievable() { | ||
| run(async { | ||
| for (key, expected_value) in EXPECTED_PASSWORDS { | ||
| let req = Request::builder() | ||
| .method("GET") | ||
| .uri(format!("/api/v2/passwords/{key}")) | ||
| .auth(BACKCOMPAT_USER, BACKCOMPAT_PW) | ||
| .body(Body::empty()) | ||
| .unwrap(); | ||
| let res = app().oneshot(req).await.unwrap(); | ||
| assert_eq!( | ||
| res.status(), | ||
| StatusCode::OK, | ||
| "GET /passwords/{key} should succeed" | ||
| ); | ||
|
|
||
| let value: String = parse_json(&body_string(res).await); | ||
| assert_eq!( | ||
| value, *expected_value, | ||
| "password for key '{key}' does not match expected value" | ||
| ); | ||
| } | ||
| }); | ||
| } | ||
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.