Add character levels and permanent player titles
This commit is contained in:
@@ -22,7 +22,7 @@ func (h *HTTP) admin(w http.ResponseWriter, r *http.Request) (string, bool) {
|
||||
return "", false
|
||||
}
|
||||
if !h.auth.isAdmin(r) {
|
||||
fail(w, 403, "Administrator access required. Sign in again with the configured Keycloak role.")
|
||||
fail(w, 403, "Administrator access required. Your Keycloak ID token must include the role \""+h.auth.AdminRole+"\". Sign in again after assigning it.")
|
||||
return "", false
|
||||
}
|
||||
return account, true
|
||||
|
||||
@@ -115,3 +115,28 @@ func TestKeycloakRolesAndReturnURL(t *testing.T) {
|
||||
t.Fatal("game return lost or untrusted query retained")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminRoleClaimsMatchExactlyAndOnlyOwnClient(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name, raw string
|
||||
want bool
|
||||
}{
|
||||
{"realm role", `{"realm_access":{"roles":["aeternalis-admin"]}}`, true},
|
||||
{"client role", `{"resource_access":{"game":{"roles":["aeternalis-admin"]}}}`, true},
|
||||
{"other client", `{"resource_access":{"other":{"roles":["aeternalis-admin"]}}}`, false},
|
||||
{"player", `{"realm_access":{"roles":["player"]}}`, false},
|
||||
{"case mismatch", `{"realm_access":{"roles":["Aeternalis-admin"]}}`, false},
|
||||
{"substring", `{"realm_access":{"roles":["not-aeternalis-admin"]}}`, false},
|
||||
{"missing", `{}`, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
var claims roleClaims
|
||||
if err := json.Unmarshal([]byte(tc.raw), &claims); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if claims.admin("aeternalis-admin", "game") != tc.want {
|
||||
t.Fatal("incorrect role access")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,6 +177,7 @@ func (s *Service) join(ctx context.Context, account, name, claim string) (p.Char
|
||||
view := c.View
|
||||
view.Inventory = maps.Clone(view.Inventory)
|
||||
view.Skills = maps.Clone(view.Skills)
|
||||
view.Titles = append([]p.TitleAward{}, view.Titles...)
|
||||
return view, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user