Skip to content

Commit 3821403

Browse files
committed
test: add testcase for minimum AsymmetricPrivateKey secret length
1 parent 2160e7b commit 3821403

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

pkg/fanal/secret/scanner_test.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,43 @@ func TestSecretScanner(t *testing.T) {
575575
},
576576
},
577577
}
578+
wantFindingMinimumAsymmSecretKey := types.SecretFinding{
579+
RuleID: "private-key",
580+
Category: secret.CategoryAsymmetricPrivateKey,
581+
Title: "Asymmetric Private Key",
582+
Severity: "HIGH",
583+
StartLine: 6,
584+
EndLine: 6,
585+
Match: "-----BEGIN PRIVATE KEY-----********************************-----END PRIVATE KEY-----",
586+
Code: types.Code{
587+
Lines: []types.Line{
588+
{
589+
Number: 4,
590+
Content: "",
591+
Highlighted: "",
592+
IsCause: false,
593+
FirstCause: false,
594+
LastCause: false,
595+
},
596+
{
597+
Number: 5,
598+
Content: "## Theoretically Asymmetric Private Key of minimum length (RSA 128 bits)",
599+
Highlighted: "## Theoretically Asymmetric Private Key of minimum length (RSA 128 bits)",
600+
IsCause: false,
601+
FirstCause: false,
602+
LastCause: false,
603+
},
604+
{
605+
Number: 6,
606+
Content: "-----BEGIN PRIVATE KEY-----********************************-----END PRIVATE KEY-----",
607+
Highlighted: "-----BEGIN PRIVATE KEY-----********************************-----END PRIVATE KEY-----",
608+
IsCause: true,
609+
FirstCause: true,
610+
LastCause: true,
611+
},
612+
},
613+
},
614+
}
578615
wantFindingAlibabaAccessKeyId := types.SecretFinding{
579616
RuleID: "alibaba-access-key-id",
580617
Category: secret.CategoryAlibaba,
@@ -1300,7 +1337,7 @@ func TestSecretScanner(t *testing.T) {
13001337
inputFilePath: "testdata/asymmetric-private-key.txt",
13011338
want: types.Secret{
13021339
FilePath: "testdata/asymmetric-private-key.txt",
1303-
Findings: []types.SecretFinding{wantFindingAsymmSecretKey},
1340+
Findings: []types.SecretFinding{wantFindingMinimumAsymmSecretKey, wantFindingAsymmSecretKey},
13041341
},
13051342
},
13061343
{

pkg/fanal/secret/testdata/asymmetric-private-key.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ MIIEowIBAAKCAQEAu/Nua0/1y08gkbnBfKd6VDHia8Na0ATgMQqZ4YEbi/t73g84IEPQPkLbPF3X De+
33
vKftqLPCPbAPPxkaqQi0Ico/1fzD10znRy66aosPBrbleduiynubgk+GVm9y/R6bDYhR
44
-----END RSA PRIVATE KEY-----
55

6-
-----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----
6+
-----BEGIN RSA PRIVATE KEY----- -----END RSA PRIVATE KEY-----
7+
8+
## Theoretically Asymmetric Private Key of minimum length (RSA 128 bits)
9+
-----BEGIN PRIVATE KEY-----4c6f4a5cb2d395f828384c2ab29d1f55-----END PRIVATE KEY-----

0 commit comments

Comments
 (0)