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
32 changes: 22 additions & 10 deletions pkgs/id/crates/id-core/src/sanctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,13 @@ pub fn find_matches(
let mut matches = Vec::new();
for entry in &list.entries {
let basis = match entry {
SanctionsEntry::Country { code } => {
subject_country.filter(|c| *c == code).map(|_| MatchBasis::StrongIdentifier)
}
SanctionsEntry::Country { code } => subject_country
.filter(|c| *c == code)
.map(|_| MatchBasis::StrongIdentifier),
SanctionsEntry::Entity { native_id, names }
| SanctionsEntry::Person { native_id, names, .. } => {
| SanctionsEntry::Person {
native_id, names, ..
} => {
if subject_native_ids.contains(native_id) {
Some(MatchBasis::StrongIdentifier)
} else if names.iter().any(|n| subject_names.contains(n)) {
Expand Down Expand Up @@ -366,9 +368,11 @@ pub fn evaluate(
}
// The strongest match decides; entry keys are compared so the
// recorded entry is deterministic for a given match set.
let strongest = matches
.iter()
.max_by(|a, b| a.basis.cmp(&b.basis).then_with(|| a.entry_key.cmp(&b.entry_key)));
let strongest = matches.iter().max_by(|a, b| {
a.basis
.cmp(&b.basis)
.then_with(|| a.entry_key.cmp(&b.entry_key))
});
let Some(m) = strongest else {
return record(DecisionOutcome::Allow, None, None);
};
Expand Down Expand Up @@ -482,7 +486,13 @@ mod tests {
// references the exact list version applied.
let l = list(7, vec![SanctionsEntry::Country { code: "CU".into() }]);
let m = find_matches(&l, Some("CU"), &BTreeSet::new(), &BTreeSet::new());
let d = evaluate(&boundary(), &l, EnforcementPoint::AccountCreation, &m, false);
let d = evaluate(
&boundary(),
&l,
EnforcementPoint::AccountCreation,
&m,
false,
);
assert_eq!(d.outcome, DecisionOutcome::Deny);
assert_eq!(
d.appeal_path.as_deref(),
Expand Down Expand Up @@ -546,8 +556,10 @@ mod tests {
assert_eq!(d.outcome, DecisionOutcome::Cleared);
assert_eq!(d.list.version, 3);
// No prior match: nothing to clear.
assert!(cleared_by_removal(&boundary(), &current, EnforcementPoint::Login, false, &[])
.is_none());
assert!(
cleared_by_removal(&boundary(), &current, EnforcementPoint::Login, false, &[])
.is_none()
);
}

#[test]
Expand Down
13 changes: 4 additions & 9 deletions pkgs/id/crates/id-core/src/world_caps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,9 +1732,8 @@ mod tests {
// to collapse to no arguments in every handler, silently
// widening records.read to every record.
for bad in ["42", "\"text\"", "[1,2]", "true"] {
let doc = format!(
r#"{{"requests":[{{"id":"r1","cap":"records.read","args":{bad}}}]}}"#
);
let doc =
format!(r#"{{"requests":[{{"id":"r1","cap":"records.read","args":{bad}}}]}}"#);
let error = parse_wants(&doc).unwrap_err();
assert!(
format!("{error:#}").contains("args must be a JSON object"),
Expand All @@ -1743,17 +1742,13 @@ mod tests {
}
// Absent args and args:null behave exactly as before.
parse_wants(r#"{"requests":[{"id":"r1","cap":"records.read"}]}"#).unwrap();
parse_wants(r#"{"requests":[{"id":"r1","cap":"records.read","args":null}]}"#)
.unwrap();
parse_wants(r#"{"requests":[{"id":"r1","cap":"records.read","args":null}]}"#).unwrap();
// An object args is carried through unchanged.
let wants = parse_wants(
r#"{"requests":[{"id":"r1","cap":"records.read","args":{"prefix":"co"}}]}"#,
)
.unwrap();
assert_eq!(
wants.requests[0].args,
serde_json::json!({"prefix": "co"})
);
assert_eq!(wants.requests[0].args, serde_json::json!({"prefix": "co"}));
}

#[test]
Expand Down
6 changes: 5 additions & 1 deletion pkgs/id/crates/id-core/tests/probe_petname_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ fn probe_open_replays_names_set_would_refuse() {
.map(|(a, n)| (a.to_string(), n.to_string()))
.collect();
println!("LOADED: {loaded:?}");
assert_eq!(loaded.len(), 4, "all four refused-at-write records loaded verbatim");
assert_eq!(
loaded.len(),
4,
"all four refused-at-write records loaded verbatim"
);
assert!(store.get("me", "acct-b") == Some("paypal"));
assert!(store.get("me", "acct-c").unwrap().contains('\u{200b}'));
}
50 changes: 26 additions & 24 deletions pkgs/id/src/boards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ use std::io::{self, Write};

use anyhow::{Context, Result, bail, ensure};
use ed25519_dalek::{SigningKey, VerifyingKey};
use sha2::{Digest, Sha256};
use serde::{Deserialize, Deserializer, Serialize, de};
use sha2::{Digest, Sha256};

use crate::artifact::SignedArtifact;

Expand Down Expand Up @@ -849,7 +849,10 @@ impl BoardGraph {
"a game challenge cannot be accepted by the game post author"
);
ensure!(
post_body.participants.iter().any(|participant| participant.author == author),
post_body
.participants
.iter()
.any(|participant| participant.author == author),
"a game challenge can be accepted only by an assigned participant"
);
}
Expand Down Expand Up @@ -878,10 +881,7 @@ impl BoardGraph {
"game turns require a signed challenge acceptance first"
);
match &value.prev_turn {
None => ensure!(
value.turn_index == 0,
"an opening game turn has index 0"
),
None => ensure!(value.turn_index == 0, "an opening game turn has index 0"),
Some(previous) => {
let previous_object =
self.require_scoped(previous, &value.board, "game_turn")?;
Expand Down Expand Up @@ -1293,8 +1293,10 @@ impl BoardGraph {
"the game has no signed challenge acceptance"
);
let lineage = self.game_lineage(game_post, head)?;
let sandbox =
crate::sandbox::Sandbox::compile(package_bytes, crate::sandbox::SandboxLimits::default())?;
let sandbox = crate::sandbox::Sandbox::compile(
package_bytes,
crate::sandbox::SandboxLimits::default(),
)?;
// The package's own initial state: the one state the
// signed-turn schedule (participants by turn index, from 0)
// is defined from.
Expand Down Expand Up @@ -1466,16 +1468,16 @@ impl BoardGraph {
BoardObject::GameTurn(body) => {
let mut dependencies = vec![body.board.clone(), body.game_post.clone()];
dependencies.extend(body.prev_turn.iter().cloned());
dependencies.extend(self.objects.iter().filter_map(
|(hash, signed)| match &signed.object {
dependencies.extend(self.objects.iter().filter_map(|(hash, signed)| {
match &signed.object {
BoardObject::GameChallengeAcceptance(acceptance)
if acceptance.game_post == body.game_post =>
{
Some(hash.clone())
}
_ => None,
},
));
}
}));
dependencies
}
};
Expand Down Expand Up @@ -4218,8 +4220,7 @@ mod tests {
}
}

const TIC_TAC_TOE_WASM: &[u8] =
include_bytes!("../apps/tic-tac-toe/program/tic-tac-toe.wasm");
const TIC_TAC_TOE_WASM: &[u8] = include_bytes!("../apps/tic-tac-toe/program/tic-tac-toe.wasm");

fn game_acceptance_object(
key: &SigningKey,
Expand Down Expand Up @@ -4542,7 +4543,11 @@ mod tests {
let mut graph = BoardGraph::default();
let root_hash = graph.insert(board(&creator)).unwrap();
let game_hash = graph
.insert(wasm_game_post_object(&creator, &opponent, root_hash.clone()))
.insert(wasm_game_post_object(
&creator,
&opponent,
root_hash.clone(),
))
.unwrap();

// Replay refuses a game with no signed challenge acceptance.
Expand Down Expand Up @@ -4605,13 +4610,10 @@ mod tests {
);
}


/// Build a wasm tic-tac-toe graph with an accepted challenge and
/// one alternating lineage over `actions` (even indices are X,
/// odd are O), returning the graph, the game hash, and the head.
fn wasm_game_lineage(
actions: &[&str],
) -> (BoardGraph, ArtifactHash, ArtifactHash) {
fn wasm_game_lineage(actions: &[&str]) -> (BoardGraph, ArtifactHash, ArtifactHash) {
wasm_game_lineage_with_genesis(actions, "---------")
}

Expand Down Expand Up @@ -4691,8 +4693,7 @@ mod tests {

// A turn signed after the game is already won is ignored by
// the package and must not extend the replayed lineage.
let (graph, game_hash, head) =
wasm_game_lineage(&["0", "4", "1", "3", "2", "5"]);
let (graph, game_hash, head) = wasm_game_lineage(&["0", "4", "1", "3", "2", "5"]);
assert!(
graph
.replay_game_lineage(&game_hash, &head, TIC_TAC_TOE_WASM)
Expand Down Expand Up @@ -4823,9 +4824,10 @@ mod tests {
[0, 4, 8],
[2, 4, 6],
];
won = lines
.iter()
.any(|line| line.iter().all(|&i| board[i] == board[line[0]] && board[i] != b'-'));
won = lines.iter().any(|line| {
line.iter()
.all(|&i| board[i] == board[line[0]] && board[i] != b'-')
});
}
Ok(String::from_utf8(board.to_vec()).unwrap())
}
Expand Down
3 changes: 1 addition & 2 deletions pkgs/id/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ pub use groups::{DelegateArgs, GroupCommand, GroupRemoveMode, GroupTemplate, Rev
#[cfg(feature = "sandbox")]
pub use match_audit::MatchAuditCommand;
pub use tag::TagCommand;
pub use writer_sets::WriterSetCommand;
pub use world::{
WorldApplyArgs, WorldCapsArgs, WorldCommand, WorldCompileArgs, WorldCrossWorldWriteArgs,
WorldDiffArgs, WorldDoctorArgs, WorldDownloadArgs, WorldFileScopeArgs,
Expand All @@ -122,6 +121,7 @@ pub use world::{
WorldProfileArgs, WorldRecordArgs, WorldRecordsArgs, WorldReplayArgs, WorldRuntimeArgs,
WorldSshTunnelArgs, WorldStatsArgs, WorldVerifyArgs, WorldVia,
};
pub use writer_sets::WriterSetCommand;

/// The main CLI structure for the `id` peer-to-peer file sharing tool.
///
Expand Down Expand Up @@ -1568,4 +1568,3 @@ mod tests;
#[cfg(all(test, feature = "world"))]
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod world_limits_args_tests;

Loading
Loading