|
6 | 6 |
|
7 | 7 | "github.com/nightfallai/nightfall_cli/internal/clients/diffreviewer" |
8 | 8 | githublogger "github.com/nightfallai/nightfall_cli/internal/clients/logger/github_logger" |
9 | | - "github.com/nightfallai/nightfall_cli/internal/nightfallconfig" |
10 | 9 | nightfallAPI "github.com/nightfallai/nightfall_go_client/generated" |
| 10 | + |
11 | 11 | "github.com/stretchr/testify/assert" |
12 | 12 | ) |
13 | 13 |
|
@@ -127,18 +127,14 @@ func TestSliceListBySize(t *testing.T) { |
127 | 127 | } |
128 | 128 |
|
129 | 129 | func TestCreateCommentsFromScanResp(t *testing.T) { |
130 | | - detectorConfigs := nightfallconfig.DetectorConfig{ |
131 | | - nightfallAPI.CREDIT_CARD_NUMBER: nightfallAPI.LIKELY, |
132 | | - nightfallAPI.IP_ADDRESS: nightfallAPI.LIKELY, |
133 | | - } |
134 | 130 | emptyTokenExclusionList := []string{} |
135 | 131 | creditCard2Regex := "4242-4242-4242-[0-9]{4}" |
136 | 132 | localIpRegex := "^127\\." |
137 | 133 | tokenExclusionList := []string{creditCard2Regex, localIpRegex} |
138 | | - creditCardResponse := createScanResponse(exampleCreditCardNumber, nightfallAPI.CREDIT_CARD_NUMBER, nightfallAPI.VERY_LIKELY) |
139 | | - creditCard2Response := createScanResponse(exampleCreditCardNumber2, nightfallAPI.CREDIT_CARD_NUMBER, nightfallAPI.VERY_LIKELY) |
140 | | - apiKeyResponse := createScanResponse(exampleAPIKey, nightfallAPI.API_KEY, nightfallAPI.VERY_LIKELY) |
141 | | - ipAddressResponse := createScanResponse(exampleIP, nightfallAPI.IP_ADDRESS, nightfallAPI.VERY_LIKELY) |
| 134 | + creditCardResponse := createScanResponse(exampleCreditCardNumber, nightfallAPI.CREDIT_CARD_NUMBER) |
| 135 | + creditCard2Response := createScanResponse(exampleCreditCardNumber2, nightfallAPI.CREDIT_CARD_NUMBER) |
| 136 | + apiKeyResponse := createScanResponse(exampleAPIKey, nightfallAPI.API_KEY) |
| 137 | + ipAddressResponse := createScanResponse(exampleIP, nightfallAPI.IP_ADDRESS) |
142 | 138 | tests := []struct { |
143 | 139 | haveContentToScanList []*contentToScan |
144 | 140 | haveScanResponseList [][]nightfallAPI.ScanResponse |
@@ -168,76 +164,28 @@ func TestCreateCommentsFromScanResp(t *testing.T) { |
168 | 164 | haveTokenExclusionList: emptyTokenExclusionList, |
169 | 165 | want: []*diffreviewer.Comment{ |
170 | 166 | createComment(creditCardResponse), |
| 167 | + createComment(apiKeyResponse), |
171 | 168 | createComment(creditCard2Response), |
172 | 169 | }, |
173 | | - desc: "credit cards omit api finding", |
174 | | - }, |
175 | | - { |
176 | | - haveContentToScanList: []*contentToScan{ |
177 | | - createContentToScan(creditCardNumberContent), |
178 | | - createContentToScan("nothing in here"), |
179 | | - createContentToScan(apiKeyContent), |
180 | | - }, |
181 | | - haveScanResponseList: [][]nightfallAPI.ScanResponse{ |
182 | | - { |
183 | | - creditCardResponse, |
184 | | - }, |
185 | | - { |
186 | | - createScanResponse("low likelihood on 4534343", nightfallAPI.CREDIT_CARD_NUMBER, nightfallAPI.UNLIKELY), |
187 | | - }, |
188 | | - }, |
189 | | - haveTokenExclusionList: emptyTokenExclusionList, |
190 | | - want: []*diffreviewer.Comment{ |
191 | | - createComment(creditCardResponse), |
192 | | - }, |
193 | | - desc: "single credit card passing likelihood threshold", |
| 170 | + desc: "credit cards and an api key", |
194 | 171 | }, |
195 | 172 | { |
196 | 173 | haveContentToScanList: []*contentToScan{ |
197 | 174 | createContentToScan("nothing in here"), |
198 | 175 | createContentToScan("nothing in here"), |
199 | 176 | createContentToScan("nothing in here"), |
200 | 177 | createContentToScan("nothing in here"), |
201 | | - createContentToScan(apiKeyContent), |
202 | 178 | }, |
203 | 179 | haveScanResponseList: [][]nightfallAPI.ScanResponse{ |
204 | 180 | {}, |
205 | 181 | {}, |
206 | 182 | {}, |
207 | 183 | {}, |
208 | | - { |
209 | | - apiKeyResponse, |
210 | | - }, |
211 | 184 | }, |
212 | 185 | haveTokenExclusionList: emptyTokenExclusionList, |
213 | 186 | want: []*diffreviewer.Comment{}, |
214 | 187 | desc: "no comments", |
215 | 188 | }, |
216 | | - { |
217 | | - haveContentToScanList: []*contentToScan{ |
218 | | - createContentToScan(creditCardNumberContent), |
219 | | - createContentToScan("nothing in here"), |
220 | | - createContentToScan(apiKeyContent), |
221 | | - createContentToScan(creditCardNumber2Content), |
222 | | - }, |
223 | | - haveScanResponseList: [][]nightfallAPI.ScanResponse{ |
224 | | - { |
225 | | - creditCardResponse, |
226 | | - }, |
227 | | - {}, |
228 | | - { |
229 | | - apiKeyResponse, |
230 | | - }, |
231 | | - { |
232 | | - creditCard2Response, |
233 | | - }, |
234 | | - }, |
235 | | - haveTokenExclusionList: tokenExclusionList, |
236 | | - want: []*diffreviewer.Comment{ |
237 | | - createComment(creditCardResponse), |
238 | | - }, |
239 | | - desc: "single credit card excluded", |
240 | | - }, |
241 | 189 | { |
242 | 190 | haveContentToScanList: []*contentToScan{ |
243 | 191 | createContentToScan("4242-4242-4242-abcd"), |
@@ -266,40 +214,8 @@ func TestCreateCommentsFromScanResp(t *testing.T) { |
266 | 214 | }, |
267 | 215 | } |
268 | 216 | for _, tt := range tests { |
269 | | - actual := createCommentsFromScanResp(tt.haveContentToScanList, tt.haveScanResponseList, detectorConfigs, tt.haveTokenExclusionList) |
270 | | - assert.Equal(t, tt.want, actual, fmt.Sprintf("Incorrect response from createCommentsFromScanResp: %s test", tt.desc)) |
271 | | - } |
272 | | -} |
273 | | - |
274 | | -func TestFoundSensitiveData(t *testing.T) { |
275 | | - detectorConfigs := nightfallconfig.DetectorConfig{ |
276 | | - nightfallAPI.CREDIT_CARD_NUMBER: nightfallAPI.POSSIBLE, |
277 | | - } |
278 | | - tests := []struct { |
279 | | - have nightfallAPI.Likelihood |
280 | | - want bool |
281 | | - }{} |
282 | | - for _, l := range allLikelihoods { |
283 | | - var want bool |
284 | | - switch l { |
285 | | - case nightfallAPI.VERY_UNLIKELY, nightfallAPI.UNLIKELY: |
286 | | - want = false |
287 | | - default: |
288 | | - want = true |
289 | | - } |
290 | | - tests = append(tests, struct { |
291 | | - have nightfallAPI.Likelihood |
292 | | - want bool |
293 | | - }{ |
294 | | - have: l, |
295 | | - want: want, |
296 | | - }) |
297 | | - } |
298 | | - |
299 | | - for _, tt := range tests { |
300 | | - finding := createScanResponse("", nightfallAPI.CREDIT_CARD_NUMBER, tt.have) |
301 | | - actual := foundSensitiveData(finding, detectorConfigs) |
302 | | - assert.Equal(t, tt.want, actual, "Incorrect response from foundSensitiveData") |
| 217 | + actual := createCommentsFromScanResp(tt.haveContentToScanList, tt.haveScanResponseList, tt.haveTokenExclusionList) |
| 218 | + assert.Equal(t, tt.want, actual, fmt.Sprintf("Incorrect response from createCommentsFromScanResp: test '%s'", tt.desc)) |
303 | 219 | } |
304 | 220 | } |
305 | 221 |
|
@@ -465,14 +381,10 @@ func TestMatchGlob(t *testing.T) { |
465 | 381 | assert.Equal(t, tt.wantMatchedPaths, matchedPaths, fmt.Sprintf("Incorrect response from match glob %s test", tt.desc)) |
466 | 382 | } |
467 | 383 | } |
468 | | - |
469 | | -func createScanResponse(fragment string, detector nightfallAPI.Detector, likelihood nightfallAPI.Likelihood) nightfallAPI.ScanResponse { |
| 384 | +func createScanResponse(fragment string, detector nightfallAPI.Detector) nightfallAPI.ScanResponse { |
470 | 385 | return nightfallAPI.ScanResponse{ |
471 | 386 | Fragment: fragment, |
472 | 387 | Detector: string(detector), |
473 | | - Confidence: nightfallAPI.ScanResponseConfidence{ |
474 | | - Bucket: string(likelihood), |
475 | | - }, |
476 | 388 | Location: nightfallAPI.ScanResponseLocation{ |
477 | 389 | ByteRange: nightfallAPI.ScanResponseLocationByteRange{ |
478 | 390 | Start: 0, |
|
0 commit comments