@@ -16,6 +16,7 @@ import (
1616 "github.com/stretchr/testify/require"
1717
1818 "github.com/cloudposse/atmos/pkg/ci/internal/provider"
19+ atmosio "github.com/cloudposse/atmos/pkg/io"
1920)
2021
2122func TestMapCheckRunStateToStatusState (t * testing.T ) {
@@ -183,6 +184,49 @@ func TestProvider_CreateCheckRun(t *testing.T) {
183184 })
184185}
185186
187+ func TestProvider_CreateCheckRun_MasksRegisteredSecrets (t * testing.T ) {
188+ atmosio .Reset ()
189+ t .Cleanup (atmosio .Reset )
190+
191+ const secret = "status-secret-ABCD1234"
192+ atmosio .RegisterSecret (secret )
193+
194+ var capturedRequest map [string ]any
195+ mux := http .NewServeMux ()
196+ mux .HandleFunc ("/repos/owner/repo/statuses/abc123" , func (w http.ResponseWriter , r * http.Request ) {
197+ require .NoError (t , json .NewDecoder (r .Body ).Decode (& capturedRequest ))
198+ w .Header ().Set ("Content-Type" , "application/json" )
199+ _ = json .NewEncoder (w ).Encode (map [string ]any {
200+ "id" : 12345 ,
201+ "context" : capturedRequest ["context" ],
202+ "state" : capturedRequest ["state" ],
203+ "description" : capturedRequest ["description" ],
204+ })
205+ })
206+
207+ server := httptest .NewServer (mux )
208+ t .Cleanup (server .Close )
209+ serverURL , err := url .Parse (server .URL + "/" )
210+ require .NoError (t , err )
211+ ghClient := github .NewClient (nil )
212+ ghClient .BaseURL = serverURL
213+ p := NewProviderWithClient (& Client {client : ghClient })
214+
215+ _ , err = p .CreateCheckRun (context .Background (), & provider.CreateCheckRunOptions {
216+ Owner : "owner" ,
217+ Repo : "repo" ,
218+ SHA : "abc123" ,
219+ Name : "atmos/plan/test/service" ,
220+ Status : provider .CheckRunStatePending ,
221+ Title : "credential: " + secret ,
222+ })
223+ require .NoError (t , err )
224+ description , ok := capturedRequest ["description" ].(string )
225+ require .True (t , ok )
226+ assert .NotContains (t , description , secret )
227+ assert .Contains (t , description , atmosio .MaskReplacement )
228+ }
229+
186230func TestProvider_UpdateCheckRun (t * testing.T ) {
187231 t .Run ("update is idempotent CreateStatus call" , func (t * testing.T ) {
188232 // UpdateCheckRun should call the same CreateStatus endpoint.
0 commit comments