summaryrefslogtreecommitdiff
path: root/sid_test.ml
diff options
context:
space:
mode:
authorPhilipp Gesang <phg@phi-gamma.net>2018-11-06 21:34:30 +0100
committerPhilipp Gesang <phg@phi-gamma.net>2018-11-06 21:37:02 +0100
commitec08b71fb47b82402f0fbb8859a2445519f79615 (patch)
treee0c5cefc8f2f62feb345ea9330633f91676b9a6b /sid_test.ml
parentdd55d557c61965d985e2f6f771bc7308e613aea8 (diff)
downloadocaml-sid-ec08b71fb47b82402f0fbb8859a2445519f79615.tar.gz
sid: sid_test: validate identifier authority on create()
Reject ia’s greater than six bytes can encompass.
Diffstat (limited to 'sid_test.ml')
-rw-r--r--sid_test.ml20
1 files changed, 18 insertions, 2 deletions
diff --git a/sid_test.ml b/sid_test.ml
index 97af2a3..9b61b40 100644
--- a/sid_test.ml
+++ b/sid_test.ml
@@ -31,12 +31,21 @@ let create_ok () =
(Printf.sprintf "[%s] ≠ [%s]" (Sid.to_string s) (Sid.to_string w))
(Sid.equal s w)
-let create_fail () =
+let create_etoomany_fail () =
let sas = Array.make 16 U32.one in
match Sid.create ~sa:sas U64.zero with
| None -> ()
| Some s -> assert_failure ("Sid.create succeeded on invalid sa array")
+let max_ident_auth = U64.of_string "0x0000_ffff_ffff_ffff"
+
+let create_iatoobig_fail () =
+ let sas = Array.make 2 U32.one in
+ let ia = U64.add max_ident_auth U64.one in
+ match Sid.create ~sa:sas ia with
+ | None -> ()
+ | Some s -> assert_failure ("Sid.create succeeded on invalid ident auth")
+
let unwrap_of_string s =
match Sid.of_string s with
| Error e ->
@@ -345,7 +354,14 @@ let packet_rep_test = "packet-rep" >:::
; "decode-odd-fail" >:: pr_decode_odd_fail
]
+let toplevel_test = "toplevel" >:::
+ [ "create-ok" >:: create_ok
+ ; "create-etoomany-fail" >:: create_etoomany_fail
+ ; "create-iatoobig-fail" >:: create_iatoobig_fail
+ ]
+
let () =
ignore (run_test_tt_main string_format_test);
- ignore (run_test_tt_main packet_rep_test )
+ ignore (run_test_tt_main packet_rep_test );
+ ignore (run_test_tt_main toplevel_test )