Skip to content

Commit 3c9af80

Browse files
authored
Merge pull request #1154 from mhcurylo/ClientSpec_split
ClientSpec split into multiple modules
2 parents 7263809 + a91cde1 commit 3c9af80

File tree

11 files changed

+771
-519
lines changed

11 files changed

+771
-519
lines changed

servant-client/servant-client.cabal

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,15 @@ test-suite spec
8989
hs-source-dirs: test
9090
main-is: Spec.hs
9191
other-modules:
92-
Servant.ClientSpec
92+
Servant.BasicAuthSpec
93+
Servant.ClientTestUtils
94+
Servant.ConnectionErrorSpec
95+
Servant.FailSpec
96+
Servant.GenAuthSpec
97+
Servant.HoistClientSpec
9398
Servant.StreamSpec
99+
Servant.SuccessSpec
100+
Servant.WrappedApiSpec
94101

95102
-- Dependencies inherited from the library. No need to specify bounds.
96103
build-depends:
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE ConstraintKinds #-}
3+
{-# LANGUAGE DataKinds #-}
4+
{-# LANGUAGE FlexibleContexts #-}
5+
{-# LANGUAGE FlexibleInstances #-}
6+
{-# LANGUAGE GADTs #-}
7+
{-# LANGUAGE MultiParamTypeClasses #-}
8+
{-# LANGUAGE OverloadedStrings #-}
9+
{-# LANGUAGE PolyKinds #-}
10+
{-# LANGUAGE ScopedTypeVariables #-}
11+
{-# LANGUAGE TypeFamilies #-}
12+
{-# LANGUAGE TypeOperators #-}
13+
{-# LANGUAGE UndecidableInstances #-}
14+
{-# OPTIONS_GHC -freduction-depth=100 #-}
15+
{-# OPTIONS_GHC -fno-warn-orphans #-}
16+
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
17+
18+
module Servant.BasicAuthSpec (spec) where
19+
20+
import Prelude ()
21+
import Prelude.Compat
22+
23+
import Control.Arrow
24+
(left)
25+
import Data.Monoid ()
26+
import qualified Network.HTTP.Types as HTTP
27+
import Test.Hspec
28+
29+
import Servant.API
30+
(BasicAuthData (..))
31+
import Servant.Client
32+
import Servant.ClientTestUtils
33+
34+
spec :: Spec
35+
spec = describe "Servant.BasicAuthSpec" $ do
36+
basicAuthSpec
37+
38+
basicAuthSpec :: Spec
39+
basicAuthSpec = beforeAll (startWaiApp basicAuthServer) $ afterAll endWaiApp $ do
40+
context "Authentication works when requests are properly authenticated" $ do
41+
42+
it "Authenticates a BasicAuth protected server appropriately" $ \(_,baseUrl) -> do
43+
let getBasic = client basicAuthAPI
44+
let basicAuthData = BasicAuthData "servant" "server"
45+
left show <$> runClient (getBasic basicAuthData) baseUrl `shouldReturn` Right alice
46+
47+
context "Authentication is rejected when requests are not authenticated properly" $ do
48+
49+
it "Authenticates a BasicAuth protected server appropriately" $ \(_,baseUrl) -> do
50+
let getBasic = client basicAuthAPI
51+
let basicAuthData = BasicAuthData "not" "password"
52+
Left (FailureResponse _ r) <- runClient (getBasic basicAuthData) baseUrl
53+
responseStatusCode r `shouldBe` HTTP.Status 403 "Forbidden"

0 commit comments

Comments
 (0)