Debian Codegraph @

pkg/detectors/aws/aws_secret_key_detector_test.go

raw symbols SCIP
1 package aws
2
3 import (
4 "testing"
5
6 "github.com/DefangLabs/secret-detector/pkg/detectors/tests"
7 )
8
9 var secretKeyTestCases = []tests.TestCase{
10
11 {"valid key - lowercase prefix", `aws"12345+67890/abcdefghijklm+NOPQRSTUVWXYZ+"`, true},
12 {"valid key - uppercase prefix", `AWS"12345+67890/abcdefghijklm+NOPQRSTUVWXYZ+"`, true},
13 {"valid key - extended prefix", `aws="12345+67890/abcdefghijklm+NOPQRSTUVWXYZ+"`, true},
14 {"valid key - max length extended prefix", `aws1234567890abcdefghij"12345+67890/abcdefghijklm+NOPQRSTUVWXYZ+"`, true},
15 {"valid key - single quoted suffix", `aws'12345+67890/abcdefghijklm+NOPQRSTUVWXYZ+'`, true},
16
17 {"missing prefix", `"12345+67890/abcdefghijklm+NOPQRSTUVWXYZ+"`, false},
18 {"illegal prefix", `xxx"12345+67890/abcdefghijklm+NOPQRSTUVWXYZ+"`, false},
19 {"too long prefix", `aws1234567890abcdefghijk"12345+67890/abcdefghijklm+NOPQRSTUVWXYZ+"`, false},
20
21 {"missing suffix", `aws`, false},
22 {"illegal characters suffix", `aws"12345+67890/abcdefghijklm+NOPQRSTUVWXYZ="`, false},
23 {"missing quotes", `aws12345+67890/abcdefghijklm+NOPQRSTUVWXYZ+`, false},
24 {"suffix too long", `aws"12345+67890/abcdefghijklm+NOPQRSTUVWXYZ+1"`, false},
25 {"suffix too short", `aws"12345+67890/abcdefghijklm+NOPQRSTUVWXYZ"`, false},
26 {"empty input", "", false},
27 }
28
29 var secretKeyDetector = NewSecretKeyDetector()
30
31 func TestSecretKeyDetector_Scan(t *testing.T) {
32 tests.TestScan(t, secretKeyDetector, secretKeyTestCases)
33 }
34
35 func TestSecretKeyDetector_ScanWithKey(t *testing.T) {
36 tests.TestScanWithKey(t, secretKeyDetector, secretKeyTestCases)
37 }
38
39 func TestSecretKeyDetector_ScanWithMultipleMatches(t *testing.T) {
40 tests.TestScanWithMultipleMatches(t, secretKeyDetector, secretKeyTestCases)
41 }
42
43 func TestSecretKeyDetector_ScanMap(t *testing.T) {
44 tests.TestScanMap(t, secretKeyDetector, secretKeyTestCases)
45 }