Skip to content

Commit

Permalink
test: added schema to hash-masked-password and fixed test
Browse files Browse the repository at this point in the history
  • Loading branch information
clauxx committed Nov 22, 2023
1 parent 024ff0f commit cc81673
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 19 additions & 4 deletions src/utils/security/core.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns utils.security.core
(:require
[native-module.core :as native-module]
[schema.core :as schema]
[utils.security.security-html :as h]))

(defprotocol Unmaskable
Expand Down Expand Up @@ -60,7 +61,21 @@
[text]
(not (re-matches rtlo-link-regex text)))

(def hash-masked-password
(comp mask-data
native-module/sha3
safe-unmask-data))
(defn hash-masked-password
[masked-password]
(-> masked-password
safe-unmask-data
native-module/sha3
mask-data))

(defn masked-data-instance?
[value]
(instance? MaskedData value))

(schema/=> hash-masked-password
[:=>
[:cat
[:fn {:error/message "argument should be an instance of MaskedData"}
masked-data-instance?]]
[:fn {:error/message "return value should be an instance of MaskedData"}
masked-data-instance?]])
5 changes: 2 additions & 3 deletions src/utils/security/security_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,5 @@
(testing "returns an instance of MaskedData with the hashed content"
(is (= (-> "test" native-module/sha3 security/mask-data)
(-> "test" security/mask-data security/hash-masked-password))))
(testing "returns the hashed content if the argument is not a MaskedData instance"
(is (= (native-module/sha3 "test")
(-> "test" security/hash-masked-password security/safe-unmask-data)))))
(testing "throws a schema exception if the argument is not an instance of MaskedData"
(is (thrown? js/Error (security/hash-masked-password "test")))))

0 comments on commit cc81673

Please sign in to comment.