Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkgs/id/crates/id-core/src/waiting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,10 @@ mod tests {
pool.restore(author(1), 1, [10], "copy", 0).unwrap();
assert!(!pool.contains(&1));
assert_eq!(pool.take_ready(), vec!["ready"]);
assert!(pool.take_ready().is_empty(), "the ready event is taken once");
assert!(
pool.take_ready().is_empty(),
"the ready event is taken once"
);
assert!(pool.arrived(10, 0).is_empty());
assert!(pool.is_empty());
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/id/examples/roc-cap-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ just recipe and flake check) runs:
wrong signature. Compilation must fail with a type mismatch at
that call.

Each negative test pins *why* it fails (asserted error content), not
Each negative test pins _why_ it fails (asserted error content), not
just that it fails.
37 changes: 26 additions & 11 deletions pkgs/id/examples/roc-cap-demo/roc-cap-demo-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ if ! command -v roc >/dev/null 2>&1; then
exit 1
fi

fail() { echo "roc-cap-demo test FAILED: $*" >&2; exit 1; }
fail() {
echo "roc-cap-demo test FAILED: $*" >&2
exit 1
}

echo "=== roc-cap-demo: library expect tests (roc test lib/main.roc) ==="
roc test lib/main.roc
Expand All @@ -38,8 +41,8 @@ roc check main.roc
# the reduced platform (Roc resolves package modules only inside the
# package root, so a symlink out of lib-no-caps/ is not allowed). Keep
# the copy honest: any drift between the two copies fails here.
diff lib/Greeter.roc lib-no-caps/Greeter.roc >/dev/null \
|| fail "lib-no-caps/Greeter.roc has drifted from lib/Greeter.roc; re-copy it"
diff lib/Greeter.roc lib-no-caps/Greeter.roc >/dev/null ||
fail "lib-no-caps/Greeter.roc has drifted from lib/Greeter.roc; re-copy it"

TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
Expand All @@ -48,20 +51,32 @@ echo "=== roc-cap-demo: negative test A (capability not on the platform) ==="
if roc check main-missing-cap.roc >"$TMP/neg-a.log" 2>&1; then
fail "main-missing-cap.roc compiled, but the reduced platform must not satisfy the library"
fi
grep -q "pf.RocCap" "$TMP/neg-a.log" \
|| { cat "$TMP/neg-a.log" >&2; fail "negative A failed, but not over the missing pf.RocCap module"; }
grep -q "does not exist" "$TMP/neg-a.log" \
|| { cat "$TMP/neg-a.log" >&2; fail "negative A failed, but the error does not say pf.RocCap is missing"; }
grep -q "pf.RocCap" "$TMP/neg-a.log" ||
{
cat "$TMP/neg-a.log" >&2
fail "negative A failed, but not over the missing pf.RocCap module"
}
grep -q "does not exist" "$TMP/neg-a.log" ||
{
cat "$TMP/neg-a.log" >&2
fail "negative A failed, but the error does not say pf.RocCap is missing"
}
echo "negative A failed as required: pf.RocCap is not provided by the reduced platform"

echo "=== roc-cap-demo: negative test B (platform used wrong) ==="
if roc check main-wrong-usage.roc >"$TMP/neg-b.log" 2>&1; then
fail "main-wrong-usage.roc compiled, but the wrong-signature capability call must not typecheck"
fi
grep -q "schedule_at_request" "$TMP/neg-b.log" \
|| { cat "$TMP/neg-b.log" >&2; fail "negative B failed, but not at the schedule_at_request call"; }
grep -qi "type mismatch" "$TMP/neg-b.log" \
|| { cat "$TMP/neg-b.log" >&2; fail "negative B failed, but not with a type mismatch"; }
grep -q "schedule_at_request" "$TMP/neg-b.log" ||
{
cat "$TMP/neg-b.log" >&2
fail "negative B failed, but not at the schedule_at_request call"
}
grep -qi "type mismatch" "$TMP/neg-b.log" ||
{
cat "$TMP/neg-b.log" >&2
fail "negative B failed, but not with a type mismatch"
}
echo "negative B failed as required: type mismatch at the schedule_at_request call"

echo "✓ roc-cap-demo tests passed (positive path + both negative tests)"
25 changes: 13 additions & 12 deletions pkgs/id/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ use std::io::{self, Write};
use std::path::Path;
use std::time::Duration;

use anyhow::{bail, ensure, Context, Result};
use anyhow::{Context, Result, bail, ensure};
use ed25519_dalek::{Signature, Signer as _, SigningKey, VerifyingKey};
use iroh::{
Endpoint, EndpointAddr,
endpoint::Connection,
protocol::{AcceptError, ProtocolHandler},
Endpoint, EndpointAddr,
};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use unicode_normalization::is_nfc;

