mediaauth was its own package only because "auth" was already taken by this package's lower-level Store/User/Role layer. Since mediaauth is no longer media-family-specific (see the earlier "unified auth proxy" generalization), it now lives directly in this package instead, renamed where it collided with existing exports: mediaauth.User -> ProxyUser, mediaauth.Store -> ProxyStore (this package's own local-account Store is unrelated and keeps its name). Service/New/NewWithStore/UserFromContext and the rest keep their names. mediacore.go updated to match. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
29 lines
905 B
Go
29 lines
905 B
Go
package auth
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeProxyCredentials(t *testing.T) {
|
|
email, username, password, err := normalizeProxyCredentials(" User@Example.com ", "user", "correct horse battery staple")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if email != "user@example.com" || username != "user" || password == "" {
|
|
t.Fatalf("normalized credentials = %q, %q, %q", email, username, password)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeProxyCredentialsAllowsAdminEmailOnly(t *testing.T) {
|
|
if _, _, _, err := normalizeProxyCredentials("admin@example.com", "", "correct horse battery staple"); err != nil {
|
|
t.Fatalf("empty optional username rejected: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestNormalizePlatformRole(t *testing.T) {
|
|
if normalizePlatformRole("MODERATOR") != "moderator" {
|
|
t.Fatal("moderator role was not normalized")
|
|
}
|
|
if normalizePlatformRole("unknown") != "user" {
|
|
t.Fatal("unknown role was not reduced to user")
|
|
}
|
|
}
|