@@ -4,10 +4,10 @@ import { findLikelySecrets } from '../../lib/plugins_core/secrets_scanning/utils
4
4
5
5
test ( 'findLikelySecrets - should not find secrets without quotes or delimiters' , async ( t ) => {
6
6
const lines = [
7
- 'aws_123456789012345678 ' ,
8
- 'ghp_1234567890123456789 ' ,
9
- 'xoxb-123456789012345678 ' ,
10
- 'nf_123456789012345678 ' ,
7
+ 'aws_Kj2P9xL5mN8vB3cX7qA4 ' ,
8
+ 'ghp_zR4wY7hQ9sK2nM5vL8xbkokM0vgXC ' ,
9
+ 'xoxb-bV8cX3zL6kM9nQ4wR7y3FIASwY6YX ' ,
10
+ 'nf_pT2hN7mK4jL9wB5vC8xOzHucej7Or ' ,
11
11
]
12
12
13
13
lines . forEach ( ( text ) => {
@@ -18,12 +18,12 @@ test('findLikelySecrets - should not find secrets without quotes or delimiters',
18
18
19
19
test ( 'findLikelySecrets - should find secrets with quotes or equals' , async ( t ) => {
20
20
const matchingLines = [
21
- 'my_secret_key=aws_123456789012345678 ' ,
22
- 'mySecretKey = aws_123456789012345678 ' ,
23
- 'secretKey="aws_123456789012345678 "' ,
24
- 'secretKey = "aws_123456789012345678 "' ,
25
- "secretKey='aws_123456789012345678 '" ,
26
- 'secretKey=`aws_123456789012345678 `' ,
21
+ 'my_secret_key=aws_Kj2P9xL5mN8vB3cX7qA4 ' ,
22
+ 'mySecretKey = aws_zR4wY7hQ9sK2nM5vL8xbkokM0vgXC ' ,
23
+ 'secretKey="aws_dF6gH9jK4mP7nW2xR5tYc6dBmFP5ym "' ,
24
+ 'secretKey = "aws_bV8cX3zL6kM9nQ4wR7y3FIASwY6YX "' ,
25
+ "secretKey='aws_pT2hN7mK4jL9wB5vC8xOzHucej7Or '" ,
26
+ 'secretKey=`aws_qS3fD8gH5jK2mN6pR9yHfBxkujdx2 `' ,
27
27
]
28
28
matchingLines . forEach ( ( text ) => {
29
29
const matches = findLikelySecrets ( { text } )
@@ -32,18 +32,18 @@ test('findLikelySecrets - should find secrets with quotes or equals', async (t)
32
32
} )
33
33
34
34
test ( 'findLikelySecrets - should not match values with spaces after prefix' , async ( t ) => {
35
- const nonMatchingLine = 'aws_ "123456789012345678 "'
35
+ const nonMatchingLine = 'aws_ "Kj2P9xL5mN8vB3cX7qA4 "'
36
36
const matches = findLikelySecrets ( { text : nonMatchingLine } )
37
37
t . is ( matches . length , 0 )
38
38
} )
39
39
40
40
test ( 'findLikelySecrets - should not match values that are too short' , async ( t ) => {
41
- const matches = findLikelySecrets ( { text : 'aws_key="12345678901 "' } )
41
+ const matches = findLikelySecrets ( { text : 'aws_key="aws_x7B9nM4k "' } )
42
42
t . is ( matches . length , 0 )
43
43
} )
44
44
45
45
test ( 'findLikelySecrets - should return the matched prefix as the key' , async ( t ) => {
46
- const matches = findLikelySecrets ( { text : 'mykey = "github_pat_123456789012345678 "' } )
46
+ const matches = findLikelySecrets ( { text : 'mykey = "github_pat_Kj2P9xL5mN8vB3cX7qA4 "' } )
47
47
t . is ( matches . length , 1 )
48
48
t . is ( matches [ 0 ] . prefix , 'github_pat_' )
49
49
} )
@@ -57,14 +57,12 @@ test('findLikelySecrets - should handle empty or invalid input', async (t) => {
57
57
}
58
58
} )
59
59
60
- test ( 'findLikelySecrets - should match exactly minimum chars after prefix' , async ( t ) => {
61
- const exactMinChars = 'value = "aws_123456789012"' // Exactly 12 chars after prefix
62
- const matches = findLikelySecrets ( { text : exactMinChars } )
63
- t . is ( matches . length , 1 )
64
- } )
65
-
66
60
test ( 'findLikelySecrets - should match different prefixes from LIKELY_SECRET_PREFIXES' , async ( t ) => {
67
- const lines = [ 'key="ghp_123456789012345678"' , 'key="sk_123456789012345678"' , 'key="aws_123456789012345678"' ]
61
+ const lines = [
62
+ 'key="ghp_zR4wY7hQ9sK2nM5vL8xbkokM0vgX"' ,
63
+ 'key="sk_zR4wY7hQ9sK2nM5vL8xbkokM0vgX"' ,
64
+ 'key="aws_zR4wY7hQ9sK2nM5vL8xbkokM0vgX"' ,
65
+ ]
68
66
69
67
lines . forEach ( ( text ) => {
70
68
const matches = findLikelySecrets ( { text } )
@@ -79,14 +77,18 @@ test('findLikelySecrets - should skip safe-listed values', async (t) => {
79
77
} )
80
78
81
79
test ( 'findLikelySecrets - should allow dashes and alphanumeric characters only' , async ( t ) => {
82
- const validLines = [ 'key="aws_abc123-456-789 "' , 'key="ghp_abc-123-def-456 "' ]
80
+ const validLines = [ 'key="aws_zR4wY7hQ-9sK2nM5vL8xbko-kM0vgXKj2P "' , 'key="ghp_zR4wY7hQ9sK2n-M5vL8xbkokM0vgX "' ]
83
81
84
82
validLines . forEach ( ( line ) => {
85
83
const matches = findLikelySecrets ( { text : line } )
86
84
t . is ( matches . length , 1 , `Should match line with dashes: ${ line } ` )
87
85
} )
88
86
89
- const invalidLines = [ 'key="aws_abc123!@#$%^&*()_+"' , 'key="ghp_abc.123_456.789"' , 'key="sk_live_123_456_789"' ]
87
+ const invalidLines = [
88
+ 'key="aws_zR4wY7hQ9sK2nMgX!@#$%^&*()_+"' ,
89
+ 'key="ghp_zR4wY7hQ.9sK2nM5vL8.xbkokM0vgX"' ,
90
+ 'key="sk_R4_wY7hQ9sK2_nM5vL8xbkokM0vgX"' ,
91
+ ]
90
92
91
93
invalidLines . forEach ( ( line ) => {
92
94
const matches = findLikelySecrets ( { text : line } )
@@ -97,16 +99,16 @@ test('findLikelySecrets - should allow dashes and alphanumeric characters only',
97
99
test ( 'findLikelySecrets - should match full secret value against omitValues' , async ( t ) => {
98
100
// Test both partial and full matches to ensure proper behavior
99
101
const partialMatch = findLikelySecrets ( {
100
- text : 'key="aws_123456789012extracharshere "' ,
102
+ text : 'key="aws_zR4wY7hQ9sK2nM5vL8xbkokM0vgX "' ,
101
103
// The omitValue only partially matches the secret - we should still detect the secret
102
- omitValuesFromEnhancedScan : [ 'aws_123456789012 ' ] ,
104
+ omitValuesFromEnhancedScan : [ 'aws_zR4wY7hQ9 ' ] ,
103
105
} )
104
106
t . is ( partialMatch . length , 1 )
105
107
106
108
const fullMatch = findLikelySecrets ( {
107
- text : 'key="aws_123456789012extracharshere "' ,
109
+ text : 'key="aws_zR4wY7hQ9sK2nM5vL8xbkokM0vgX "' ,
108
110
// Omit the full secret value - we should not detect the secret
109
- omitValuesFromEnhancedScan : [ 'aws_123456789012extracharshere ' ] ,
111
+ omitValuesFromEnhancedScan : [ 'aws_zR4wY7hQ9sK2nM5vL8xbkokM0vgX ' ] ,
110
112
} )
111
113
t . is ( fullMatch . length , 0 )
112
114
} )
0 commit comments