@@ -42,6 +42,8 @@ public async Task One_Secret_Updated()
42
42
SecretType = secretType ,
43
43
Secret = secret ,
44
44
Resolution = SecretScanningAlert . ResolutionRevoked ,
45
+ ResolutionComment = "This token was revoked during migration" ,
46
+ ResolverName = "actor"
45
47
} ;
46
48
47
49
var sourceLocation = new GithubSecretScanningAlertLocation ( )
@@ -95,7 +97,7 @@ public async Task One_Secret_Updated()
95
97
100 ,
96
98
SecretScanningAlert . AlertStateResolved ,
97
99
SecretScanningAlert . ResolutionRevoked ,
98
- null )
100
+ $ "[@ { sourceSecret . ResolverName } ] { sourceSecret . ResolutionComment } " )
99
101
) ;
100
102
}
101
103
@@ -105,6 +107,7 @@ public async Task Secret_Updated_With_Comment()
105
107
var secretType = "custom" ;
106
108
var secret = "my-password" ;
107
109
var resolutionComment = "This secret was revoked and replaced" ;
110
+ var resolverName = "actor" ;
108
111
109
112
// Arrange
110
113
var sourceSecret = new GithubSecretScanningAlert ( )
@@ -114,7 +117,8 @@ public async Task Secret_Updated_With_Comment()
114
117
SecretType = secretType ,
115
118
Secret = secret ,
116
119
Resolution = SecretScanningAlert . ResolutionRevoked ,
117
- ResolutionComment = resolutionComment
120
+ ResolutionComment = resolutionComment ,
121
+ ResolverName = resolverName
118
122
} ;
119
123
120
124
var sourceLocation = new GithubSecretScanningAlertLocation ( )
@@ -168,7 +172,7 @@ public async Task Secret_Updated_With_Comment()
168
172
100 ,
169
173
SecretScanningAlert . AlertStateResolved ,
170
174
SecretScanningAlert . ResolutionRevoked ,
171
- resolutionComment )
175
+ $ "[@ { sourceSecret . ResolverName } ] { sourceSecret . ResolutionComment } " )
172
176
) ;
173
177
}
174
178
@@ -186,6 +190,8 @@ public async Task No_Matching_Location()
186
190
SecretType = secretType ,
187
191
Secret = secret ,
188
192
Resolution = SecretScanningAlert . ResolutionRevoked ,
193
+ ResolutionComment = "This token was revoked during migration" ,
194
+ ResolverName = "actor"
189
195
} ;
190
196
191
197
var sourceLocation = new GithubSecretScanningAlertLocation ( )
@@ -256,6 +262,8 @@ public async Task No_Matching_Secret()
256
262
SecretType = secretType ,
257
263
Secret = secret ,
258
264
Resolution = SecretScanningAlert . ResolutionRevoked ,
265
+ ResolutionComment = "This token was revoked during migration" ,
266
+ ResolverName = "actor"
259
267
} ;
260
268
261
269
var sourceLocation = new GithubSecretScanningAlertLocation ( )
@@ -375,6 +383,8 @@ public async Task Migrates_Multiple_Alerts()
375
383
SecretType = secretType ,
376
384
Secret = secretOne ,
377
385
Resolution = SecretScanningAlert . ResolutionRevoked ,
386
+ ResolutionComment = "This token was revoked during migration" ,
387
+ ResolverName = "actor"
378
388
} ;
379
389
380
390
var sourceSecretTwo = new GithubSecretScanningAlert ( )
@@ -384,6 +394,8 @@ public async Task Migrates_Multiple_Alerts()
384
394
SecretType = secretType ,
385
395
Secret = secretTwo ,
386
396
Resolution = SecretScanningAlert . ResolutionRevoked ,
397
+ ResolutionComment = "This token was revoked during migration" ,
398
+ ResolverName = "actor"
387
399
} ;
388
400
389
401
var sourceSecretThree = new GithubSecretScanningAlert ( )
@@ -393,6 +405,8 @@ public async Task Migrates_Multiple_Alerts()
393
405
SecretType = secretType ,
394
406
Secret = secretThree ,
395
407
Resolution = SecretScanningAlert . ResolutionFalsePositive ,
408
+ ResolutionComment = "This token was revoked during migration" ,
409
+ ResolverName = "actor"
396
410
} ;
397
411
398
412
var sourceLocation = new GithubSecretScanningAlertLocation ( )
@@ -443,7 +457,7 @@ public async Task Migrates_Multiple_Alerts()
443
457
100 ,
444
458
SecretScanningAlert . AlertStateResolved ,
445
459
SecretScanningAlert . ResolutionRevoked ,
446
- null )
460
+ $ "[@ { sourceSecretOne . ResolverName } ] { sourceSecretOne . ResolutionComment } " )
447
461
) ;
448
462
449
463
_mockTargetGithubApi . Verify ( m => m . UpdateSecretScanningAlert (
@@ -452,7 +466,7 @@ public async Task Migrates_Multiple_Alerts()
452
466
300 ,
453
467
SecretScanningAlert . AlertStateResolved ,
454
468
SecretScanningAlert . ResolutionFalsePositive ,
455
- null )
469
+ $ "[@ { sourceSecretThree . ResolverName } ] { sourceSecretThree . ResolutionComment } " )
456
470
) ;
457
471
}
458
472
@@ -687,6 +701,8 @@ public async Task Migrate_Matching_Alerts_With_Different_Resolutions()
687
701
SecretType = secretType ,
688
702
Secret = secret ,
689
703
Resolution = SecretScanningAlert . ResolutionRevoked ,
704
+ ResolutionComment = "This token was revoked" ,
705
+ ResolverName = "actor-source"
690
706
} ;
691
707
692
708
var sourceLocation = new GithubSecretScanningAlertLocation ( )
@@ -712,6 +728,8 @@ public async Task Migrate_Matching_Alerts_With_Different_Resolutions()
712
728
SecretType = secretType ,
713
729
Secret = secret ,
714
730
Resolution = SecretScanningAlert . ResolutionFalsePositive ,
731
+ ResolutionComment = "This token was resolved as false positive" ,
732
+ ResolverName = "actor-target"
715
733
} ;
716
734
717
735
var targetSecretLocation = new GithubSecretScanningAlertLocation ( )
@@ -740,7 +758,7 @@ public async Task Migrate_Matching_Alerts_With_Different_Resolutions()
740
758
100 ,
741
759
SecretScanningAlert . AlertStateResolved ,
742
760
SecretScanningAlert . ResolutionRevoked ,
743
- null )
761
+ $ "[@ { sourceSecret . ResolverName } ] { sourceSecret . ResolutionComment } " )
744
762
) ;
745
763
}
746
764
@@ -901,7 +919,7 @@ public async Task Alerts_With_Extra_Fields_Are_Handled_Gracefully()
901
919
100 ,
902
920
SecretScanningAlert . AlertStateResolved ,
903
921
SecretScanningAlert . ResolutionRevoked ,
904
- null )
922
+ "[@] " )
905
923
) ;
906
924
}
907
925
@@ -919,7 +937,8 @@ public async Task Pull_Request_Comment_Location_Is_Matched_And_Secret_Is_Updated
919
937
SecretType = secretType ,
920
938
Secret = secret ,
921
939
Resolution = SecretScanningAlert . ResolutionRevoked ,
922
- ResolutionComment = "This token was revoked during migration"
940
+ ResolutionComment = "This token was revoked during migration" ,
941
+ ResolverName = "actor"
923
942
} ;
924
943
925
944
var sourceLocation = new GithubSecretScanningAlertLocation
@@ -966,7 +985,7 @@ public async Task Pull_Request_Comment_Location_Is_Matched_And_Secret_Is_Updated
966
985
100 ,
967
986
SecretScanningAlert . AlertStateResolved ,
968
987
SecretScanningAlert . ResolutionRevoked ,
969
- "This token was revoked during migration ")
988
+ $ "[@ { sourceSecret . ResolverName } ] { sourceSecret . ResolutionComment } ")
970
989
) ;
971
990
}
972
991
@@ -1056,7 +1075,7 @@ public async Task Pull_Request_Comment_And_Commit_Locations_Are_Both_Matched()
1056
1075
100 ,
1057
1076
SecretScanningAlert . AlertStateResolved ,
1058
1077
SecretScanningAlert . ResolutionRevoked ,
1059
- null )
1078
+ "[@] " )
1060
1079
) ;
1061
1080
}
1062
1081
@@ -1137,7 +1156,8 @@ public async Task Multiple_Pull_Request_Related_Location_Types_Are_Matched()
1137
1156
SecretType = secretType ,
1138
1157
Secret = secret ,
1139
1158
Resolution = SecretScanningAlert . ResolutionFalsePositive ,
1140
- ResolutionComment = "This is a test token"
1159
+ ResolutionComment = "This is a test token" ,
1160
+ ResolverName = "actor"
1141
1161
} ;
1142
1162
1143
1163
var sourceLocations = new [ ]
@@ -1214,7 +1234,47 @@ public async Task Multiple_Pull_Request_Related_Location_Types_Are_Matched()
1214
1234
100 ,
1215
1235
SecretScanningAlert . AlertStateResolved ,
1216
1236
SecretScanningAlert . ResolutionFalsePositive ,
1217
- "This is a test token" )
1237
+ $ "[@{ sourceSecret . ResolverName } ] { sourceSecret . ResolutionComment } ")
1238
+ ) ;
1239
+ }
1240
+
1241
+ [ Fact ]
1242
+ public async Task Update_When_No_ResolutionComment_Still_Includes_ResolverName_Prefix ( )
1243
+ {
1244
+ // Arrange
1245
+ var source = new GithubSecretScanningAlert
1246
+ {
1247
+ Number = 1 ,
1248
+ State = SecretScanningAlert . AlertStateResolved ,
1249
+ SecretType = "foo" ,
1250
+ Secret = "bar" ,
1251
+ Resolution = SecretScanningAlert . ResolutionRevoked ,
1252
+ ResolverName = "actor" ,
1253
+ ResolutionComment = null
1254
+ } ;
1255
+ var srcLoc = new GithubSecretScanningAlertLocation { LocationType = "commit" , Path = "f" , StartLine = 1 , EndLine = 1 , StartColumn = 1 , EndColumn = 1 , BlobSha = "x" } ;
1256
+ _mockSourceGithubApi
1257
+ . Setup ( x => x . GetSecretScanningAlertsForRepository ( SOURCE_ORG , SOURCE_REPO ) ) . ReturnsAsync ( new [ ] { source } ) ;
1258
+ _mockSourceGithubApi
1259
+ . Setup ( x => x . GetSecretScanningAlertsLocations ( SOURCE_ORG , SOURCE_REPO , 1 ) ) . ReturnsAsync ( new [ ] { srcLoc } ) ;
1260
+
1261
+ var tgt = new GithubSecretScanningAlert { Number = 42 , State = SecretScanningAlert . AlertStateOpen , SecretType = "foo" , Secret = "bar" } ;
1262
+ _mockTargetGithubApi
1263
+ . Setup ( x => x . GetSecretScanningAlertsForRepository ( TARGET_ORG , TARGET_REPO ) ) . ReturnsAsync ( new [ ] { tgt } ) ;
1264
+ _mockTargetGithubApi
1265
+ . Setup ( x => x . GetSecretScanningAlertsLocations ( TARGET_ORG , TARGET_REPO , 42 ) ) . ReturnsAsync ( new [ ] { srcLoc } ) ;
1266
+
1267
+ // Act
1268
+ await _service . MigrateSecretScanningAlerts ( SOURCE_ORG , SOURCE_REPO , TARGET_ORG , TARGET_REPO , false ) ;
1269
+
1270
+ // Assert
1271
+ _mockTargetGithubApi . Verify ( m => m . UpdateSecretScanningAlert (
1272
+ TARGET_ORG ,
1273
+ TARGET_REPO ,
1274
+ 42 ,
1275
+ SecretScanningAlert . AlertStateResolved ,
1276
+ SecretScanningAlert . ResolutionRevoked ,
1277
+ "[@actor] " ) // even though comment was null
1218
1278
) ;
1219
1279
}
1220
1280
}
0 commit comments