20 lines
812 B
Go
20 lines
812 B
Go
package testutil
|
|
|
|
import "regexp"
|
|
|
|
var (
|
|
// emailLike matches an address anywhere in a text, for example inside a
|
|
// metric label value or a log line.
|
|
emailLike = regexp.MustCompile(`[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}`)
|
|
// uuidLike matches the canonical text form of a UUID, the form of user,
|
|
// delivery, attempt, and document IDs.
|
|
uuidLike = regexp.MustCompile(`[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}`)
|
|
)
|
|
|
|
// FindPersonalIdentifiers returns every email-like and UUID-like substring of
|
|
// text. Tests use it on a metrics exposition or a log to prove that no
|
|
// address or entity ID leaked into labels or messages.
|
|
func FindPersonalIdentifiers(text string) []string {
|
|
return append(emailLike.FindAllString(text, -1), uuidLike.FindAllString(text, -1)...)
|
|
}
|