Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(relay): keep path mode beside a host domain, send old share links to their origin (#6061)

ddupont8ed5bd3c5d04
diff --git a/docs/content/docs/cua-cli/guides/share-a-link.mdx b/docs/content/docs/cua-cli/guides/share-a-link.mdx
index 3b2696e757..acdef2dae9 100644
--- a/docs/content/docs/cua-cli/guides/share-a-link.mdx
+++ b/docs/content/docs/cua-cli/guides/share-a-link.mdx
@@ -62,6 +62,11 @@ for public ones), so a shared app sees its own root, its links work, and one
share's cookies never reach another. The sign-in cookie is limited to that one
share and lasts at most 12 hours. Public links need no sign-in.
+On cua.ai the domain is `m.cua.sh`, kept apart from `cua.ai` so a shared page
+can never set cookies for your account's sites. Links made before the move
+(`https://relay.cua.ai/m/<machine>/share/…`) still work: a browser that opens
+one is sent to the same share on `m.cua.sh`.
+
<Callout type="warn">
The browser sign-in needs the relay's web client configured by the relay
operator (`CUA_RELAY_WEB_CLIENT_ID` and a host domain; see "Share links" in
diff --git a/libs/cua-spacesd/crates/cua-relay/README.md b/libs/cua-spacesd/crates/cua-relay/README.md
index 19c9e2183e..835f8a1525 100644
--- a/libs/cua-spacesd/crates/cua-relay/README.md
+++ b/libs/cua-spacesd/crates/cua-relay/README.md
@@ -260,40 +260,53 @@ sent none.
The stronger fix, also shipped in code: set `CUA_RELAY_HOST_DOMAIN` to a
**separate registrable domain** from the one the account API and viewer
-live on (for example `m.relay.cua.ai` under `relay.cua.ai`'s parent zone,
-or better, an entirely different domain such as `cua-relay.net`, the way
-GitHub serves `github.dev`/`app.github.dev` off `github.com`). Once set:
+live on, the way GitHub serves `github.dev` off `github.com`. The hosted
+relay uses `m.cua.sh` (`relay.cua.ai` keeps the account API; staging uses
+`m.staging.cua.sh`). A domain of its own matters twice: a page on it can
+never set cookies for the account domain, and if someone shares something
+malicious, reputation systems flag the share's domain, not the account
+domain. Listing the host domain on the Public Suffix List (as `m.cua.sh` is
+requested to be) also stops one share's origin from setting cookies for
+every other share. Once set:
- every machine gets `https://<id>.<host_domain>` (`Relay::machine_url`,
- what `GET /v1/machines` reports as each machine's `url`);
+ what `GET /v1/machines` reports as each machine's `url`), and each share
+ its own origin under it (below);
- path mode (`/m/<id>/…`) stops forwarding on the main origin entirely
(`route()` refuses it with 404), so a machine's response is never reached
- by a request to `relay.cua.ai` itself, and cookies, storage and a Service
+ by a request to the relay's own origin, and cookies, storage and a Service
Worker a rogue machine sets can only ever apply to *its own* subdomain,
never to the relay's own pages or to a different machine's subdomain
(browsers isolate by origin, and a subdomain is a different origin).
-This needs a **DNS and TLS change outside this repo** (cloud, not code):
-
-1. **DNS.** Add a wildcard record for the machine domain, for example
- `*.m.relay.cua.ai` (or the whole separate domain), pointing at the same
- Traefik/load balancer `relay.cua.ai` already uses. Keep it DNS-only /
- no-proxy, the way `relay.cua.ai` itself is set up, so the TLS handshake
- reaches Traefik directly.
-2. **TLS.** Issue a wildcard certificate for `*.m.relay.cua.ai` (cert-manager
- `Certificate` with DNS-01, since HTTP-01 cannot prove a wildcard; the
- existing `relay.cua.ai` cert uses HTTP-01 and does not cover this). Add
- the wildcard host to the `IngressRoute`/`IngressRouteTCP` that fronts the
- relay pod, routed to the same Service.
-3. **Deploy.** Set `CUA_RELAY_HOST_DOMAIN=m.relay.cua.ai` (or the chosen
- domain) on the relay Deployment and keep `CUA_RELAY_PUBLIC_URL` pointing
- at the account-API origin (`https://relay.cua.ai`) unchanged.
-4. **Clients.** Nothing to change: clients already follow the `url` the
- directory API reports per machine (`Relay::machine_url`); they do not
- hardcode `/m/<id>`.
-
-See the PR report for exact copy-pasteable manifest and DNS steps for this
-deployment.
+**Keeping path mode (`CUA_RELAY_KEEP_PATH_MODE=on`).** Clients that build
+`<relay>/m/<id>` URLs themselves (older `cua` builds, and anything that
+saved such a URL) keep working when this is on: `/m/<id>/…` is still
+forwarded on the main origin, with every response hardened as above (no
+cookies, no rendered HTML outside the viewer). The one exception is an old
+path-mode share link opened by a browser: a request for
+`/m/<id>/share/<key>/…` or `/m/<id>/share/pub/<token>/…` that carries no
+account credential header gets a `308` to the same path on the share's own
+origin (`<s|p><key>-<id prefix>.<host_domain>/…`). A tool that sends a
+bearer token keeps getting path mode. The hosted relay runs with this on
+while older clients are in use; turning it off is the full S6 setting.
+
+Deploying a host domain needs DNS and TLS outside this repo:
+
+1. **DNS.** A wildcard record for the machine domain (for example
+ `*.m.cua.sh`) pointing at the same Traefik/load balancer the relay's own
+ origin uses. Keep it DNS-only / no proxy, the way `relay.cua.ai` is set
+ up, so the TLS handshake and long-lived WebSockets reach Traefik
+ directly.
+2. **TLS.** A wildcard certificate for it (cert-manager `Certificate` with
+ DNS-01, since HTTP-01 cannot prove a wildcard). Add the wildcard host to
+ an `IngressRoute` that fronts the relay pod (gRPC to the h2c scheme like
+ the main origin), routed to the same Service.
+3. **Deploy.** Set `CUA_RELAY_HOST_DOMAIN` (and `CUA_RELAY_KEEP_PATH_MODE=on`
+ while clients still use path mode) on the relay Deployment and keep
+ `CUA_RELAY_PUBLIC_URL` pointing at the account-API origin unchanged.
+4. **Clients.** Share links follow the `url` the directory API reports per
+ machine; nothing to change.
## Share links (`cua share`)
diff --git a/libs/cua-spacesd/crates/cua-relay/src/main.rs b/libs/cua-spacesd/crates/cua-relay/src/main.rs
index fb11561522..54f872895e 100644
--- a/libs/cua-spacesd/crates/cua-relay/src/main.rs
+++ b/libs/cua-spacesd/crates/cua-relay/src/main.rs
@@ -28,6 +28,12 @@ struct Args {
/// Host-mode domain: `<computer-id>.<domain>` routes to that computer.
#[arg(long, env = "CUA_RELAY_HOST_DOMAIN")]
host_domain: Option<String>,
+ /// With a host domain, keep serving `/m/<computer-id>/…` on the main
+ /// origin too (`on` / `off`): for clients that build path-mode URLs
+ /// themselves. Browsers that open a path-mode share link are sent to
+ /// the share's own origin.
+ #[arg(long, env = "CUA_RELAY_KEEP_PATH_MODE", default_value = "off")]
+ keep_path_mode: String,
/// Maximum computers per registration token.
#[arg(long, env = "CUA_RELAY_MAX_MACHINES_PER_TOKEN", default_value_t = 16)]
max_machines_per_token: usize,
@@ -411,6 +417,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
machine_max_streams: args.machine_max_streams,
machine_window_bytes: args.machine_window_bytes,
machine_idle_timeout: Duration::from_secs(args.idle_secs.max(5)),
+ keep_path_mode: on_off("CUA_RELAY_KEEP_PATH_MODE", &args.keep_path_mode)?,
host_domain: args.host_domain,
admin_token: args.admin_token.filter(|t| !t.is_empty()),
require_client_credentials: !args.allow_anonymous_clients,
diff --git a/libs/cua-spacesd/crates/cua-relay/src/server.rs b/libs/cua-spacesd/crates/cua-relay/src/server.rs
index ea3d3c83ac..b2431c0351 100644
--- a/libs/cua-spacesd/crates/cua-relay/src/server.rs
+++ b/libs/cua-spacesd/crates/cua-relay/src/server.rs
@@ -77,6 +77,12 @@ pub struct RelayConfig {
pub machine_idle_timeout: Duration,
/// Host-mode domain: `<id>.<domain>` routes to machine `<id>`.
pub host_domain: Option<String>,
+ /// With a host domain, keep forwarding `/m/<id>/…` on the main origin
+ /// (for clients that build path-mode URLs), except that a browser
+ /// opening a path-mode share link is redirected to the share's own
+ /// origin (see [`legacy_share_redirect`]). Off: a host domain turns
+ /// path mode off (S6).
+ pub keep_path_mode: bool,
/// Token for `/relay/v1/machines`.
pub admin_token: Option<String>,
/// Refuse client requests that carry no spacesd credential
@@ -172,6 +178,7 @@ impl Default for RelayConfig {
max_streams_per_machine: crate::mux::MAX_STREAMS as u32,
machine_idle_timeout: Duration::from_secs(90),
host_domain: None,
+ keep_path_mode: false,
admin_token: None,
require_client_credentials: true,
oidc: None,
@@ -1477,7 +1484,7 @@ fn route_ex(relay: &Relay, uri: &Uri, headers: &HeaderMap) -> Option<Routed> {
)
};
if let Some(rest) = path.strip_prefix("/m/") {
- if domain.is_some() {
+ if domain.is_some() && !relay.config.keep_path_mode {
return None;
}
let (id, tail) = match rest.find('/') {
@@ -1523,6 +1530,43 @@ fn route_ex(relay: &Relay, uri: &Uri, headers: &HeaderMap) -> Option<Routed> {
})
}
+/// Where a browser that opened a path-mode share link
+/// (`<relay>/m/<id>/share/<key>/…`, `…/share/pub/<token>/…`) on a relay that
+/// now has a host domain and keeps path mode should go instead: the same
+/// path on the share's own origin, `<s|p><key>-<id prefix>.<domain>`.
+///
+/// Only requests without an account credential header are redirected (a
+/// browser never sends one; a tool that does keeps getting path mode), and
+/// only when the label is well formed, so anything else is routed as before.
+fn legacy_share_redirect(relay: &Relay, uri: &Uri, headers: &HeaderMap) -> Option<String> {
+ let domain = relay.config.host_domain.as_deref()?;
+ if !relay.config.keep_path_mode
+ || headers.contains_key(header::AUTHORIZATION)
+ || headers.contains_key("x-cua-env-authorization")
+ {
+ return None;
+ }
+ let rest = uri.path().strip_prefix("/m/")?;
+ let (id, tail) = rest.split_once('/')?;
+ let tail = format!("/{tail}");
+ let (kind, sid) = crate::share_web::share_of_path(&tail)?;
+ let (letter, base) = match kind {
+ crate::share_web::ShareKind::Public => ('p', format!("/share/pub/{sid}")),
+ crate::share_web::ShareKind::Private => ('s', format!("/share/{sid}")),
+ };
+ let id_prefix: String = id.chars().take(16).collect();
+ let label = format!("{letter}{sid}-{id_prefix}");
+ crate::share_web::parse_label(&label)?;
+ let path = tail.strip_prefix(&base)?;
+ let path = if path.is_empty() { "/" } else { path };
+ if !path.starts_with('/') {
+ return None;
+ }
+ let query = uri.query().map(|q| format!("?{q}")).unwrap_or_default();
+ let scheme = relay.share_scheme(headers);
+ Some(format!("{scheme}://{label}.{domain}{path}{query}"))
+}
+
/// The address a request came from, for the public-share rate limit: the
/// socket peer, or, when the peer is a configured trusted proxy, the client
/// address it forwarded (see [`crate::proxies`]).
@@ -2041,6 +2085,21 @@ async fn proxy(state: State<Relay>, request: Request) -> Response {
}
async fn proxy_inner(State(relay): State<Relay>, mut request: Request) -> Response {
+ if let Some(location) = legacy_share_redirect(&relay, request.uri(), request.headers()) {
+ let mut response = Response::new(axum::body::Body::empty());
+ *response.status_mut() = StatusCode::PERMANENT_REDIRECT;
+ if let Ok(v) = HeaderValue::from_str(&location) {
+ response.headers_mut().insert(header::LOCATION, v);
+ }
+ response.headers_mut().insert(
+ header::REFERRER_POLICY,
+ HeaderValue::from_static("no-referrer"),
+ );
+ response
+ .extensions_mut()
+ .insert(crate::conn_metrics::Uncounted);
+ return response;
+ }
let Some(Routed {
id,
forwarded,
@@ -2716,6 +2775,96 @@ mod tests {
assert_eq!(route(&relay(None), &"/files".parse().unwrap(), &host), None);
}
+ fn kept(domain: &str) -> Relay {
+ Relay::new(RelayConfig {
+ host_domain: Some(domain.into()),
+ keep_path_mode: true,
+ public_url: Some("https://relay.example".into()),
+ ..RelayConfig::default()
+ })
+ }
+
+ #[test]
+ fn keep_path_mode_forwards_both_modes() {
+ let r = kept("m.share.example");
+ let h = HeaderMap::new();
+ assert_eq!(
+ route(
+ &r,
+ &"/m/abc123/cua.env.v1.SystemService/Health".parse().unwrap(),
+ &h
+ ),
+ Some((
+ "abc123".into(),
+ "/cua.env.v1.SystemService/Health".into(),
+ "/m/abc123".into()
+ ))
+ );
+ let mut host = HeaderMap::new();
+ host.insert(header::HOST, "abc123.m.share.example".parse().unwrap());
+ assert_eq!(
+ route(&r, &"/files".parse().unwrap(), &host),
+ Some(("abc123".into(), "/files".into(), String::new()))
+ );
+ assert_eq!(
+ r.machine_url(&h, "abc123"),
+ "https://abc123.m.share.example"
+ );
+ }
+
+ #[test]
+ fn browsers_on_old_share_links_go_to_the_share_origin() {
+ const ID: &str = "0123456789abcdef0123456789abcdef";
+ let r = kept("m.share.example");
+ let h = HeaderMap::new();
+ let token = "a".repeat(40);
+ let go = |r: &Relay, path: &str, h: &HeaderMap| {
+ legacy_share_redirect(r, &path.parse().unwrap(), h)
+ };
+ assert_eq!(
+ go(&r, &format!("/m/{ID}/share/pub/{token}/app/x.js?v=1"), &h).as_deref(),
+ Some(
+ format!("https://p{token}-0123456789abcdef.m.share.example/app/x.js?v=1").as_str()
+ )
+ );
+ assert_eq!(
+ go(&r, &format!("/m/{ID}/share/pub/{token}"), &h).as_deref(),
+ Some(format!("https://p{token}-0123456789abcdef.m.share.example/").as_str())
+ );
+ assert_eq!(
+ go(&r, &format!("/m/{ID}/share/aaaa1111bbbb2222/"), &h).as_deref(),
+ Some("https://saaaa1111bbbb2222-0123456789abcdef.m.share.example/")
+ );
+ // A tool with an account token keeps path mode.
+ let mut bearer = HeaderMap::new();
+ bearer.insert(header::AUTHORIZATION, "Bearer t".parse().unwrap());
+ assert_eq!(
+ go(&r, &format!("/m/{ID}/share/aaaa1111bbbb2222/"), &bearer),
+ None
+ );
+ // Not a share, a malformed share id, a non-hex machine id: routed as before.
+ assert_eq!(go(&r, &format!("/m/{ID}/files"), &h), None);
+ assert_eq!(go(&r, &format!("/m/{ID}/share/nothex/"), &h), None);
+ assert_eq!(
+ go(&r, "/m/my-machine-name/share/aaaa1111bbbb2222/", &h),
+ None
+ );
+ // Without keep_path_mode (or without a host domain) nothing redirects.
+ let strict = relay(Some("m.share.example"));
+ assert_eq!(
+ go(&strict, &format!("/m/{ID}/share/aaaa1111bbbb2222/"), &h),
+ None
+ );
+ assert_eq!(
+ go(
+ &relay(None),
+ &format!("/m/{ID}/share/aaaa1111bbbb2222/"),
+ &h
+ ),
+ None
+ );
+ }
+
#[test]
fn machine_url_prefers_the_host_domain() {
let mut config = RelayConfig {
diff --git a/libs/cua-spacesd/crates/cua-relay/tests/share_links.rs b/libs/cua-spacesd/crates/cua-relay/tests/share_links.rs
index 67c3279246..9df2c93467 100644
--- a/libs/cua-spacesd/crates/cua-relay/tests/share_links.rs
+++ b/libs/cua-spacesd/crates/cua-relay/tests/share_links.rs
@@ -143,6 +143,7 @@ struct Opts {
web: bool,
limits: ShareLimits,
trusted_proxies: &'static str,
+ keep_path_mode: bool,
}
impl Default for Opts {
@@ -152,6 +153,7 @@ impl Default for Opts {
web: true,
limits: ShareLimits::default(),
trusted_proxies: "",
+ keep_path_mode: false,
}
}
}
@@ -186,6 +188,7 @@ impl Env {
device_enrollment: false,
state_file: Some(state.path().join("machines.json")),
host_domain: o.host_mode.then(|| DOMAIN.to_owned()),
+ keep_path_mode: o.keep_path_mode,
public_url: Some(base.clone()),
share_web: o.web.then(|| ShareWebConfig {
client_id: "share-web".into(),
@@ -783,6 +786,78 @@ async fn path_mode_serves_shares_but_never_renders_their_html() {
assert_eq!(r.status(), StatusCode::UNAUTHORIZED);
}
+#[tokio::test]
+async fn kept_path_mode_sends_browsers_on_old_links_to_the_share_origin() {
+ let env = Env::start(Opts {
+ web: false,
+ keep_path_mode: true,
+ ..Opts::default()
+ })
+ .await;
+ let m = &env.machine;
+ // An old public link opened by a browser: the same path on its own origin.
+ let r = env
+ .http
+ .get(format!("{}/m/{m}/share/pub/{TOKEN}/report/?v=2", env.base))
+ .send()
+ .await
+ .unwrap();
+ assert_eq!(r.status(), StatusCode::PERMANENT_REDIRECT);
+ let host = env.public_host(TOKEN);
+ assert_eq!(
+ r.headers()[header::LOCATION],
+ format!("http://{host}/report/?v=2").as_str()
+ );
+ let r = env.get(&host, "/report/?v=2").send().await.unwrap();
+ assert_eq!(r.status(), StatusCode::OK);
+ let seen: Value = r.json().await.unwrap();
+ assert_eq!(seen["uri"], format!("/share/pub/{TOKEN}/report/?v=2"));
+ // An old private link: the same, to the private share origin.
+ let r = env
+ .http
+ .get(format!("{}/m/{m}/share/{SID}/", env.base))
+ .send()
+ .await
+ .unwrap();
+ assert_eq!(r.status(), StatusCode::PERMANENT_REDIRECT);
+ let location = r.headers()[header::LOCATION].to_str().unwrap().to_owned();
+ assert!(
+ location.starts_with(&format!("http://s{SID}-{}", &m[..16])),
+ "{location}"
+ );
+ // A tool with the account's token keeps path mode.
+ let r = env
+ .http
+ .get(format!("{}/m/{m}/share/{SID}/x", env.base))
+ .bearer_auth(env.token("ada"))
+ .send()
+ .await
+ .unwrap();
+ assert_eq!(r.status(), StatusCode::OK);
+ let seen: Value = r.json().await.unwrap();
+ assert_eq!(seen["uri"], format!("/share/{SID}/x"));
+ // Path mode for everything else is still forwarded (and still gated).
+ let r = env
+ .http
+ .get(format!("{}/m/{m}/files?path=/etc/passwd", env.base))
+ .send()
+ .await
+ .unwrap();
+ assert_eq!(r.status(), StatusCode::UNAUTHORIZED);
+ // The directory lists the machine on its own origin.
+ let r: Value = env
+ .http
+ .get(format!("{}/v1/machines/{m}", env.base))
+ .bearer_auth(env.token("ada"))
+ .send()
+ .await
+ .unwrap()
+ .json()
+ .await
+ .unwrap();
+ assert_eq!(r["url"], format!("http://{m}.{DOMAIN}"), "{r}");
+}
+
#[tokio::test]
async fn share_origins_belong_to_the_app_and_resolve_one_machine() {
let env = Env::start(Opts::default()).await;
diff --git a/libs/cua/crates/cua-daemon/src/share_link.rs b/libs/cua/crates/cua-daemon/src/share_link.rs
index c61e779fd6..607cf80c50 100644
--- a/libs/cua/crates/cua-daemon/src/share_link.rs
+++ b/libs/cua/crates/cua-daemon/src/share_link.rs
@@ -1,4 +1,9 @@
//! Where a share's link points: this machine's entry on the cua.ai relay.
+//!
+//! The relay decides the form: with a host domain (hosted relay: `m.cua.sh`,
+//! a domain of its own so shared content never lives under cua.ai) the
+//! directory lists `https://<id>.<domain>` and each share gets its own
+//! origin; without one, links stay in path mode under the relay URL.
use std::path::Path;
use std::sync::Arc;
@@ -181,30 +186,39 @@ mod tests {
#[test]
fn host_mode_gives_each_share_its_own_origin() {
let u = compose_link(
- &format!("https://{ID}.m.relay.cua.ai"),
+ &format!("https://{ID}.m.cua.sh"),
ID,
"aaaa1111bbbb2222",
Access::Private,
);
- assert_eq!(
- u,
- "https://saaaa1111bbbb2222-0123456789abcdef.m.relay.cua.ai/"
- );
+ assert_eq!(u, "https://saaaa1111bbbb2222-0123456789abcdef.m.cua.sh/");
let token = "t".repeat(40);
let p = compose_link(
- &format!("https://{ID}.m.relay.cua.ai"),
+ &format!("https://{ID}.m.cua.sh"),
ID,
&token,
Access::Public,
);
- assert_eq!(
- p,
- format!("https://p{token}-0123456789abcdef.m.relay.cua.ai/")
- );
+ assert_eq!(p, format!("https://p{token}-0123456789abcdef.m.cua.sh/"));
let label = p.trim_start_matches("https://").split('.').next().unwrap();
assert!(label.len() <= 63, "{label}");
}
+ #[test]
+ fn host_mode_follows_whatever_domain_the_relay_lists() {
+ // A self-hosted relay's own domain, and a relay URL with a port.
+ let u = compose_link(
+ &format!("https://{ID}.m.relay.example.com:8443/"),
+ ID,
+ "aaaa1111bbbb2222",
+ Access::Team,
+ );
+ assert_eq!(
+ u,
+ "https://saaaa1111bbbb2222-0123456789abcdef.m.relay.example.com:8443/"
+ );
+ }
+
#[test]
fn path_mode_keeps_the_machine_path() {
let u = compose_link(
diff --git a/libs/cua/crates/cua-host/src/relay.rs b/libs/cua/crates/cua-host/src/relay.rs
index 5b01a9e241..29425605ae 100644
--- a/libs/cua/crates/cua-host/src/relay.rs
+++ b/libs/cua/crates/cua-host/src/relay.rs
@@ -152,7 +152,9 @@ pub struct Machine {
/// Unix seconds of the current session.
#[serde(default)]
pub connected_at: Option<u64>,
- /// `<relay>/m/<id>`: the spacesd URL clients connect to.
+ /// The machine's spacesd URL as the relay lists it: `https://<id>.<host
+ /// domain>` on a relay with a host domain (cua.ai: `m.cua.sh`), else
+ /// `<relay>/m/<id>`. `<relay>/m/<id>` works on the hosted relay too.
#[serde(default)]
pub url: String,
/// Allowlist (owner view only): accounts with full use (editors).
diff --git a/libs/cua/crates/cua-share/src/notices.rs b/libs/cua/crates/cua-share/src/notices.rs
index 47a218fddc..e69bca4ab0 100644
--- a/libs/cua/crates/cua-share/src/notices.rs
+++ b/libs/cua/crates/cua-share/src/notices.rs
@@ -3,7 +3,8 @@
use crate::model::Share;
-/// Shown when the link is in relay path mode.
+/// Shown when a browser cannot open the link: any path-mode link, and a
+/// private or team link (the hosted relay has no browser sign-in yet).
pub const PATH_MODE: &str =
"Browser viewing of private links is coming; this link opens for tools and signed-in devices.";
@@ -16,7 +17,7 @@ pub fn is_path_mode(url: &str) -> bool {
/// The notices for `share`.
pub fn notices(share: &Share) -> Vec<String> {
- if is_path_mode(&share.url) {
+ if is_path_mode(&share.url) || share.access != crate::model::Access::Public {
vec![PATH_MODE.to_string()]
} else {
Vec::new()
@@ -46,13 +47,23 @@ mod tests {
#[test]
fn host_mode_has_no_notices() {
let s = share(
- "https://sabc-1234.share.cua.ai/",
+ "https://pabc-1234.m.cua.sh/",
Access::Public,
Target::Port { port: 1 },
);
assert!(notices(&s).is_empty());
}
+ #[test]
+ fn private_host_mode_links_still_say_browsers_cannot_open_them() {
+ let s = share(
+ "https://sabcd-0123456789ab.m.cua.sh/",
+ Access::Private,
+ Target::Port { port: 1 },
+ );
+ assert_eq!(notices(&s), vec![PATH_MODE.to_string()]);
+ }
+
#[test]
fn path_mode_says_browsers_need_the_host_domain() {
let s = share(