From 05e140314eab18d37629f146ca1c3c45521793e3 Mon Sep 17 00:00:00 2001 From: Mark Wotton Date: Thu, 21 Apr 2016 17:13:26 -0400 Subject: [PATCH] add example for more complicated api --- servant-client/test/Servant/ClientSpec.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/servant-client/test/Servant/ClientSpec.hs b/servant-client/test/Servant/ClientSpec.hs index c41b4093..bf37d482 100644 --- a/servant-client/test/Servant/ClientSpec.hs +++ b/servant-client/test/Servant/ClientSpec.hs @@ -211,6 +211,15 @@ type GenAuthAPI = genAuthAPI :: Proxy GenAuthAPI genAuthAPI = Proxy +type GenAuthAPI2 = + AuthProtect "auth-tag" :> ("private" :> "auth" :> Get '[JSON] Person + :<|> ("private2" :> "auth" :> Get '[JSON] Person)) + + +genAuthAPI2 :: Proxy GenAuthAPI2 +genAuthAPI2 = Proxy + + type instance AuthServerData (AuthProtect "auth-tag") = () type instance AuthClientData (AuthProtect "auth-tag") = () @@ -385,6 +394,13 @@ genAuthSpec = beforeAll (startWaiApp genAuthServer) $ afterAll endWaiApp $ do let authRequest = mkAuthenticateReq () (\_ req -> SCR.addHeader "AuthHeader" ("cool" :: String) req) (left show <$> runExceptT (getProtected authRequest manager baseUrl)) `shouldReturn` Right alice + it "Also works for more complicated apis" $ \(_, baseUrl) -> do + let (getProtected :<|> getOtherProtected) = client genAuthAPI2 + let authRequest = mkAuthenticateReq () (\_ req -> SCR.addHeader "AuthHeader" ("cool" :: String) req) + (left show <$> runExceptT (getProtected authRequest manager baseUrl)) `shouldReturn` Right alice + + + context "Authentication is rejected when requests are not authenticated properly" $ do it "Authenticates a AuthProtect protected server appropriately" $ \(_, baseUrl) -> do