2024-05-26 15:34:09 +02:00
|
|
|
import Test.Hspec
|
|
|
|
import qualified Crypto as Cr
|
2024-05-26 16:50:04 +02:00
|
|
|
import Data.ByteString.UTF8 (fromString)
|
2024-05-26 16:35:15 +02:00
|
|
|
import qualified Utils as Ut
|
2024-05-26 15:34:09 +02:00
|
|
|
|
2024-05-22 18:37:36 +02:00
|
|
|
main :: IO ()
|
2024-05-26 15:34:09 +02:00
|
|
|
main = hspec $ do
|
2024-05-26 16:50:04 +02:00
|
|
|
describe "Crypto Encryption & Decryption" $ do
|
2024-05-26 15:34:09 +02:00
|
|
|
it "should encrypt and decrypt a message correctly" $ do
|
|
|
|
let originalMessage = "Hello, World!"
|
|
|
|
masterPassword = "mysecretpassword"
|
|
|
|
encryptedMessage = Cr.encrypt' masterPassword originalMessage
|
|
|
|
decryptedMessage = Cr.decrypt' masterPassword encryptedMessage
|
|
|
|
decryptedMessage `shouldBe` originalMessage
|
2024-05-26 16:35:15 +02:00
|
|
|
|
2024-05-26 16:50:04 +02:00
|
|
|
describe "Crypto Hash Identical" $ do
|
|
|
|
it "should hash identical ByteString's to the same output" $ do
|
|
|
|
let input1 = "Hello, World!"
|
|
|
|
input2 = "Hello, World!"
|
|
|
|
hash1 = Cr.hash' $ fromString input1
|
|
|
|
hash2 = Cr.hash' $ fromString input2
|
|
|
|
hash1 `shouldBe` hash2
|
|
|
|
|
|
|
|
describe "Crypto Hash Different" $ do
|
|
|
|
it "should hash different ByteString's to different output" $ do
|
|
|
|
let input1 = "Hello, World!"
|
|
|
|
input2 = "Hello, World"
|
|
|
|
hash1 = Cr.hash' $ fromString input1
|
|
|
|
hash2 = Cr.hash' $ fromString input2
|
|
|
|
hash1 `shouldNotBe` hash2
|
|
|
|
|
2024-05-26 16:35:15 +02:00
|
|
|
describe "Utils Valid password" $ do
|
|
|
|
it "should result in Valid for master password validation with valid input" $ do
|
|
|
|
let password1 = "mysecretpassword"
|
|
|
|
password2 = "mysecretpassword"
|
|
|
|
result = Ut.validate_password password1 password2
|
|
|
|
result `shouldBe` Ut.Valid password1
|
|
|
|
|
|
|
|
describe "Utils DoNotMatch password" $ do
|
|
|
|
it "should result in DoNotMatch for master password validation with non-matching input" $ do
|
|
|
|
let password1 = "mysecretpassword"
|
|
|
|
password2 = "nonmatchingpassword"
|
|
|
|
result = Ut.validate_password password1 password2
|
|
|
|
result `shouldBe` Ut.DoNotMatch
|
|
|
|
|
|
|
|
describe "Utils Empty password" $ do
|
|
|
|
it "should result in Empty for master password validation with empty input" $ do
|
|
|
|
let password1 = ""
|
|
|
|
password2 = ""
|
|
|
|
result = Ut.validate_password password1 password2
|
|
|
|
result `shouldBe` Ut.Empty
|
|
|
|
|
|
|
|
describe "Utils TooShort password" $ do
|
|
|
|
it "should result in TooShort for master password validation with too short input" $ do
|
|
|
|
let password1 = "short"
|
|
|
|
password2 = "short"
|
|
|
|
result = Ut.validate_password password1 password2
|
|
|
|
result `shouldBe` Ut.TooShort
|