aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / crates / allen-reflex-kernel / tests / route_card.rs
| 1 | //! Route card parser (aienos#399): what the image accepts, and that the card cannot carry |
| 2 | //! capabilities or expected answers. |
| 3 | use allen_reflex_kernel::card::{self, Kind}; |
| 4 | |
| 5 | fn card(lines: &str) -> Vec<u8> { |
| 6 | format!("AIENALR1 QUALIF-ALLEN-ROUTE\n{lines}").into_bytes() |
| 7 | } |
| 8 | |
| 9 | #[test] |
| 10 | fn accepts_owner_guest_flags_and_escapes() { |
| 11 | let b = card("R1|owner:7|C|<u> what can you do?\nR2|guest:9|-|<u> tell me my notes\nR3|owner:1|PC|<u> approve it%2C please\n"); |
| 12 | assert_eq!(card::kind(&b), Some(Kind::Route)); |
| 13 | let r = card::parse_route(&b).unwrap(); |
| 14 | assert_eq!(r.len(), 3); |
| 15 | assert!(r[0].owner && r[0].consent && !r[0].pending && r[0].session == 7); |
| 16 | assert!(!r[1].owner && !r[1].consent && !r[1].pending); |
| 17 | assert!(r[2].consent && r[2].pending); |
| 18 | } |
| 19 | |
| 20 | #[test] |
| 21 | fn refuses_malformed_lines() { |
| 22 | for bad in [ |
| 23 | "R1|admin:1|-|<u> hi\n", // unknown speaker |
| 24 | "R1|owner:0|-|<u> hi\n", // session 0 |
| 25 | "R1|owner:1234567890|-|<u> hi\n", // session too long |
| 26 | "R1|owner:1|X|<u> hi\n", // unknown flag (e.g. a capability claim) |
| 27 | "R1|owner:1|CC|<u> hi\n", // repeated flag |
| 28 | "R1|owner:1||<u> hi\n", // empty flags |
| 29 | "R1|owner:1|-|\n", // empty turns |
| 30 | "R1|owner:1|<u> hi\n", // missing field |
| 31 | "R1|owner:1|-|<u> hi\nR1|guest:1|-|<u> hi\n", // duplicate id |
| 32 | ] { |
| 33 | assert!(card::parse_route(&card(bad)).is_err(), "accepted: {bad}"); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | #[test] |
| 38 | fn kinds_do_not_mix() { |
| 39 | let exam = b"AIENALX1 QUALIF-ALLEN-EXAM\nX1|<u> hi\n".to_vec(); |
| 40 | assert_eq!(card::kind(&exam), Some(Kind::Exam)); |
| 41 | assert!(card::parse_route(&exam).is_err()); |
| 42 | assert!(card::parse(&card("R1|owner:1|-|<u> hi\n")).is_err()); |
| 43 | assert_eq!(card::kind(b"AIENALR1 QUALIF-ALLEN-ROUTEX\n"), None); |
| 44 | } |