Move credential ceremonies into the world web UI and ignore proxy environment

This commit is contained in:
2026-11-12 06:57:34 +00:00
parent e0c2d8bc8b
commit a74ebd11ba
22 changed files with 209 additions and 356 deletions
+11 -26
View File
@@ -49,14 +49,11 @@ async fn page(api: &Api, path: &str) -> Result<String> {
http::Request::builder().uri(path).body(Bytes::new())?,
)
.await;
assert_eq!(response.status(), 200);
assert_eq!(
response.headers()["content-type"],
"text/html; charset=utf-8"
);
assert_eq!(response.status(), 404);
assert_eq!(response.headers()["content-type"], "application/json");
let text = std::str::from_utf8(response.body())?;
assert!(!text.contains(SECRET));
assert!(text.contains("app.js"));
assert!(text.contains("route_missing"));
Ok(text.into())
}
fn item(cred: &Cred, name: &str) -> Result<cred::items::Item> {
@@ -161,11 +158,9 @@ async fn approvals_registration_and_revocation() -> Result<()> {
let id = file(&api, &second.id, "approval").await?;
let other = file(&api, &second.id, "other").await?;
let path = format!("/cred/requests/{id}");
let review = page(&api, &format!("/approve/{id}")).await?;
assert!(review.contains("data-grant=\"true\""));
assert!(review.contains("value=\"300\""));
assert!(review.contains("&lt;script&gt;not markup&lt;/script&gt;"));
assert!(!review.contains("<script>not markup</script>"));
page(&api, &format!("/approve/{id}")).await?;
let review = ok(&api, "GET", &path, json!({})).await?;
assert_eq!(review["payload"]["duration_secs"], 300);
assert_ne!(
send(
&api,
@@ -268,9 +263,7 @@ async fn approvals_registration_and_revocation() -> Result<()> {
assert!(api.cred.grant_status(&grant.id)?.revoked);
let edit = ok(&api,"POST","/cred/requests",json!({"kind":"edit","key":"rename","request":{"item":second.id,"base_version":api.cred.item_get(&second.id)?.version,"change":[{"op":"set_name","name":"renamed"}]}})).await?;
let edit = edit["request"].as_str().unwrap();
let edit_page = page(&api, &format!("/approve/{edit}")).await?;
assert!(edit_page.contains("data-grant=\"false\""));
assert!(edit_page.contains("<fieldset hidden disabled>"));
page(&api, &format!("/approve/{edit}")).await?;
let edit_gate = assertion(
&api,
&mut auth,
@@ -314,16 +307,9 @@ async fn approvals_registration_and_revocation() -> Result<()> {
Ok(())
}
async fn encrypt(api: &Api, public_key: Value) -> Result<Envelope> {
async fn encrypt(_api: &Api, public_key: Value) -> Result<Envelope> {
use deno_core::{JsRuntime, RuntimeOptions};
let script = handle(
api,
caller(),
http::Request::builder().uri("/app.js").body(Bytes::new())?,
)
.await;
assert_eq!(script.status(), 200);
assert!(!std::str::from_utf8(script.body())?.contains(SECRET));
let script = include_str!("../../../userland/web/credentials.js");
let mut runtime = JsRuntime::new(RuntimeOptions {
extensions: vec![
deno_webidl::deno_webidl::init(),
@@ -340,8 +326,7 @@ async fn encrypt(api: &Api, public_key: Value) -> Result<Envelope> {
runtime.execute_script("browser.js","globalThis.crypto = Deno.core.loadExtScript('ext:deno_crypto/00_crypto.js').crypto; globalThis.TextEncoder = Deno.core.loadExtScript('ext:deno_web/08_text_encoding.js').TextEncoder; globalThis.document = {querySelector: () => ({addEventListener() {}})};")?;
runtime.execute_script(
"app.js",
std::str::from_utf8(script.body())?
.replace("import.meta.url", "'http://localhost:8080/api/app.js'"),
script,
)?;
runtime.execute_script("encrypt.js",format!("globalThis.done = encrypt({public_key},'{SECRET}').then(result => globalThis.envelope = JSON.stringify(result.envelope));"))?;
runtime.run_event_loop(Default::default()).await?;
@@ -372,7 +357,7 @@ async fn encrypted_entry_uses_the_host_page_code() -> Result<()> {
&format!("/entry/{}/{}", item.id, item.fields[0].field_id),
)
.await?;
assert!(entry_page.contains(&public["public_key"].to_string()));
assert!(!entry_page.contains(&public["public_key"].to_string()));
let envelope = encrypt(&api, public["public_key"].clone()).await?;
let path = format!("/cred/items/{}/fields/{}", item.id, item.fields[0].field_id);
for target in [