diff options
author | Eduardo Julian | 2018-12-05 19:29:36 -0400 |
---|---|---|
committer | Eduardo Julian | 2018-12-05 19:29:36 -0400 |
commit | aa154846497701cffba97004c743f80d5a345a57 (patch) | |
tree | ec2d122adc15831bf5cf012ad45c494ab47a6692 /stdlib/test | |
parent | dd1eaeed77b536950e4b6bdf3ce44237e19cb275 (diff) |
Made some improvements to value taining, and added some tests.
Diffstat (limited to '')
-rw-r--r-- | stdlib/test/test/lux/control/security/taint.lux | 49 |
1 files changed, 49 insertions, 0 deletions
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<Text>) + 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<Dirty> + (^open "@/.") @.Apply<Dirty> + (^open "@/.") @.Monad<Dirty>]] + ($_ 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> + [dirty (@.taint raw)] + (wrap (duplicate dirty))))) + ))) |