@@ -616,3 +616,128 @@ func TestSecretScanningAlertUpdateOptions_Marshal(t *testing.T) {
616616
617617 testJSONMarshal (t , u , want )
618618}
619+
620+ func TestSecretScanningService_CreatePushProtectionBypass (t * testing.T ) {
621+ t .Parallel ()
622+ client , mux , _ := setup (t )
623+
624+ owner := "o"
625+ repo := "r"
626+
627+ mux .HandleFunc (fmt .Sprintf ("/repos/%v/%v/secret-scanning/push-protection-bypasses" , owner , repo ), func (w http.ResponseWriter , r * http.Request ) {
628+ testMethod (t , r , "POST" )
629+ var v * PushProtectionBypassRequest
630+ assertNilError (t , json .NewDecoder (r .Body ).Decode (& v ))
631+ want := & PushProtectionBypassRequest {Reason : "valid reason" , PlaceholderID : "bypass-123" }
632+ if ! cmp .Equal (v , want ) {
633+ t .Errorf ("Request body = %+v, want %+v" , v , want )
634+ }
635+
636+ fmt .Fprint (w , `{
637+ "reason": "valid reason",
638+ "expire_at": "2018-01-01T00:00:00Z",
639+ "token_type": "github_token"
640+ }` )
641+ })
642+
643+ ctx := t .Context ()
644+ opts := PushProtectionBypassRequest {Reason : "valid reason" , PlaceholderID : "bypass-123" }
645+
646+ bypass , _ , err := client .SecretScanning .CreatePushProtectionBypass (ctx , owner , repo , opts )
647+ if err != nil {
648+ t .Errorf ("SecretScanning.CreatePushProtectionBypass returned error: %v" , err )
649+ }
650+
651+ expireTime := Timestamp {time .Date (2018 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC )}
652+ want := & PushProtectionBypass {
653+ Reason : "valid reason" ,
654+ ExpireAt : & expireTime ,
655+ TokenType : "github_token" ,
656+ }
657+
658+ if ! cmp .Equal (bypass , want ) {
659+ t .Errorf ("SecretScanning.CreatePushProtectionBypass returned %+v, want %+v" , bypass , want )
660+ }
661+ const methodName = "CreatePushProtectionBypass"
662+ testBadOptions (t , methodName , func () (err error ) {
663+ _ , _ , err = client .SecretScanning .CreatePushProtectionBypass (ctx , "\n " , "\n " , opts )
664+ return err
665+ })
666+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
667+ _ , resp , err := client .SecretScanning .CreatePushProtectionBypass (ctx , "o" , "r" , opts )
668+ return resp , err
669+ })
670+ }
671+
672+ func TestSecretScanningService_GetScanHistory (t * testing.T ) {
673+ t .Parallel ()
674+ client , mux , _ := setup (t )
675+
676+ owner := "o"
677+ repo := "r"
678+
679+ mux .HandleFunc (fmt .Sprintf ("/repos/%v/%v/secret-scanning/scan-history" , owner , repo ), func (w http.ResponseWriter , r * http.Request ) {
680+ testMethod (t , r , "GET" )
681+ fmt .Fprint (w , `{
682+ "incremental_scans": [
683+ {
684+ "type": "incremental",
685+ "status": "success",
686+ "completed_at": "2025-07-29T10:00:00Z",
687+ "started_at": "2025-07-29T09:55:00Z"
688+ }
689+ ],
690+ "backfill_scans": [],
691+ "pattern_update_scans": [],
692+ "custom_pattern_backfill_scans": [
693+ {
694+ "type": "custom_backfill",
695+ "status": "in_progress",
696+ "completed_at": null,
697+ "started_at": "2025-07-29T09:00:00Z",
698+ "pattern_slug": "my-custom-pattern",
699+ "pattern_scope": "organization"
700+ }
701+ ]
702+ }` )
703+ })
704+
705+ ctx := t .Context ()
706+
707+ history , _ , err := client .SecretScanning .GetScanHistory (ctx , owner , repo )
708+ if err != nil {
709+ t .Errorf ("SecretScanning.GetScanHistory returned error: %v" , err )
710+ }
711+
712+ incrementalScanStartAt := Timestamp {time .Date (2025 , time .July , 29 , 9 , 55 , 0 , 0 , time .UTC )}
713+ incrementalScancompleteAt := Timestamp {time .Date (2025 , time .July , 29 , 10 , 0 , 0 , 0 , time .UTC )}
714+ customPatternBackfillScanStartedAt := Timestamp {time .Date (2025 , time .July , 29 , 9 , 0 , 0 , 0 , time .UTC )}
715+
716+ want := & SecretScanningScanHistory {
717+ IncrementalScans : []* SecretsScan {
718+ {Type : "incremental" , Status : "success" , CompletedAt : & incrementalScancompleteAt , StartedAt : & incrementalScanStartAt },
719+ },
720+ BackfillScans : []* SecretsScan {},
721+ PatternUpdateScans : []* SecretsScan {},
722+ CustomPatternBackfillScans : []* CustomPatternBackfillScan {
723+ {
724+ SecretsScan : SecretsScan {Type : "custom_backfill" , Status : "in_progress" , CompletedAt : nil , StartedAt : & customPatternBackfillScanStartedAt },
725+ PatternSlug : Ptr ("my-custom-pattern" ),
726+ PatternScope : Ptr ("organization" ),
727+ },
728+ },
729+ }
730+
731+ if ! cmp .Equal (history , want ) {
732+ t .Errorf ("SecretScanning.GetScanHistory returned %+v, want %+v" , history , want )
733+ }
734+ const methodName = "GetScanHistory"
735+ testBadOptions (t , methodName , func () (err error ) {
736+ _ , _ , err = client .SecretScanning .GetScanHistory (ctx , "\n " , "\n " )
737+ return err
738+ })
739+ testNewRequestAndDoFailure (t , methodName , client , func () (* Response , error ) {
740+ _ , resp , err := client .SecretScanning .GetScanHistory (ctx , "o" , "r" )
741+ return resp , err
742+ })
743+ }
0 commit comments