@@ -639,33 +639,35 @@ func TestRedactRunResidual(t *testing.T) {
639639func TestRedactTxt (t * testing.T ) {
640640 for _ , tc := range []struct {
641641 name string
642- txt [] byte
643- expected [] byte
642+ txt string
643+ expected string
644644 }{
645645 {
646646 name : "remote headers" ,
647- txt : [] byte ( "ok --remote_header=x-buildbuddy-api-key=secret --flag=ok" ) ,
648- expected : [] byte ( "ok --remote_header=<REDACTED> --flag=ok" ) ,
647+ txt : "ok --remote_header=x-buildbuddy-api-key=secret --flag=ok" ,
648+ expected : "ok --remote_header=<REDACTED> --flag=ok" ,
649649 },
650650 {
651651 name : "url secrets" ,
652- txt : [] byte ( "ok url://username:password@uri --flag=ok" ) ,
653- expected : [] byte ( "ok url://username:<REDACTED>@uri --flag=ok" ) ,
652+ txt : "ok url://username:password@uri --flag=ok" ,
653+ expected : "ok url://username:<REDACTED>@uri --flag=ok" ,
654654 },
655655 {
656656 name : "do not redact rules names" ,
657- txt : [] byte ( "ERROR: Error computing the main repository mapping: rules_apple@3.16.1 depends on rules_swift@2.1.1 with compatibility level 2, but <root> depends on rules_swift@1.18.0 with compatibility level 1 which is different" ) ,
658- expected : [] byte ( "ERROR: Error computing the main repository mapping: rules_apple@3.16.1 depends on rules_swift@2.1.1 with compatibility level 2, but <root> depends on rules_swift@1.18.0 with compatibility level 1 which is different" ) ,
657+ txt : "ERROR: Error computing the main repository mapping: rules_apple@3.16.1 depends on rules_swift@2.1.1 with compatibility level 2, but <root> depends on rules_swift@1.18.0 with compatibility level 1 which is different" ,
658+ expected : "ERROR: Error computing the main repository mapping: rules_apple@3.16.1 depends on rules_swift@2.1.1 with compatibility level 2, but <root> depends on rules_swift@1.18.0 with compatibility level 1 which is different" ,
659659 },
660660 {
661661 name : "api key start of line" ,
662- txt : [] byte ( "apikeyexactly20chars@mydomain.com" ) ,
663- expected : [] byte ( "<REDACTED>@mydomain.com" ) ,
662+ txt : "apikeyexactly20chars@mydomain.com" ,
663+ expected : "<REDACTED>@mydomain.com" ,
664664 },
665665 {
666- name : "environment variables" ,
667- txt : []byte ("common --repo_env=AWS_ACCESS_KEY_ID=super_secret_access_key_id # gitleaks:allow\n common --repo_env=AWS_SECRET_ACCESS_KEY=super_secret_access_key # gitleaks:allow" ),
668- expected : []byte ("common --repo_env=AWS_ACCESS_KEY_ID=<REDACTED> # gitleaks:allow\n common --repo_env=AWS_SECRET_ACCESS_KEY=<REDACTED> # gitleaks:allow" ),
666+ name : "environment variables" ,
667+ txt : "common --repo_env=AWS_ACCESS_KEY_ID=super_secret_access_key_id # gitleaks:allow\n " +
668+ "common --repo_env=AWS_SECRET_ACCESS_KEY=super_secret_access_key # gitleaks:allow" ,
669+ expected : "common --repo_env=AWS_ACCESS_KEY_ID=<REDACTED> # gitleaks:allow\n " +
670+ "common --repo_env=AWS_SECRET_ACCESS_KEY=<REDACTED> # gitleaks:allow" ,
669671 },
670672 } {
671673 t .Run (tc .name , func (t * testing.T ) {
@@ -678,28 +680,28 @@ func TestRedactTxt(t *testing.T) {
678680func TestRedactAPIKeys (t * testing.T ) {
679681 for _ , tc := range []struct {
680682 name string
681- txt [] byte
682- expected [] byte
683+ txt string
684+ expected string
683685 }{
684686 {
685687 name : "api key after equals" ,
686- txt : [] byte ( "MY_SECRET_API_KEY=apikeyexactly20chars@mydomain.com" ) ,
687- expected : [] byte ( "MY_SECRET_API_KEY=<REDACTED>@mydomain.com" ) ,
688+ txt : "MY_SECRET_API_KEY=apikeyexactly20chars@mydomain.com" ,
689+ expected : "MY_SECRET_API_KEY=<REDACTED>@mydomain.com" ,
688690 },
689691 {
690692 name : "api key in grpc call" ,
691- txt : [] byte ( "grpc://apikeyexactly20chars@mydomain.com" ) ,
692- expected : [] byte ( "grpc://<REDACTED>@mydomain.com" ) ,
693+ txt : "grpc://apikeyexactly20chars@mydomain.com" ,
694+ expected : "grpc://<REDACTED>@mydomain.com" ,
693695 },
694696 {
695697 name : "api key in http call" ,
696- txt : [] byte ( "https://apikeyexactly20chars@mydomain.com" ) ,
697- expected : [] byte ( "https://<REDACTED>@mydomain.com" ) ,
698+ txt : "https://apikeyexactly20chars@mydomain.com" ,
699+ expected : "https://<REDACTED>@mydomain.com" ,
698700 },
699701 {
700702 name : "do not redact text before bazel repository name" ,
701- txt : [] byte ( "FAILED:exactly20alphanumber@@apple_support++apple_cc_configure_extension+local_config_apple_cc; starting" ) ,
702- expected : [] byte ( "FAILED:exactly20alphanumber@@apple_support++apple_cc_configure_extension+local_config_apple_cc; starting" ) ,
703+ txt : "FAILED:exactly20alphanumber@@apple_support++apple_cc_configure_extension+local_config_apple_cc; starting" ,
704+ expected : "FAILED:exactly20alphanumber@@apple_support++apple_cc_configure_extension+local_config_apple_cc; starting" ,
703705 },
704706 } {
705707 t .Run (tc .name , func (t * testing.T ) {
@@ -709,14 +711,14 @@ func TestRedactAPIKeys(t *testing.T) {
709711 event := & bespb.BuildEvent {
710712 Payload : & bespb.BuildEvent_Progress {
711713 Progress : & bespb.Progress {
712- Stdout : string ( tc .txt ) ,
714+ Stdout : tc .txt ,
713715 },
714716 },
715717 }
716718 redactor := redact .NewStreamingRedactor (testenv .GetTestEnv (t ))
717719 err := redactor .RedactAPIKeysWithSlowRegexp (context .TODO (), event )
718720 require .NoError (t , err )
719- require .Equal (t , string ( tc .expected ) , event .GetProgress ().GetStdout ())
721+ require .Equal (t , tc .expected , event .GetProgress ().GetStdout ())
720722 })
721723 }
722724}
0 commit comments