| 1 |
package basicauth |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"github.com/DefangLabs/secret-detector/pkg/detectors/tests" |
| 7 |
) |
| 8 |
|
| 9 |
var testCases = []tests.TestCase{ |
| 10 |
|
| 11 |
{"valid token - minimal length", "basic dTpw", true}, |
| 12 |
{"valid token - with padding", "basic ZDp6cg==", true}, |
| 13 |
{"valid token - long", "Basic dXNlcm5mc2RzZ2dmc2dzZmdzZmFtZTpwZ3NzZmdzZ3Nnc2RndGFlZ2FnYXNzd29yZGRkZGQ=", true}, |
| 14 |
{"valid token - with header key", "Authorization: Basic YTpn", true}, |
| 15 |
{"valid token - with quoted header key", `"Authorization": "Basic YTpn"`, true}, |
| 16 |
|
| 17 |
{"invalid token - minimal length with invalid base 64", "basic Og=", false}, |
| 18 |
{"invalid token - without padding", "basic ZDp6cg", false}, |
| 19 |
{"invalid token - without : inside the base64", "basic YWRkc2Y6", false}, |
| 20 |
{"token too short", "basic O", false}, |
| 21 |
{"token too short with padding", "basic O==", false}, |
| 22 |
{"missing basic auth scheme", "YWRtaW46YWRtaW4=", false}, |
| 23 |
{"wrong auth scheme", "bearer YWRtaW46YWRtaW4=", false}, |
| 24 |
{"illegal padding position", "basic xy=z", false}, |
| 25 |
{"illegal characters", "basic xy.z", false}, |
| 26 |
{"empty input", "", false}, |
| 27 |
} |
| 28 |
|
| 29 |
var basicAuthDetector = NewDetector() |
| 30 |
|
| 31 |
func TestScan(t *testing.T) { |
| 32 |
tests.TestScan(t, basicAuthDetector, testCases) |
| 33 |
} |
| 34 |
|
| 35 |
func TestScanWithKey(t *testing.T) { |
| 36 |
tests.TestScanWithKey(t, basicAuthDetector, testCases) |
| 37 |
} |
| 38 |
|
| 39 |
func TestScanWithMultipleMatches(t *testing.T) { |
| 40 |
tests.TestScanWithMultipleMatches(t, basicAuthDetector, testCases) |
| 41 |
} |
| 42 |
|
| 43 |
func TestScanMap(t *testing.T) { |
| 44 |
tests.TestScanMap(t, basicAuthDetector, testCases) |
| 45 |
} |