Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions pkg/detectors/pagerdutyapikey/pagerdutyapikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pagerdutyapikey
import (
"context"
"fmt"
"io"
"net/http"
"strings"

Expand Down Expand Up @@ -84,6 +85,20 @@ func verifyPagerdutyapikey(ctx context.Context, client *http.Client, token strin
switch res.StatusCode {
case http.StatusOK:
return true, nil
case http.StatusForbidden:
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
return false, err
}
bodyStr := string(bodyBytes)

// 403 with "Access Denied" and "2010" means valid credentials with insufficient permissions.
// Ref: https://developer.pagerduty.com/docs/errors
if strings.Contains(bodyStr, "Access Denied") && strings.Contains(bodyStr, "2010") {
return true, nil
}

return false, fmt.Errorf("response status forbidden 403: %s", bodyStr)
case http.StatusUnauthorized:
return false, nil
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestPagerDutyApiKey_FromChunk(t *testing.T) {
t.Errorf("PagerDutyApiKey.FromData() verificationError = %v, wantVerificationErr %v", got[i].VerificationError(), tt.wantVerificationErr)
}
}
ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "verificationError")
ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "verificationError", "primarySecret")
if diff := cmp.Diff(got, tt.want, ignoreOpts); diff != "" {
t.Errorf("PagerDutyApiKey.FromData() %s diff: (-got +want)\n%s", tt.name, diff)
}
Expand Down