aboutsummaryrefslogtreecommitdiff
path: root/stdlib/test
diff options
context:
space:
mode:
authorEduardo Julian2018-12-05 19:29:36 -0400
committerEduardo Julian2018-12-05 19:29:36 -0400
commitaa154846497701cffba97004c743f80d5a345a57 (patch)
treeec2d122adc15831bf5cf012ad45c494ab47a6692 /stdlib/test
parentdd1eaeed77b536950e4b6bdf3ce44237e19cb275 (diff)
Made some improvements to value taining, and added some tests.
Diffstat (limited to '')
-rw-r--r--stdlib/test/test/lux/control/security/taint.lux49
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)))))
+ )))