feat #14740: release builds use the production backend

Release builds talk to https://backend.euvinopro.eu, debug builds keep
https://test.euvinopro.eu. A key bound to the test backend is discarded
in a release build (fresh login).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
hauke
2026-11-09 10:51:09 +01:00
co-authored by Claude Opus 5.5
parent a0f89454f9
commit d0ece263a2
2 changed files with 55 additions and 7 deletions
+10 -5
View File
@@ -31,11 +31,13 @@ use crate::state::AppState;
// The backend this build talks to: the one place to change it. It is not a
// setting; a key created on one backend is never sent to another.
/// Release builds. Switch to "https://backend.euvinopro.eu" here, then
/// release, once that backend is live.
const RELEASE_BACKEND_URL: &str = "https://test.euvinopro.eu";
/// Debug builds (`cargo tauri dev`) always use the test backend.
const DEV_BACKEND_URL: &str = "https://test.euvinopro.eu";
/// Release builds: the production euvino admin backend.
pub(crate) const RELEASE_BACKEND_URL: &str = "https://backend.euvinopro.eu";
/// Debug builds (`cargo tauri dev`) always use the test backend, never the
/// production one. `pub(crate)`: `state.rs` tests the exact test-backend →
/// release-backend transition against this value (a key bound to one must
/// never work for the other).
pub(crate) const DEV_BACKEND_URL: &str = "https://test.euvinopro.eu";
/// The backend of this build (no trailing slash).
pub const BACKEND_URL: &str = if cfg!(debug_assertions) {
DEV_BACKEND_URL
@@ -461,6 +463,9 @@ mod tests {
assert!(!url.ends_with('/'), "{url}");
assert!(url.starts_with("https://"), "{url}");
}
// Release and dev talk to different backends: a key from one must
// never be usable on the other (see AppState::backend_key).
assert_ne!(RELEASE_BACKEND_URL, DEV_BACKEND_URL);
}
#[test]
+45 -2
View File
@@ -1538,6 +1538,42 @@ mod tests {
}
}
/// The real transition the review asked to lock in: a key created while
/// this install talked to the test backend must not work once the same
/// install is a release build talking to the production backend — it is
/// discarded and a fresh login is required, exactly like any other
/// backend mismatch above, but with the two real build-time constants
/// instead of a placeholder domain.
#[test]
fn a_key_from_the_test_backend_does_not_work_for_a_release_build() {
let mut f = fixture();
// A build on the test backend (what `cargo tauri dev` is), whatever
// profile this test itself runs in.
f.state.backend_url = crate::backend::DEV_BACKEND_URL.to_string();
f.state
.store_backend_key(
&new_key("euv_test"),
crate::backend::DEV_BACKEND_URL,
Some("hinrichs".into()),
)
.unwrap();
assert!(f.state.backend_key().is_some());
// Same keyring entry and settings file; now read as a release build
// would (a different `backend_url`, nothing else changed).
f.state.backend_url = crate::backend::RELEASE_BACKEND_URL.to_string();
assert_eq!(
f.state.backend_key(),
None,
"a test-backend key must not work for the release backend"
);
assert_eq!(f.state.secrets.get(Service::Backend), None);
let settings = f.state.settings();
assert_eq!(settings.backend_username, None);
assert_eq!(settings.backend_key_base_url, None);
}
#[test]
fn the_backend_login_is_refreshed_from_the_key_info() {
let f = fixture();
@@ -1622,10 +1658,17 @@ mod tests {
#[test]
fn the_backend_is_fixed_per_build() {
let f = fixture();
assert_eq!(f.state.backend_url(), "https://test.euvinopro.eu");
// Debug builds (`cargo tauri dev`, `cargo test`) use the test
// backend, release builds the production one.
let expected = if cfg!(debug_assertions) {
"https://test.euvinopro.eu"
} else {
"https://backend.euvinopro.eu"
};
assert_eq!(f.state.backend_url(), expected);
assert_eq!(
f.state.backend_client().login_url(),
"https://test.euvinopro.eu/euvadm"
format!("{expected}/euvadm")
);
}