diff options
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))))) + ))) |