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 = "
|
||||
. showsPrec 0 (requestAccept req)
|
||||
. showString ", requestHeaders = "
|
||||
. showsPrec 0 (redactSensitiveHeader <$> requestHeaders req))
|
||||
. showsPrec 0 (redactSensitiveHeader <$> requestHeaders req)
|
||||
. showString ", requestHttpVersion = "
|
||||
. showsPrec 0 (requestHttpVersion req)
|
||||
. showString ", requestMethod = "
|
||||
. showsPrec 0 (requestMethod req)
|
||||
. showString "}"
|
||||
)
|
||||
where
|
||||
redactSensitiveHeader :: Header -> Header
|
||||
redactSensitiveHeader ("Authorization", _) = ("Authorization", "<REDACTED>")
|
||||
|
|
|
@ -10,10 +10,22 @@ import Data.List (isInfixOf)
|
|||
import Servant.Client.Core.Request
|
||||
import Test.Hspec
|
||||
|
||||
newtype DataWithRequest = DataWithRequest (RequestF RequestBody ())
|
||||
deriving Show
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
describe "Request" $ 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
|
||||
let request = void $ defaultRequest { requestHeaders = pure ("authorization", "secret") }
|
||||
isInfixOf "secret" (show request) `shouldBe` False
|
||||
|
|
Loading…
Reference in a new issue