Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format and add tests #56

Merged
merged 3 commits into from
Apr 21, 2022
Merged

Format and add tests #56

merged 3 commits into from
Apr 21, 2022

Conversation

michivi
Copy link
Contributor

@michivi michivi commented Mar 8, 2022

In anticipation of a new major version with a breaking change (take into account the request's body for the HMAC signature), this PR adds the following:

  • Authentication tests between a servant-hmac-auth client and server
  • Formatting code with Fourmolu for consistency

Comment on lines 186 to 196
unsignedPayload :: Either LBS.ByteString (RequestPayload, Signature)
unsignedPayload = case extractOn isAuthHeader $ rpHeaders signedPayload of
(Nothing, _) -> Left "No 'Authentication' header"
(Just (_, val), headers) -> case BS.stripPrefix "HMAC " val of
Just sig -> Right
( signedPayload { rpHeaders = headers }
, Signature sig
)
Just sig ->
Right
( signedPayload{rpHeaders = headers}
, Signature sig
)
Nothing -> Left "Can not strip 'HMAC' prefix in header"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about the HMAC authentication standard, but I think this code makes the library can not be reused in many cases :

  • The signature is specified in a different header name (such as x-sendbird-signature)
  • The payload is request body or combination of request body with some header content (such as Stripe payload)

So I think it could be better if we can specify the header name of the signature and the function to map from request to singed payload

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like you said, our current implementation of the authentication differs from Sendbird's which also differs from Stripe's. While it would be interesting to be customizable to handle as much use case as possible, I fear that there's too many different use cases out there and we would lose the "simple" aspect of the library.

For example, we could expose the requestSignature function and allow the client to change the actual implementation, but the library may lose most of its usefulness as a consequence.

What's everyone else's opinion on that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed this earlier.
@thongpv87 Just so that I understand your point better :

  • Does it mean that with this change merged into master, that you would have to re-implement or change some existing code in order to be compatible with a future version of servant-hmac-auth?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is essentially formatting and testing so there should be no impact on existing projects.
#57 may be more impactful, but the previous API should be untouched (the tests from this PR are actually testing the previous API and there weren't broken in the #57).

@michivi michivi merged commit 57f8b71 into master Apr 21, 2022
@michivi michivi deleted the tle/hash-request branch April 21, 2022 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants