mirror of
https://github.com/smallstep/certificates.git
synced 2024-11-15 18:12:59 +00:00
Sanitize usernames
This commit is contained in:
parent
bf364f0a5f
commit
8b1ab30212
@ -358,7 +358,7 @@ func DefaultIdentityFunc(ctx context.Context, p Interface, email string, usernam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
usernames = append(usernames, email)
|
usernames = append(usernames, email)
|
||||||
// Some remove duplicate function should be added
|
usernames = SanitizeStringSlices(usernames)
|
||||||
return &Identity{
|
return &Identity{
|
||||||
Usernames: usernames,
|
Usernames: usernames,
|
||||||
}, nil
|
}, nil
|
||||||
@ -367,6 +367,21 @@ func DefaultIdentityFunc(ctx context.Context, p Interface, email string, usernam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SanitizeStringSlices(original []string) []string {
|
||||||
|
output := []string{}
|
||||||
|
seen := make(map[string]bool)
|
||||||
|
for _, entry := range original {
|
||||||
|
if entry == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, value := seen[entry]; !value {
|
||||||
|
seen[entry] = true
|
||||||
|
output = append(output, entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
// MockProvisioner for testing
|
// MockProvisioner for testing
|
||||||
type MockProvisioner struct {
|
type MockProvisioner struct {
|
||||||
Mret1, Mret2, Mret3 interface{}
|
Mret1, Mret2, Mret3 interface{}
|
||||||
|
Loading…
Reference in New Issue
Block a user