Skip to content

Commit cb69a01

Browse files
committed
update test cases
1 parent 865987e commit cb69a01

File tree

1 file changed

+67
-27
lines changed

1 file changed

+67
-27
lines changed

pkg/detectors/phraseaccesstoken/phraseaccesstoken_test.go

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,49 +18,89 @@ func TestPhrase_Pattern(t *testing.T) {
1818
want []string
1919
}{
2020
{
21-
name: "valid pattern - with keyword phrase",
22-
input: "phrase token = 1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890",
23-
want: []string{"1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890"},
21+
name: "valid pattern - with keyword phrase",
22+
input: `
23+
[INFO] Initializing authentication
24+
[DEBUG] phrase token = 1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890
25+
[Info] Response received: 200 OK
26+
`,
27+
want: []string{"1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890"},
2428
},
2529
{
26-
name: "valid pattern - ignore duplicate",
27-
input: "phrase token = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890' | '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'",
28-
want: []string{"1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890"},
30+
name: "valid pattern - ignore duplicate",
31+
input: `
32+
[INFO] Processing authentication tokens
33+
[DEBUG] phrase token = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'
34+
[WARN] Duplicate token found: phrase token = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'
35+
[Info] Response received: 200 OK
36+
`,
37+
want: []string{"1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890"},
2938
},
3039
{
31-
name: "valid pattern - key out of prefix range",
32-
input: "phrase keyword is not close to the real key in the data\n = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'",
33-
want: []string{},
40+
name: "valid pattern - key out of prefix range",
41+
input: `
42+
[INFO] Starting system initialization
43+
[DEBUG] phrase keyword is not close to the real key in the data
44+
[DEBUG] Configuration loaded successfully
45+
[DEBUG] Secret key = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'
46+
[ERROR] Response received: 400 BadRequest
47+
`,
48+
want: nil,
3449
},
3550
{
36-
name: "invalid pattern",
37-
input: "phrase = 7cf4135a4e7f7ac228d36f210f151917a86f5dbd6",
38-
want: []string{},
51+
name: "invalid pattern",
52+
input: `
53+
[INFO] Loading configuration
54+
[DEBUG] phrase = 7cf4135a4e7f7ac228d36f210f151917a86f5dbd6
55+
[ERROR] Response received: 400 BadRequest
56+
`,
57+
want: nil,
3958
},
4059
{
41-
name: "finds all valid matches",
42-
input: "phrase token1 = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'\n phrase token2 = 'abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890'",
43-
want: []string{"1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890", "abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"},
60+
name: "finds all valid matches",
61+
input: `
62+
[INFO] Multi-token authentication
63+
[DEBUG] phrase token1 = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'
64+
[DEBUG] phrase token2 = 'abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890'
65+
[Info] Response received: 200 OK
66+
`,
67+
want: []string{"1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890", "abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"},
4468
},
4569
{
46-
name: "invalid pattern - too short",
47-
input: "phrase = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef12345678'",
48-
want: []string{},
70+
name: "invalid pattern - too short",
71+
input: `
72+
[INFO] Processing short token
73+
[DEBUG] phrase = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef12345678'
74+
[ERROR] Response received: 400 BadRequest
75+
`,
76+
want: nil,
4977
},
5078
{
51-
name: "invalid pattern - too long",
52-
input: "phrase = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef123456789012'",
53-
want: []string{},
79+
name: "invalid pattern - too long",
80+
input: `
81+
[INFO] Processing long token
82+
[DEBUG] phrase = '1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef123456789012'
83+
[ERROR] Response received: 400 BadRequest
84+
`,
85+
want: nil,
5486
},
5587
{
56-
name: "invalid pattern - contains uppercase",
57-
input: "phrase = '1A2B3C4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'",
58-
want: []string{},
88+
name: "invalid pattern - contains uppercase",
89+
input: `
90+
[INFO] Processing token with uppercase
91+
[DEBUG] phrase = '1A2B3C4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'
92+
[ERROR] Response received: 400 BadRequest
93+
`,
94+
want: nil,
5995
},
6096
{
61-
name: "invalid pattern - contains special characters",
62-
input: "phrase = '1a2b3c4d-e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'",
63-
want: []string{},
97+
name: "invalid pattern - contains special characters",
98+
input: `
99+
[INFO] Processing token with special chars
100+
[DEBUG] phrase = '1a2b3c4d-e6f7890abcdef1234567890abcdef1234567890abcdef1234567890'
101+
[ERROR] Response received: 400 BadRequest
102+
`,
103+
want: nil,
64104
},
65105
}
66106

0 commit comments

Comments
 (0)