Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added pattern test cases [WIP] #3539

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kashifkhan0771
Copy link
Contributor

Description:

Added pattern test cases for Alphabet A detectors
Separated integration tests

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

var (
validPattern = `
apiflash_key: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
apiflash_url: abc123XYZ456def789ghijklm
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the documentation, this parameter should be an actual URL, not a plain text string limited from 21 to 30 characters.

The current regex in use is: urlPat: \b([a-zA-Z0-9\S]{21,30})\b.

Comment on lines +16 to +28
complexPattern = `
func main() {
url := "https://api.example.com/v1/resource"

// Create a new request with the secret as a header
req, err := http.NewRequest("POST", url, bytes.NewBuffer([]byte("{}")))
if err != nil {
fmt.Println("Error creating request:", err)
return
}

apactaSecret := "Bearer abcd1234-ef56-gh78-ij90-klmn1234opqr"
req.Header.Set("Authorization", apactaSecret)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback needed: How does this test example look? I aimed to create something that reflects a real-world scenario. If it looks good, I can use similar examples in the other test cases.

keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"apimatic"}) + `\b([a-zA-Z0-9]{3,20}@[a-zA-Z0-9]{2,12}.[a-zA-Z0-9]{2,5})\b`)
passPat = regexp.MustCompile(detectors.PrefixRegex([]string{"apimatic"}) + `\b([a-z0-9-\S]{8,32})\b`)
apiKeyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"apimatic", "apikey"}) + `\b([a-zA-Z0-9_-]{64})\b`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I somehow discovered that APIMatic is no longer using these for authentication and now utilizing an Auth Key. Additionally, the API we were using earlier appears to no longer exist; it may have been available before, but the path seems to have changed in their documentation. I confirmed these updates through some local testing.

Documentation links are added in code comments, if you wanna take a look 🕵🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Test:
Screenshot from 2024-10-31 19-25-26
Bad Test:
Screenshot from 2024-10-31 19-26-53

@@ -22,7 +22,7 @@ var (
client = common.SaneHttpClient()

// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"apimetrics"}) + `\b([a-bA-Z0-9\S]{32})\b`)
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"apimetrics"}) + `\b([a-zA-Z0-9]{32})\b`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved APIMetrics detector regex 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant