K8s: Update stack id validation (#82275)

This commit is contained in:
Stephanie Hingtgen 2024-02-09 13:51:00 -06:00 committed by GitHub
parent c9593531ef
commit 87c3d0fb6a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 10 deletions

View File

@ -67,10 +67,12 @@ func ParseNamespace(ns string) (NamespaceInfo, error) {
} }
if strings.HasPrefix(ns, "stack-") { if strings.HasPrefix(ns, "stack-") {
info.StackID = ns[6:] stackIDStr := ns[6:]
if len(info.StackID) < 1 { stackID, err := strconv.Atoi(stackIDStr)
if err != nil || stackID < 1 {
return info, fmt.Errorf("invalid stack id") return info, fmt.Errorf("invalid stack id")
} }
info.StackID = stackIDStr
info.OrgID = 1 info.OrgID = 1
return info, nil return info, nil
} }

View File

@ -77,15 +77,15 @@ func TestParseNamespace(t *testing.T) {
}, },
}, },
{ {
name: "valid stack", name: "invalid stack id (must be an int)",
expectErr: true,
namespace: "stack-abcdef", namespace: "stack-abcdef",
expected: request.NamespaceInfo{ expected: request.NamespaceInfo{
OrgID: 1, OrgID: -1,
StackID: "abcdef",
}, },
}, },
{ {
name: "invalid stack id", name: "invalid stack id (must be provided)",
namespace: "stack-", namespace: "stack-",
expectErr: true, expectErr: true,
expected: request.NamespaceInfo{ expected: request.NamespaceInfo{
@ -93,12 +93,19 @@ func TestParseNamespace(t *testing.T) {
}, },
}, },
{ {
name: "invalid stack id (too short)", name: "invalid stack id (cannot be 0)",
namespace: "stack-", namespace: "stack-0",
expectErr: true, expectErr: true,
expected: request.NamespaceInfo{ expected: request.NamespaceInfo{
OrgID: -1, OrgID: -1,
StackID: "", },
},
{
name: "valid stack",
namespace: "stack-1",
expected: request.NamespaceInfo{
OrgID: 1,
StackID: "1",
}, },
}, },
{ {