From 20d17eef898d342ef62812d2b74b590e73cc1180 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Fri, 29 Apr 2016 02:49:31 -0400 Subject: function to parse Triple-Field Specs --- testkiki/testkiki.hs | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) (limited to 'testkiki') diff --git a/testkiki/testkiki.hs b/testkiki/testkiki.hs index c8b141b..d588336 100644 --- a/testkiki/testkiki.hs +++ b/testkiki/testkiki.hs @@ -29,6 +29,7 @@ import System.IO.Unsafe (unsafePerformIO) import ProcessUtils import Data.Bool import Data.Char +import KeyRing #if !MIN_VERSION_base(4,7,0) setEnv k v = System.Posix.Env.setEnv k v True @@ -80,6 +81,134 @@ didFirstEportSecret = unsafePerformIO $ newIORef False doTests :: TestKikiSettings -> IO () doTests tkConfig = hspec $ do + describe "parseSpec3" $ do + it "succeeds as expected" $ do + let resultOf x = (x,parseSpec3 Nothing x) + rslt y x = (x, parseSpec3 (Just y) x) + let typ = Just KeyTypeField + user = Just UserIDField + circ = Just GroupIDField + resultOf "u:joe//fp:4abf30" + `shouldBe` ("u:joe//fp:4abf30",Right (SubstringMatch user "joe",AnyMatch, FingerprintMatch "4abf30")) + resultOf "t:tor" + `shouldBe` ("t:tor",Right (AnyMatch, AnyMatch, SubstringMatch typ "tor")) + resultOf "u:joe" + `shouldBe` ("u:joe",Right (AnyMatch, SubstringMatch user "joe", AnyMatch )) + resultOf "u:joe/" + `shouldBe` ("u:joe/",Right (AnyMatch, SubstringMatch user "joe", AnyMatch )) + resultOf "fp:4A39F/tor" + `shouldBe` ("fp:4A39F/tor",Right (AnyMatch, FingerprintMatch "4A39F", SubstringMatch typ "tor")) + resultOf "u:joe/tor" + `shouldBe` ("u:joe/tor",Right (AnyMatch, SubstringMatch user "joe", SubstringMatch typ "tor")) + resultOf "u:joe/t:tor" + `shouldBe` ("u:joe/t:tor",Right (AnyMatch, SubstringMatch user "joe", SubstringMatch typ "tor")) + resultOf "u:joe/fp:4abf30" + `shouldBe` ("u:joe/fp:4abf30",Right (AnyMatch, SubstringMatch user "joe", FingerprintMatch "4abf30")) + resultOf "joe/tor" + `shouldBe` ("joe/tor",Right (AnyMatch, SubstringMatch user "joe", SubstringMatch typ "tor")) + resultOf "c:buds//fp:4abf3" + `shouldBe` ("c:buds//fp:4abf3",Right (SubstringMatch circ "buds", AnyMatch, FingerprintMatch "4abf3" )) + + it "succeeds as expected, with context: UserIDField" $ do + let resultOf x = (x,parseSpec3 Nothing x) + rslt y x = (x, parseSpec3 (Just y) x) + let typ = Just KeyTypeField + user = Just UserIDField + circ = Just GroupIDField + rslt UserIDField "t:tor" + `shouldBe` ("t:tor",Right (AnyMatch, SubstringMatch typ "tor", AnyMatch )) + rslt UserIDField "u:joe" + `shouldBe` ("u:joe",Right (AnyMatch, SubstringMatch user "joe", AnyMatch )) + rslt UserIDField "u:joe/" + `shouldBe` ("u:joe/",Right (AnyMatch, SubstringMatch user "joe", AnyMatch )) + rslt UserIDField "fp:4A39F/tor" + `shouldBe` ("fp:4A39F/tor",Right (AnyMatch, FingerprintMatch "4A39F", SubstringMatch typ "tor")) + rslt UserIDField "u:joe/tor" + `shouldBe` ("u:joe/tor",Right (AnyMatch, SubstringMatch user "joe", SubstringMatch typ "tor")) + rslt UserIDField "u:joe/t:tor" + `shouldBe` ("u:joe/t:tor",Right (AnyMatch, SubstringMatch user "joe", SubstringMatch typ "tor")) + rslt UserIDField "u:joe/fp:4abf30" + `shouldBe` ("u:joe/fp:4abf30",Right (AnyMatch, SubstringMatch user "joe", FingerprintMatch "4abf30")) + rslt UserIDField "joe/tor" + `shouldBe` ("joe/tor",Right (AnyMatch, SubstringMatch user "joe", SubstringMatch typ "tor")) + + it "succeeds as expected, with context: GroupIDField" $ do + let resultOf x = (x,parseSpec3 Nothing x) + rslt y x = (x, parseSpec3 (Just y) x) + let typ = Just KeyTypeField + user = Just UserIDField + circ = Just GroupIDField + rslt GroupIDField "u:joe//fp:4abf30" + `shouldBe` ("u:joe//fp:4abf30",Right (SubstringMatch user "joe",AnyMatch, FingerprintMatch "4abf30")) + rslt GroupIDField "t:tor" + `shouldBe` ("t:tor",Right (SubstringMatch typ "tor", AnyMatch, AnyMatch)) + rslt GroupIDField "u:joe" + `shouldBe` ("u:joe",Right (SubstringMatch user "joe", AnyMatch, AnyMatch )) + rslt GroupIDField "u:joe/" + `shouldBe` ("u:joe/",Right (SubstringMatch user "joe", AnyMatch, AnyMatch )) + rslt GroupIDField "fp:4A39F/tor" + `shouldBe` ("fp:4A39F/tor",Right (FingerprintMatch "4A39F", AnyMatch, SubstringMatch typ "tor")) + rslt GroupIDField "u:joe/tor" + `shouldBe` ("u:joe/tor",Right (SubstringMatch user "joe", AnyMatch, SubstringMatch typ "tor")) + rslt GroupIDField "u:joe/t:tor" + `shouldBe` ("u:joe/t:tor",Right (SubstringMatch user "joe", AnyMatch, SubstringMatch typ "tor")) + rslt GroupIDField "u:joe/fp:4abf30" + `shouldBe` ("u:joe/fp:4abf30",Right (SubstringMatch user "joe", AnyMatch, FingerprintMatch "4abf30")) + rslt GroupIDField "joe/tor" + `shouldBe` ("joe/tor",Right (SubstringMatch user "joe",AnyMatch, SubstringMatch typ "tor")) + rslt GroupIDField "c:buds//fp:4abf3" + `shouldBe` ("c:buds//fp:4abf3",Right (SubstringMatch circ "buds", AnyMatch, FingerprintMatch "4abf3" )) + + it "succeeds as expected, with context: KeyTypeField" $ do + let resultOf x = (x,parseSpec3 Nothing x) + rslt y x = (x, parseSpec3 (Just y) x) + let typ = Just KeyTypeField + user = Just UserIDField + circ = Just GroupIDField + rslt KeyTypeField "t:tor" + `shouldBe` ("t:tor",Right (AnyMatch, AnyMatch, SubstringMatch typ "tor")) + rslt KeyTypeField "u:joe" + `shouldBe` ("u:joe",Right (AnyMatch, AnyMatch, SubstringMatch user "joe" )) + rslt KeyTypeField "u:joe/" + `shouldBe` ("u:joe/",Right (AnyMatch, AnyMatch, SubstringMatch user "joe" )) + rslt KeyTypeField "fp:4A39F/tor" + `shouldBe` ("fp:4A39F/tor",Right (AnyMatch, FingerprintMatch "4A39F", SubstringMatch typ "tor")) + rslt KeyTypeField "u:joe/tor" + `shouldBe` ("u:joe/tor",Right (AnyMatch, SubstringMatch user "joe", SubstringMatch typ "tor")) + rslt KeyTypeField "u:joe/t:tor" + `shouldBe` ("u:joe/t:tor",Right (AnyMatch, SubstringMatch user "joe", SubstringMatch typ "tor")) + rslt KeyTypeField "u:joe/fp:4abf30" + `shouldBe` ("u:joe/fp:4abf30",Right (AnyMatch, SubstringMatch user "joe", FingerprintMatch "4abf30")) + rslt KeyTypeField "joe/tor" + `shouldBe` ("joe/tor",Right (AnyMatch, SubstringMatch user "joe", SubstringMatch typ "tor")) + + + it "fails as expected" $ do + let resultOf x = (x,parseSpec3 Nothing x) + rslt y x = (x, parseSpec3 (Just y) x) + let typ = Just KeyTypeField + user = Just UserIDField + circ = Just GroupIDField + -- TODO: Should be error: + resultOf "//c:buds" + `shouldBe` ("//c:buds", + (Left $ SpecEMissMatch "buds" (Just GroupIDField) KeyTypeField)) + resultOf "/c:buds/" + `shouldBe` ("/c:buds/", + (Left $ SpecEMissMatch "buds" (Just GroupIDField) UserIDField)) + rslt UserIDField "c:buds//fp:4abf3" + `shouldBe` ("c:buds//fp:4abf3", + (Left . SpecETooBig) (SubstringMatch (Just GroupIDField) "buds",AnyMatch, FingerprintMatch "4abf3")) + rslt UserIDField "u:joe//fp:4abf30" + `shouldBe` ("u:joe//fp:4abf30", + (Left . SpecETooBig) (SubstringMatch (Just UserIDField) "joe",AnyMatch, FingerprintMatch "4abf30")) + rslt KeyTypeField "u:joe//fp:4abf30" + `shouldBe` ("u:joe//fp:4abf30", + Left (SpecETooBig (SubstringMatch user "joe",AnyMatch, FingerprintMatch "4abf30"))) + rslt KeyTypeField "c:buds//fp:4abf3" + `shouldBe` ("c:buds//fp:4abf3", + (Left . SpecETooBig) (SubstringMatch circ "buds", AnyMatch, FingerprintMatch "4abf3" )) + {- -- Example of shouldThrow describe "TODO: error" $ -- cgit v1.2.3