--- GET confirmation page behavior --- TestMagicLinkGETDoesNotExecute is the core security property of the split GET/POST design: an email-client URL scanner that previews the approve link must not trigger the send.
(t *testing.T)
| 118 | // split GET/POST design: an email-client URL scanner that previews the |
| 119 | // approve link must not trigger the send. |
| 120 | func TestMagicLinkGETDoesNotExecute(t *testing.T) { |
| 121 | server, store, signer, smtpDone := setupMagicLinkAPI(t) |
| 122 | a, userID := prepareHITLAgent(t, store, "get-no-execute") |
| 123 | msg := issuePending(t, store, a.ID) |
| 124 | |
| 125 | tok, _ := signer.Sign(msg.ID, approvaltoken.ActionApprove, time.Now().Add(1*time.Hour)) |
| 126 | resp, err := http.Get(server.URL + "/v1/approve?t=" + url.QueryEscape(tok)) |
| 127 | if err != nil { |
| 128 | t.Fatal(err) |
| 129 | } |
| 130 | if resp.StatusCode != http.StatusOK { |
| 131 | t.Fatalf("GET confirm page: status = %d", resp.StatusCode) |
| 132 | } |
| 133 | |
| 134 | // No SMTP activity at all — we only rendered a confirmation page. |
| 135 | if msgs := smtpDone(); len(msgs) != 0 { |
| 136 | t.Errorf("GET should not have triggered a send; got %d SMTP messages", len(msgs)) |
| 137 | } |
| 138 | |
| 139 | // Row stays pending. |
| 140 | got, _ := store.GetOutboundMessageForUser(context.Background(), msg.ID, userID) |
| 141 | if got.Status != identity.MessageStatusPendingReview { |
| 142 | t.Errorf("status after GET = %q, want still pending_approval", got.Status) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // TestMagicApproveGETRendersConfirmForm verifies the confirmation page |
| 147 | // contains a POST form with the token carried in a hidden field, plus |
nothing calls this directly
no test coverage detected