Skip to content

Commit

Permalink
TestHandleApiRequest: use POST unsubscribe
Browse files Browse the repository at this point in the history
This is in preparation for allowing only POST unsubscribe requests.

The handler logic doesn't care what HTTP method is used to unsubscribe,
which is why this test change didn't require any code changes. The
/unsubscribe HTTP method is enforced by the CloudFormation template.

Still, it's good for the test input to closely resemble what's expected
from the configured API Gateway, even if it doesn't affect the handler
logic.

I mean, I could add logic to enforce the expected HTTP method for each
API endpoint. Maybe that's not a bad idea. However, it will have to come
after updating the system to point {{UnsubscribeUrl}} at a page with a
web form.

That, in fact, is why I'm diving into making sure `@` is encoded as
`%40` and thinking of eliminating GET /unsubscribe. I accidentally
unsubscribed myself by clicking on the unsubscribe link in an email.
Updating {{UnsubscribeUrl}} to point to a form will allow the user to
make sure they really intend to unsubscribe. This POST /unsubscribe will
be less error prone while also being more semantically correct. (I think
technically /verify should also be a POST, but it seems conventional to
have such links always use GET.)
  • Loading branch information
mbland committed Jul 6, 2023
1 parent 9493ab2 commit 890afc9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions handler/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ func TestHandleApiRequest(t *testing.T) {
Id: "deadbeef",
RawPath: ops.ApiPrefixUnsubscribe + "mbland%40acm.org/" +
testValidUidStr,
Method: http.MethodGet,
ContentType: "text/plain",
Method: http.MethodPost,
ContentType: "application/x-www-form-urlencoded",
Params: map[string]string{
"email": "mbland@acm.org",
"email": "mbland%40acm.org",
"uid": testValidUidStr,
},
}
Expand Down

0 comments on commit 890afc9

Please sign in to comment.