haskell-servant / haskell-servant/servant
Client function hangs without an error
- Dominant language
- Haskell
- Stars
- 2k
- Forks
- 427
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 5
Description
I am working on a simple Servant server using `AuthProtect` and JWTs. The server works, I can successfully use all the endpoints with `curl`. However, when trying to create client functions to use in the tests, the functions for the `ManagedAPI` just hang. No error is reported, the server logs don't record the endpoint being accessed.
Here are the (I think) relevant bits:
```haskell
type AuthJwt = AuthProtect "jwt-auth"
type instance AuthServerData AuthJwt = AuthenticatedUser
type instance Auth.AuthClientData AuthJwt = Token
type PublicAPI =
"status" :> Description "Provide server status" :> Get '[JSON] ServerStatus
type ManagedAPI =
AuthJwt
:> "register"
:> Description "Create a user"
:> ReqBody '[JSON] RegisterPayload
:> PostAccepted '[JSON] RegisterResponse
:<|> AuthJwt
:> "login"
:> Description "Log in with existing user"
:> ReqBody '[JSON] LoginPayload
:> Post
'[JSON]
(Headers '[SA.Header "Authorization" T.Text] LoginResponse)
:<|> AuthJwt
:> "tokentest"
:> Description "Test JWT auth"
:> Get '[JSON] TestPayload
type API =
PublicAPI
:<|> ManagedAPI
api :: Proxy API
api = Proxy
clientAuth
:: Token -> Auth.AuthenticatedRequest AuthJwt
clientAuth token = Auth.mkAuthenticatedRequest token addAuthHeader
addAuthHeader :: Token -> R.Request -> R.Request
addAuthHeader t r = R.addHeader "Authorization" ("Bearer " <> t) r
checkStatus :: ClientM ServerStatus
registerUser
:: Auth.AuthenticatedRequest AuthJwt -> RegisterPayload -> ClientM RegisterResponse
loginUser
:: Auth.AuthenticatedRequest AuthJwt
-> LoginPayload
-> ClientM (Headers '[SA.Header "Authorization" T.Text] LoginResponse)
testToken :: Auth.AuthenticatedRequest AuthJwt -> ClientM TestPayload
checkStatus :<|> (registerUser :<|> loginUser :<|> testToken) = client api
```
Here, I test with `anonToken`, a JWT I created manually for the guest user:
```
ghci> runClientM checkStatus clientEnv
Right (ServerStatus {ss_version = "0.1.0.0"})
ghci> runClientM (loginUser (clientAuth anonToken) (LoginPayload "user1@mail.com" "pass1")) clientEnv
^C^CInterrupted.
```
I suspect it may be something surrounding the `clientAuth` function, but it typechecks and compiles, so I don't know what the issue is.
Contributor guide
Assessment
This issue has not been assessed yet.