summaryrefslogtreecommitdiff
path: root/src/Test.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-07-25 20:57:39 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-07-26 21:55:45 +0200
commit1f961a5a882d2626f0c6be28b03d86b8c257a855 (patch)
treebbd7cfd41b82ab1c092ae21220f7a67543b15174 /src/Test.hs
parent6c13b1285605020bb3c510dd1862d2d8d9828337 (diff)
Pairing failure reason
Diffstat (limited to 'src/Test.hs')
-rw-r--r--src/Test.hs35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/Test.hs b/src/Test.hs
index 30aa8c4..19d1a64 100644
--- a/src/Test.hs
+++ b/src/Test.hs
@@ -128,7 +128,7 @@ pairingAttributes _ out peers prefix = PairingAttributes
index <- show <$> getPeerIndex peers
liftIO $ outLine out $ unwords [prefix ++ "-request", index, confirm]
- , pairingHookRequestNonceFailed = failed
+ , pairingHookRequestNonceFailed = failed "nonce"
, pairingHookConfirmedResponse = return ()
, pairingHookConfirmedRequest = return ()
@@ -141,13 +141,16 @@ pairingAttributes _ out peers prefix = PairingAttributes
index <- show <$> getPeerIndex peers
liftIO $ outLine out $ unwords [prefix ++ "-request-done", index]
- , pairingHookFailed = failed
- , pairingHookVerifyFailed = failed
- , pairingHookRejected = failed
+ , pairingHookFailed = \case
+ PairingUserRejected -> failed "user"
+ PairingUnexpectedMessage pstate packet -> failed $ "unexpected " ++ strState pstate ++ " " ++ strPacket packet
+ PairingFailedOther str -> failed $ "other " ++ str
+ , pairingHookVerifyFailed = failed "verify"
+ , pairingHookRejected = failed "rejected"
}
where
- failed :: PairingResult a => ServiceHandler (PairingService a) ()
- failed = do
+ failed :: PairingResult a => String -> ServiceHandler (PairingService a) ()
+ failed detail = do
ptype <- svcGet >>= return . \case
OurRequest {} -> "response"
OurRequestConfirm {} -> "response"
@@ -157,7 +160,25 @@ pairingAttributes _ out peers prefix = PairingAttributes
_ -> fail "unexpected pairing state"
index <- show <$> getPeerIndex peers
- liftIO $ outLine out $ prefix ++ "-" ++ ptype ++ "-failed " ++ index
+ liftIO $ outLine out $ prefix ++ "-" ++ ptype ++ "-failed " ++ index ++ " " ++ detail
+
+ strState :: PairingState a -> String
+ strState = \case
+ NoPairing -> "none"
+ OurRequest {} -> "our-request"
+ OurRequestConfirm {} -> "our-request-confirm"
+ OurRequestReady -> "our-request-ready"
+ PeerRequest {} -> "peer-request"
+ PeerRequestConfirm -> "peer-request-confirm"
+ PairingDone -> "done"
+
+ strPacket :: PairingService a -> String
+ strPacket = \case
+ PairingRequest {} -> "request"
+ PairingResponse {} -> "response"
+ PairingRequestNonce {} -> "nonce"
+ PairingAccept {} -> "accept"
+ PairingReject -> "reject"
newtype CommandM a = CommandM (ReaderT TestInput (StateT TestState (ExceptT String IO)) a)