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-") {
info.StackID = ns[6:]
if len(info.StackID) < 1 {
stackIDStr := ns[6:]
stackID, err := strconv.Atoi(stackIDStr)
if err != nil || stackID < 1 {
return info, fmt.Errorf("invalid stack id")
}
info.StackID = stackIDStr
info.OrgID = 1
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",
expected: request.NamespaceInfo{
OrgID: 1,
StackID: "abcdef",
OrgID: -1,
},
},
{
name: "invalid stack id",
name: "invalid stack id (must be provided)",
namespace: "stack-",
expectErr: true,
expected: request.NamespaceInfo{
@ -93,12 +93,19 @@ func TestParseNamespace(t *testing.T) {
},
},
{
name: "invalid stack id (too short)",
namespace: "stack-",
name: "invalid stack id (cannot be 0)",
namespace: "stack-0",
expectErr: true,
expected: request.NamespaceInfo{
OrgID: -1,
StackID: "",
OrgID: -1,
},
},
{
name: "valid stack",
namespace: "stack-1",
expected: request.NamespaceInfo{
OrgID: 1,
StackID: "1",
},
},
{