@@ -30,6 +30,7 @@ import Network.HTTP.Types (Status (..), hAccept, hContentType,
30 methodDelete, methodGet,
30 methodDelete, methodGet,
31 methodHead, methodPatch,
31 methodHead, methodPatch,
32 methodPost, methodPut, ok200,
32 methodPost, methodPut, ok200,
33 parseQuery)
34 parseQuery)
34import Network.Wai (Application, Request, requestHeaders, pathInfo,
35import Network.Wai (Application, Request, requestHeaders, pathInfo,
35 queryString, rawQueryString,
36 queryString, rawQueryString,
@@ -542,13 +543,17 @@ miscCombinatorSpec = with (return $ serve miscApi miscServ) $
542-- * Basic Authentication {{{
543-- * Basic Authentication {{{
543------------------------------------------------------------------------------
544------------------------------------------------------------------------------
545−type BasicAuthAPI = BasicAuth "foo" () :> "basic" :> Get '[JSON] Animal
547+ BasicAuth "foo" () :> "basic" :> Get '[JSON] Animal
547basicAuthApi :: Proxy BasicAuthAPI
550basicAuthApi :: Proxy BasicAuthAPI
548basicAuthApi = Proxy
551basicAuthApi = Proxy
550basicAuthServer :: Server BasicAuthAPI
553basicAuthServer :: Server BasicAuthAPI
551−basicAuthServer = const (return jerry)
555+ const (return jerry) :<|>
556+ (\ _ respond -> respond $ responseLBS imATeaPot418 [] "")
553basicAuthContext :: Context '[ BasicAuthCheck () ]
558basicAuthContext :: Context '[ BasicAuthCheck () ]
554basicAuthContext =
559basicAuthContext =
@@ -564,14 +569,22 @@ basicAuthSpec = do
564 with (return (serveWithContext basicAuthApi basicAuthContext basicAuthServer)) $ do
569 with (return (serveWithContext basicAuthApi basicAuthContext basicAuthServer)) $ do
566 context "Basic Authentication" $ do
571 context "Basic Authentication" $ do
567− it "returns 401 with bad password" $ do
572+ it "returns 401 when no credentials given" $ do
568 get "/basic" `shouldRespondWith` 401
573 get "/basic" `shouldRespondWith` 401
575+ it "returns 403 when invalid credentials given" $ do
576+ let invalid = [("Authorization", "Basic bbbbbbbbbDpzZXJ2ZXI=")] -- fixme: how do I create basic auth tokens?
577+ THW.request methodGet "/basic" invalid ""
578+ `shouldRespondWith` 403
570 it "returns 200 with the right password" $ do
580 it "returns 200 with the right password" $ do
571 let validCredentials = [("Authorization", "Basic c2VydmFudDpzZXJ2ZXI=")]
581 let validCredentials = [("Authorization", "Basic c2VydmFudDpzZXJ2ZXI=")]
572 THW.request methodGet "/basic" validCredentials ""
582 THW.request methodGet "/basic" validCredentials ""
573 `shouldRespondWith` 200
583 `shouldRespondWith` 200
585+ it "plays nice with subsequent Raw endpoints" $ do
586+ get "/foo" `shouldRespondWith` 418
576------------------------------------------------------------------------------
589------------------------------------------------------------------------------
577-- * General Authentication {{{
590-- * General Authentication {{{