From 65d690074cd258585c752f659ae465dd87bff564 Mon Sep 17 00:00:00 2001 From: Amir Raminfar Date: Mon, 29 Sep 2025 13:04:18 -0700 Subject: [PATCH] feat: support for dozzle_* roles (#4153) --- internal/auth/roles.go | 10 +++++----- internal/auth/roles_test.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/internal/auth/roles.go b/internal/auth/roles.go index bf6e3ca7..22ee99ae 100644 --- a/internal/auth/roles.go +++ b/internal/auth/roles.go @@ -43,15 +43,15 @@ func ParseRole(input string) Role { for _, r := range parts { role := strings.TrimSpace(strings.ToLower(r)) switch role { - case "shell": + case "shell", "dozzle_shell": roles |= Shell - case "actions": + case "actions", "dozzle_actions": roles |= Actions - case "download": + case "download", "dozzle_download": roles |= Download - case "none": + case "none", "dozzle_none": return None - case "all": + case "all", "dozzle_all": return All default: log.Debug().Str("role", role).Msg("invalid role") diff --git a/internal/auth/roles_test.go b/internal/auth/roles_test.go index 9c971021..3257733c 100644 --- a/internal/auth/roles_test.go +++ b/internal/auth/roles_test.go @@ -17,26 +17,42 @@ func TestParseRole(t *testing.T) { {"None role", "none", None}, {"All role", "all", All}, + // Single dozzle_ prefixed role tests + {"Single dozzle_shell role", "dozzle_shell", Shell}, + {"Single dozzle_actions role", "dozzle_actions", Actions}, + {"Single dozzle_download role", "dozzle_download", Download}, + {"Dozzle_none role", "dozzle_none", None}, + {"Dozzle_all role", "dozzle_all", All}, + // Case insensitive tests {"Shell uppercase", "SHELL", Shell}, {"Actions mixed case", "AcTiOnS", Actions}, {"Download with spaces", " download ", Download}, + {"Dozzle_shell uppercase", "DOZZLE_SHELL", Shell}, + {"Dozzle_actions mixed case", "DoZzLe_AcTiOnS", Actions}, + {"Dozzle_download with spaces", " dozzle_download ", Download}, // Multiple roles with comma separator {"Shell and actions", "shell,actions", Shell | Actions}, {"All three roles", "shell,actions,download", Shell | Actions | Download}, {"Roles with spaces", "shell , actions , download", Shell | Actions | Download}, + {"Dozzle roles with comma", "dozzle_shell,dozzle_actions", Shell | Actions}, + {"Mixed dozzle and regular", "shell,dozzle_actions,download", Shell | Actions | Download}, // Multiple roles with pipe separator {"Shell and actions with pipe", "shell|actions", Shell | Actions}, {"All three with pipe", "shell|actions|download", Shell | Actions | Download}, {"Mixed separators", "shell,actions|download", Shell | Actions | Download}, + {"Dozzle roles with pipe", "dozzle_shell|dozzle_actions", Shell | Actions}, // JSON format tests {"JSON single role", `["shell"]`, Shell}, {"JSON multiple roles", `["shell", "actions"]`, Shell | Actions}, {"JSON all roles", `["shell", "actions", "download"]`, Shell | Actions | Download}, {"JSON with spaces", ` ["shell", "actions"] `, Shell | Actions}, + {"JSON single dozzle role", `["dozzle_shell"]`, Shell}, + {"JSON multiple dozzle roles", `["dozzle_shell", "dozzle_actions"]`, Shell | Actions}, + {"JSON mixed dozzle and regular", `["shell", "dozzle_actions"]`, Shell | Actions}, // Edge cases {"Empty string", "", None}, @@ -45,6 +61,8 @@ func TestParseRole(t *testing.T) { {"Mixed valid and invalid", "shell,invalid,actions", Shell | Actions}, {"None overrides others", "shell,none,actions", None}, {"All overrides others", "shell,all,actions", All}, + {"Dozzle_none overrides others", "dozzle_shell,dozzle_none,dozzle_actions", None}, + {"Dozzle_all overrides others", "dozzle_shell,dozzle_all,dozzle_actions", All}, // Invalid JSON {"Invalid JSON format", `["shell"`, None},