@@ -30,6 +30,7 @@ import Network.HTTP.Types (Status (..), hAccept, hContentType,
3030 methodDelete, methodGet,
3131 methodHead, methodPatch,
3232 methodPost, methodPut, ok200,
33+ imATeaPot418,
3334 parseQuery)
3435import Network.Wai (Application, Request, requestHeaders, pathInfo,
3536 queryString, rawQueryString,
@@ -542,13 +543,17 @@ miscCombinatorSpec = with (return $ serve miscApi miscServ) $
542543-- * Basic Authentication {{{
543544------------------------------------------------------------------------------
544545
545−type BasicAuthAPI = BasicAuth "foo" () :> "basic" :> Get '[JSON] Animal
546+type BasicAuthAPI =
547+ BasicAuth "foo" () :> "basic" :> Get '[JSON] Animal
548+ :<|> Raw
546549
547550basicAuthApi :: Proxy BasicAuthAPI
548551basicAuthApi = Proxy
549552
550553basicAuthServer :: Server BasicAuthAPI
551−basicAuthServer = const (return jerry)
554+basicAuthServer =
555+ const (return jerry) :<|>
556+ (\ _ respond -> respond $ responseLBS imATeaPot418 [] "")
552557
553558basicAuthContext :: Context '[ BasicAuthCheck () ]
554559basicAuthContext =
@@ -564,14 +569,22 @@ basicAuthSpec = do
564569 with (return (serveWithContext basicAuthApi basicAuthContext basicAuthServer)) $ do
565570
566571 context "Basic Authentication" $ do
567− it "returns 401 with bad password" $ do
572+ it "returns 401 when no credentials given" $ do
568573 get "/basic" `shouldRespondWith` 401
569574
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
579+
570580 it "returns 200 with the right password" $ do
571581 let validCredentials = [("Authorization", "Basic c2VydmFudDpzZXJ2ZXI=")]
572582 THW.request methodGet "/basic" validCredentials ""
573583 `shouldRespondWith` 200
574584
585+ it "plays nice with subsequent Raw endpoints" $ do
586+ get "/foo" `shouldRespondWith` 418
587+
575588-- }}}
576589------------------------------------------------------------------------------
577590-- * General Authentication {{{