diff --git a/src/utils/security/core.cljs b/src/utils/security/core.cljs index 66eb87ed53a6..c254c59e0744 100644 --- a/src/utils/security/core.cljs +++ b/src/utils/security/core.cljs @@ -61,6 +61,6 @@ (not (re-matches rtlo-link-regex text))) (def hash-masked-password - (comp safe-unmask-data + (comp mask-data native-module/sha3 - mask-data)) + safe-unmask-data)) diff --git a/src/utils/security/security_test.cljs b/src/utils/security/security_test.cljs index 3e8c2a51f65a..dcd4c76f96d0 100644 --- a/src/utils/security/security_test.cljs +++ b/src/utils/security/security_test.cljs @@ -1,6 +1,7 @@ (ns utils.security.security-test (:require [cljs.test :refer-macros [deftest is testing]] + [native-module.core :as native-module] [utils.security.core :as security])) (def rtlo-link "‮http://google.com") @@ -29,3 +30,27 @@ (deftest safe-link-text-test-exceptions (testing "rtlo links" (is (not (security/safe-link-text? rtlo-link-text))))) + +(deftest mask-data-test + (testing "returns an instance of MaskedData" + (is (instance? security/MaskedData (security/mask-data "test")))) + (testing "hides the original value" + (is (= "******" (str (security/mask-data "test"))))) + (testing "succeeds the equality check between same MaskedData instances" + (is (= (security/mask-data "value") (security/mask-data "value")))) + (testing "fails the equality check between different MaskedData instances" + (is (not (= (security/mask-data "value-A") (security/mask-data "value-B"))))) + (testing "fails the equality check with non-MaskedData instances" + (is (not (= (security/mask-data "value") "value")))) + (testing "counts the masked data correctly" + (is (= (count "test") (count (security/mask-data "test"))))) + (testing "unmasks the data correctly" + (is (= "test" (-> "test" security/mask-data security/safe-unmask-data))))) + +(deftest hash-masked-password-test + (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)))))