use crate::connectivity::{connect, within, DIAL_TIMEOUT};
use crate::directory::{hex_to_array, normalize_key, Directory, Refusal};
use crate::connectivity::{DIAL_TIMEOUT, connect, within};
use crate::directory::{Directory, Refusal, hex_to_array, normalize_key};
use crate::directory_auth::Caller;
use crate::directory_view::{DirectoryAction, DirectoryOutcome};
use crate::envelope_net::{answer_frames, send, Reply};
use crate::envelope_outbox::{check_target, Outcome};
use crate::envelope_net::{Reply, answer_frames, send};
use crate::envelope_outbox::{Outcome, check_target};
use crate::event_sync::{CLOSE_WAIT, SESSION_DEADLINE};
use crate::frames::{read_frame, write_frame};
use crate::world::hex_encode;
Expand Down Expand Up @@ -1227,11 +1227,11 @@ pub async fn pull_within(
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod tests {
use super::*;
use crate::test_forgeries::{identity_forgery, with_non_canonical_s, IDENTITY_KEY};
use crate::test_forgeries::{IDENTITY_KEY, identity_forgery, with_non_canonical_s};
use iroh::{
endpoint::{presets, RelayMode},
protocol::Router,
TransportAddr,
endpoint::{RelayMode, presets},
protocol::Router,
};
use iroh_base::SecretKey;
use proptest::prelude::*;
Expand Down Expand Up @@ -2328,13 +2328,14 @@ mod tests {
assert!(log.insert(doubled).is_err());

// The builder refuses the same frontier before receipt sees it.
assert!(log
.sign_after(
assert!(
log.sign_after(
&key(1),
&document("second"),
vec![first.hash.clone(), first.hash.clone()],
)
.is_err());
.is_err()
);

let repeated = sign_raw_after(
&key(1),
Expand Down
14 changes: 2 additions & 12 deletions pkgs/id/src/didit/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,7 @@ fn day_count_includes_previous_days_wrapping_span() {
period: Period::Day,
},
));
let at_2am = record(
0x56,
vec![dog_a()],
"outside",
chicago(2026, 6, 16, 2, 0),
);
let at_2am = record(0x56, vec![dog_a()], "outside", chicago(2026, 6, 16, 2, 0));
let now = chicago(2026, 6, 16, 12, 0);

let verdicts = evaluate(&[outside], &[at_2am], now).expect("evaluate");
Expand Down Expand Up @@ -566,12 +561,7 @@ fn week_count_includes_previous_days_wrapping_span() {
period: Period::Week,
},
));
let at_2am = record(
0x58,
vec![dog_a()],
"outside",
chicago(2026, 6, 15, 2, 0),
);
let at_2am = record(0x58, vec![dog_a()], "outside", chicago(2026, 6, 15, 2, 0));
let now = chicago(2026, 6, 15, 12, 0);

let verdicts = evaluate(&[outside], &[at_2am], now).expect("evaluate");
Expand Down
15 changes: 3 additions & 12 deletions pkgs/id/src/seitan/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,26 +374,17 @@ fn parse_rejects_trailing_bytes_after_the_accept_map() {
// A single stray byte.
let mut trailing_byte = bare.clone();
trailing_byte.push(0x00);
assert_eq!(
accept::parse(&trailing_byte),
Err(ProofError::Malformed)
);
assert_eq!(accept::parse(&trailing_byte), Err(ProofError::Malformed));

// A trailing scalar value (msgpack positive fixint 42).
let mut trailing_scalar = bare.clone();
trailing_scalar.push(0x2a);
assert_eq!(
accept::parse(&trailing_scalar),
Err(ProofError::Malformed)
);
assert_eq!(accept::parse(&trailing_scalar), Err(ProofError::Malformed));

// A trailing string value ("hello" as a fixstr).
let mut trailing_string = bare.clone();
trailing_string.extend_from_slice(b"\xa5hello");
assert_eq!(
accept::parse(&trailing_string),
Err(ProofError::Malformed)
);
assert_eq!(accept::parse(&trailing_string), Err(ProofError::Malformed));

// A whole second accept map concatenated after the first.
let mut duplicated = bare.clone();
Expand Down
17 changes: 10 additions & 7 deletions pkgs/id/src/web/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5924,9 +5924,9 @@ mod tests {
let link_text = para_content
.iter()
.find(|n| {
n["marks"].as_array().is_some_and(|m| {
m.iter().any(|mark| mark["type"] == "link")
})
n["marks"]
.as_array()
.is_some_and(|m| m.iter().any(|mark| mark["type"] == "link"))
})
.unwrap_or_else(|| panic!("no link mark for {md}"));
// The link text survives; only the target is neutralized.
Expand Down Expand Up @@ -5964,9 +5964,9 @@ mod tests {
let para_content = doc["content"][0]["content"].as_array().unwrap();
assert!(
para_content.iter().all(|n| {
n["marks"].as_array().is_none_or(|marks| {
marks.iter().all(|mark| mark["type"] != "link")
})
n["marks"]
.as_array()
.is_none_or(|marks| marks.iter().all(|mark| mark["type"] != "link"))
}),
"tab-obfuscated destination produced a link mark: {para_content:?}"
);
Expand All @@ -5979,7 +5979,10 @@ mod tests {
// directions.
for (md, expected_href) in [
("[a](http://example.com)", "http://example.com"),
("[a](https://example.com/x?y=1)", "https://example.com/x?y=1"),
(
"[a](https://example.com/x?y=1)",
"https://example.com/x?y=1",
),
("[a](HTTPS://example.com)", "HTTPS://example.com"),
("[a](mailto:me@example.com)", "mailto:me@example.com"),
("[a](notes.md)", "notes.md"),
Expand Down
14 changes: 12 additions & 2 deletions pkgs/id/src/web/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,12 @@ mod tests {
.await;
assert_eq!(query.status(), StatusCode::SEE_OTHER);
assert_eq!(
query.headers().get(header::LOCATION).unwrap().to_str().unwrap(),
query
.headers()
.get(header::LOCATION)
.unwrap()
.to_str()
.unwrap(),
"/"
);
let set = query
Expand Down Expand Up @@ -556,7 +561,12 @@ mod tests {
assert_eq!(loc, "/page?a=1&b=2");
assert!(!loc.contains("s3cret"));
assert!(!loc.contains("token="));
let set = r.headers().get(header::SET_COOKIE).unwrap().to_str().unwrap();
let set = r
.headers()
.get(header::SET_COOKIE)
.unwrap()
.to_str()
.unwrap();
assert!(set.starts_with("id_token=s3cret"), "{set}");
assert!(set.contains("HttpOnly"));
assert!(set.contains("SameSite=Strict"));
Expand Down
Loading