Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: Add two new Secret Scanning API endpoints#3687
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f97ab6d895f1523a24cda52ce83a9908a2d25437f3317ee253ba69ca4aa75c66f7860ec7213dc1d091ff6606dd4399ec39a4badd13ccea73d92b8d27dfdcfd82cb264cfa6d5e71aa241be5f36dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -616,3 +616,128 @@ func TestSecretScanningAlertUpdateOptions_Marshal(t *testing.T) { | ||
| testJSONMarshal(t, u, want) | ||
| } | ||
| func TestSecretScanningService_CreatePushProtectionBypass(t *testing.T) { | ||
Not-Dhananjay-Mishra marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| t.Parallel() | ||
| client, mux, _ := setup(t) | ||
| owner := "o" | ||
| repo := "r" | ||
| mux.HandleFunc(fmt.Sprintf("/repos/%v/%v/secret-scanning/push-protection-bypasses", owner, repo), func(w http.ResponseWriter, r *http.Request) { | ||
| testMethod(t, r, "POST") | ||
| var v *PushProtectionBypassRequest | ||
| assertNilError(t, json.NewDecoder(r.Body).Decode(&v)) | ||
| want := &PushProtectionBypassRequest{Reason: "valid reason", PlaceholderID: "bypass-123"} | ||
| if !cmp.Equal(v, want) { | ||
| t.Errorf("Request body = %+v, want %+v", v, want) | ||
| } | ||
| fmt.Fprint(w, `{ | ||
| "reason": "valid reason", | ||
| "expire_at": "2018-01-01T00:00:00Z", | ||
| "token_type": "github_token" | ||
| }`) | ||
| }) | ||
| ctx := t.Context() | ||
| opts := PushProtectionBypassRequest{Reason: "valid reason", PlaceholderID: "bypass-123"} | ||
| bypass, _, err := client.SecretScanning.CreatePushProtectionBypass(ctx, owner, repo, opts) | ||
| if err != nil { | ||
| t.Errorf("SecretScanning.CreatePushProtectionBypass returned error: %v", err) | ||
| } | ||
| expireTime := Timestamp{time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)} | ||
| want := &PushProtectionBypass{ | ||
| Reason: "valid reason", | ||
| ExpireAt: &expireTime, | ||
| TokenType: "github_token", | ||
| } | ||
| if !cmp.Equal(bypass, want) { | ||
| t.Errorf("SecretScanning.CreatePushProtectionBypass returned %+v, want %+v", bypass, want) | ||
| } | ||
| const methodName = "CreatePushProtectionBypass" | ||
| testBadOptions(t, methodName, func() (err error) { | ||
| _, _, err = client.SecretScanning.CreatePushProtectionBypass(ctx, "\n", "\n", opts) | ||
| return err | ||
| }) | ||
| testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
| _, resp, err := client.SecretScanning.CreatePushProtectionBypass(ctx, "o", "r", opts) | ||
| return resp, err | ||
| }) | ||
| } | ||
| func TestSecretScanningService_GetScanHistory(t *testing.T) { | ||
| t.Parallel() | ||
| client, mux, _ := setup(t) | ||
| owner := "o" | ||
| repo := "r" | ||
| mux.HandleFunc(fmt.Sprintf("/repos/%v/%v/secret-scanning/scan-history", owner, repo), func(w http.ResponseWriter, r *http.Request) { | ||
| testMethod(t, r, "GET") | ||
| fmt.Fprint(w, `{ | ||
| "incremental_scans": [ | ||
| { | ||
| "type": "incremental", | ||
| "status": "success", | ||
| "completed_at": "2025-07-29T10:00:00Z", | ||
| "started_at": "2025-07-29T09:55:00Z" | ||
| } | ||
| ], | ||
| "backfill_scans": [], | ||
| "pattern_update_scans": [], | ||
| "custom_pattern_backfill_scans": [ | ||
| { | ||
| "type": "custom_backfill", | ||
| "status": "in_progress", | ||
| "completed_at": null, | ||
| "started_at": "2025-07-29T09:00:00Z", | ||
| "pattern_slug": "my-custom-pattern", | ||
| "pattern_scope": "organization" | ||
| } | ||
| ] | ||
| }`) | ||
| }) | ||
| ctx := t.Context() | ||
| history, _, err := client.SecretScanning.GetScanHistory(ctx, owner, repo) | ||
| if err != nil { | ||
| t.Errorf("SecretScanning.GetScanHistory returned error: %v", err) | ||
| } | ||
| incrementalScanStartAt := Timestamp{time.Date(2025, time.July, 29, 9, 55, 0, 0, time.UTC)} | ||
| incrementalScancompleteAt := Timestamp{time.Date(2025, time.July, 29, 10, 0, 0, 0, time.UTC)} | ||
| customPatternBackfillScanStartedAt := Timestamp{time.Date(2025, time.July, 29, 9, 0, 0, 0, time.UTC)} | ||
| want := &SecretScanningScanHistory{ | ||
| IncrementalScans: []*SecretsScan{ | ||
| {Type: "incremental", Status: "success", CompletedAt: &incrementalScancompleteAt, StartedAt: &incrementalScanStartAt}, | ||
| }, | ||
| BackfillScans: []*SecretsScan{}, | ||
| PatternUpdateScans: []*SecretsScan{}, | ||
| CustomPatternBackfillScans: []*CustomPatternBackfillScan{ | ||
| { | ||
| SecretsScan: SecretsScan{Type: "custom_backfill", Status: "in_progress", CompletedAt: nil, StartedAt: &customPatternBackfillScanStartedAt}, | ||
| PatternSlug: Ptr("my-custom-pattern"), | ||
| PatternScope: Ptr("organization"), | ||
| }, | ||
| }, | ||
| } | ||
| if !cmp.Equal(history, want) { | ||
| t.Errorf("SecretScanning.GetScanHistory returned %+v, want %+v", history, want) | ||
| } | ||
| const methodName = "GetScanHistory" | ||
| testBadOptions(t, methodName, func() (err error) { | ||
| _, _, err = client.SecretScanning.GetScanHistory(ctx, "\n", "\n") | ||
| return err | ||
| }) | ||
| testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { | ||
| _, resp, err := client.SecretScanning.GetScanHistory(ctx, "o", "r") | ||
| return resp, err | ||
| }) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.