Fix Request's Show instance (#1492)
This commit is contained in:
parent
a975cfc361
commit
cb294aa2b3
2 changed files with 14 additions and 1 deletions
|
@ -78,12 +78,13 @@ instance (Show a, Show b) =>
|
||||||
. showString ", requestAccept = "
|
. showString ", requestAccept = "
|
||||||
. showsPrec 0 (requestAccept req)
|
. showsPrec 0 (requestAccept req)
|
||||||
. showString ", requestHeaders = "
|
. showString ", requestHeaders = "
|
||||||
. showsPrec 0 (redactSensitiveHeader <$> requestHeaders req))
|
. showsPrec 0 (redactSensitiveHeader <$> requestHeaders req)
|
||||||
. showString ", requestHttpVersion = "
|
. showString ", requestHttpVersion = "
|
||||||
. showsPrec 0 (requestHttpVersion req)
|
. showsPrec 0 (requestHttpVersion req)
|
||||||
. showString ", requestMethod = "
|
. showString ", requestMethod = "
|
||||||
. showsPrec 0 (requestMethod req)
|
. showsPrec 0 (requestMethod req)
|
||||||
. showString "}"
|
. showString "}"
|
||||||
|
)
|
||||||
where
|
where
|
||||||
redactSensitiveHeader :: Header -> Header
|
redactSensitiveHeader :: Header -> Header
|
||||||
redactSensitiveHeader ("Authorization", _) = ("Authorization", "<REDACTED>")
|
redactSensitiveHeader ("Authorization", _) = ("Authorization", "<REDACTED>")
|
||||||
|
|
|
@ -10,10 +10,22 @@ import Data.List (isInfixOf)
|
||||||
import Servant.Client.Core.Request
|
import Servant.Client.Core.Request
|
||||||
import Test.Hspec
|
import Test.Hspec
|
||||||
|
|
||||||
|
newtype DataWithRequest = DataWithRequest (RequestF RequestBody ())
|
||||||
|
deriving Show
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
describe "Request" $ do
|
describe "Request" $ do
|
||||||
describe "show" $ do
|
describe "show" $ do
|
||||||
|
it "has parenthesis correctly positioned" $ do
|
||||||
|
let d = DataWithRequest (void defaultRequest)
|
||||||
|
show d `shouldBe` "DataWithRequest (Request {requestPath = ()\
|
||||||
|
\, requestQueryString = fromList []\
|
||||||
|
\, requestBody = Nothing\
|
||||||
|
\, requestAccept = fromList []\
|
||||||
|
\, requestHeaders = fromList []\
|
||||||
|
\, requestHttpVersion = HTTP/1.1\
|
||||||
|
\, requestMethod = \"GET\"})"
|
||||||
it "redacts the authorization header" $ do
|
it "redacts the authorization header" $ do
|
||||||
let request = void $ defaultRequest { requestHeaders = pure ("authorization", "secret") }
|
let request = void $ defaultRequest { requestHeaders = pure ("authorization", "secret") }
|
||||||
isInfixOf "secret" (show request) `shouldBe` False
|
isInfixOf "secret" (show request) `shouldBe` False
|
||||||
|
|
Loading…
Reference in a new issue