Debian Codegraph @

pkg/detectors/generic/url_password_detector_test.go

raw symbols SCIP
1 package generic
2
3 import (
4 "testing"
5
6 "github.com/DefangLabs/secret-detector/pkg/detectors/tests"
7 )
8
9 var urlPwdTestCases = []tests.TestCase{
10 {"url with pwd", "https://user:[email protected]", true},
11 {"shortest url with pwd", "aa://u:p@d", true},
12 {"long url with pwd", "bitcoin://very-very-very-very-very-very-very-very-very-long-user:very-very-very-very-very-very-very-very-very-long-pass@very-very-very-very-very-very-very-very-very-long-subdomain.very-very-very-very-very-very-very-very-very-long-domain.com:8082/very-very-very-very-very-very-very-very-very-long-path.html?param1=value1&param2=value2#fragment", true},
13 {"url with email user", "smtp://[email protected]:[email protected]:465/", true},
14
15 {"missing scheme", "user:[email protected]", false},
16 {"missing domain", "https://user:p455w0rd@", false},
17 {"empty user", "https://:[email protected]", true},
18 {"empty pwd", "https://user:@example.com", false},
19 {"missing pwd", "https://[email protected]", false},
20 {"missing user & pwd", "https://example.com", false},
21 {"variable pwd", "https://user:[email protected]", false},
22 {"illegal url characters", "https://user:{pwd}@example.com", false},
23
24 {"empty input", "", false},
25 }
26
27 var urlPwdDetector = NewURLPasswordDetector()
28
29 func TestURLPasswordDetector_Scan(t *testing.T) {
30 tests.TestScan(t, urlPwdDetector, urlPwdTestCases)
31 }
32
33 func TestURLPasswordDetector_ScanWithKey(t *testing.T) {
34 tests.TestScanWithKey(t, urlPwdDetector, urlPwdTestCases)
35 }
36
37 func TestURLPasswordDetector_ScanWithMultipleMatches(t *testing.T) {
38 tests.TestScanWithMultipleMatches(t, urlPwdDetector, urlPwdTestCases)
39 }
40
41 func TestURLPasswordDetector_ScanMap(t *testing.T) {
42 tests.TestScanMap(t, urlPwdDetector, urlPwdTestCases)
43 }