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.

fix(cua-compat): build Basic auth test headers at runtime (#6639)

injaneity3d9c9828ee44
diff --git a/libs/cua/crates/cua-compat/src/e2b/mod.rs b/libs/cua/crates/cua-compat/src/e2b/mod.rs
index 80e76df0ef..ab556ebe83 100644
--- a/libs/cua/crates/cua-compat/src/e2b/mod.rs
+++ b/libs/cua/crates/cua-compat/src/e2b/mod.rs
@@ -553,7 +553,12 @@ mod tests {
fn reads_the_basic_auth_user() {
let mut h = HeaderMap::new();
assert_eq!(request_user(&h, "user"), "user");
- h.insert(header::AUTHORIZATION, "Basic cm9vdDo=".parse().unwrap()); // "root:"
+ use base64::Engine;
+ let basic = base64::engine::general_purpose::STANDARD.encode("root:");
+ h.insert(
+ header::AUTHORIZATION,
+ format!("Basic {basic}").parse().unwrap(),
+ );
assert_eq!(request_user(&h, "user"), "root");
}
}
diff --git a/libs/cua/crates/cua-compat/tests/gateway.rs b/libs/cua/crates/cua-compat/tests/gateway.rs
index 8d0638f5b7..3fcf1334c1 100644
--- a/libs/cua/crates/cua-compat/tests/gateway.rs
+++ b/libs/cua/crates/cua-compat/tests/gateway.rs
@@ -16,6 +16,14 @@ struct Gw {
_dir: tempfile::TempDir,
}
+/// An `Authorization: Basic` value for `user:pass`, built at runtime so no
+/// encoded credential sits in the source.
+fn basic_auth(user: &str, pass: &str) -> String {
+ use base64::Engine;
+ let token = base64::engine::general_purpose::STANDARD.encode(format!("{user}:{pass}"));
+ format!("Basic {token}")
+}
+
async fn start(ports: &[(u16, String)]) -> Gw {
let dir = tempfile::tempdir().unwrap();
let backend = Arc::new(MockBackend::new());
@@ -236,18 +244,16 @@ async fn a_root_command_names_root_to_an_agent_that_switches_users() {
// The mock agent is not root and switches users by capability (as the
// Linux image's `cua` agent does): a command sent without a user runs
// as the agent, so `root` must be named.
- use base64::Engine;
let g = start(&[]).await;
let sb = g.sandbox(json!({"templateID": "base"})).await;
let body = envelope(&json!({
"process": {"cmd": "/bin/bash", "args": ["-l", "-c", "echo hi"], "envs": {}},
"stdin": false
}));
- let basic = base64::engine::general_purpose::STANDARD.encode("root:");
let r = g
.envd(&sb, "process.Process/Start")
.header("content-type", "application/connect+json")
- .header("authorization", format!("Basic {basic}"))
+ .header("authorization", basic_auth("root", ""))
.body(body)
.send()
.await
@@ -272,7 +278,6 @@ async fn a_root_command_runs_as_root_on_a_non_root_agent() {
use base64::Engine;
let g = start(&[]).await;
let sb = g.sandbox(json!({"templateID": "base"})).await;
- let basic = base64::engine::general_purpose::STANDARD.encode("root:");
let mut seen = Vec::new();
for line in ["whoami", "id -u", "printf %s \"$HOME\""] {
let body = envelope(&json!({
@@ -282,7 +287,7 @@ async fn a_root_command_runs_as_root_on_a_non_root_agent() {
let r = g
.envd(&sb, "process.Process/Start")
.header("content-type", "application/connect+json")
- .header("authorization", format!("Basic {basic}"))
+ .header("authorization", basic_auth("root", ""))
.body(body)
.send()
.await
@@ -1095,7 +1100,7 @@ async fn root_file_calls_name_root_to_an_agent_that_switches_users() {
let call = |method: &str, body: Value| {
g.envd(&sb, &format!("filesystem.Filesystem/{method}"))
.header("content-type", "application/json")
- .header("authorization", "Basic cm9vdDo=")
+ .header("authorization", basic_auth("root", ""))
.body(body.to_string())
.send()
};
@@ -1157,7 +1162,7 @@ async fn native_file_calls_give_what_they_make_to_the_user() {
let r = g
.envd(&sb, &format!("filesystem.Filesystem/{method}"))
.header("content-type", "application/json")
- .header("authorization", "Basic YWxpY2U6")
+ .header("authorization", basic_auth("alice", ""))
.body(body.to_string())
.send()
.await