@@ -57,21 +57,23 @@ func TestStartStop(t *testing.T) {
5757}
5858
5959func TestRequestApproval_SyncPath (t * testing.T ) {
60- var received WebhookPayload
61- var receivedSig string
6260 secret := "test-secret-123"
61+ payloadCh := make (chan WebhookPayload , 1 )
6362
6463 srv := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
65- receivedSig = r .Header .Get ("X-Sluice-Signature" )
64+ sig : = r .Header .Get ("X-Sluice-Signature" )
6665 body , _ := io .ReadAll (r .Body )
67- _ = json .Unmarshal (body , & received )
66+
67+ var payload WebhookPayload
68+ _ = json .Unmarshal (body , & payload )
69+ payloadCh <- payload
6870
6971 // Verify HMAC signature.
7072 mac := hmac .New (sha256 .New , []byte (secret ))
7173 mac .Write (body )
7274 expectedSig := "sha256=" + hex .EncodeToString (mac .Sum (nil ))
73- if receivedSig != expectedSig {
74- t .Errorf ("signature mismatch: got %s, want %s" , receivedSig , expectedSig )
75+ if sig != expectedSig {
76+ t .Errorf ("signature mismatch: got %s, want %s" , sig , expectedSig )
7577 }
7678
7779 w .Header ().Set ("Content-Type" , "application/json" )
@@ -112,6 +114,9 @@ func TestRequestApproval_SyncPath(t *testing.T) {
112114 if resp != channel .ResponseAllowOnce {
113115 t .Errorf ("got response %v, want %v" , resp , channel .ResponseAllowOnce )
114116 }
117+
118+ // Read the payload that was captured by the handler (no race).
119+ received := <- payloadCh
115120 if received .ID == "" {
116121 t .Error ("webhook did not receive a request ID" )
117122 }
0 commit comments