From aa154846497701cffba97004c743f80d5a345a57 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 5 Dec 2018 19:29:36 -0400 Subject: Made some improvements to value taining, and added some tests. --- stdlib/test/test/lux/control/security/taint.lux | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 stdlib/test/test/lux/control/security/taint.lux (limited to 'stdlib/test') diff --git a/stdlib/test/test/lux/control/security/taint.lux b/stdlib/test/test/lux/control/security/taint.lux new file mode 100644 index 000000000..0b18111ef --- /dev/null +++ b/stdlib/test/test/lux/control/security/taint.lux @@ -0,0 +1,49 @@ +(.module: + [lux #* + [control + [hash (#+ Hash)] + [monad (#+ do)] + [security + ["@" taint]]] + [data + ["." text ("text/." Equivalence) + format]] + [math + ["r" random]]] + lux/test) + +(context: "Taint." + (do @ + [raw (r.ascii 10) + #let [dirty (@.taint raw)]] + ($_ seq + (test "Can clean a tainted value by trusting it." + (text/= raw (@.trust dirty))) + (test "Can validate a tainted value." + (case (@.validate (|>> text.size (n/> 0)) dirty) + (#.Some clean) + (text/= raw clean) + + #.None + false)) + ))) + +(context: "Structures." + (do @ + [#let [duplicate (: (-> Text Text) + (function (_ raw) (format raw raw)))] + raw (r.ascii 10) + #let [check (|>> @.trust (text/= (duplicate raw))) + (^open "@/.") @.Functor + (^open "@/.") @.Apply + (^open "@/.") @.Monad]] + ($_ seq + (test "Can use Functor." + (check (@/map duplicate (@.taint raw)))) + (test "Can use Apply." + (check (@/apply (@/wrap duplicate) (@.taint raw)))) + (test "Can use Monad." + (check (do @.Monad + [dirty (@.taint raw)] + (wrap (duplicate dirty))))) + ))) -- cgit v1.2.3