Skip to content

Commit

Permalink
fix: validate that namespace ID is int32
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Mar 10, 2023
1 parent a4b41bd commit f3c5245
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .schema/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"id": {
"type": "integer",
"title": "The unique ID of the namespace. Can not be changed once set.",
"minimum": 0
"minimum": 0,
"maximum": 2147483647
},
"config": {
"type": "object",
Expand Down
3 changes: 2 additions & 1 deletion embedx/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"id": {
"type": "integer",
"title": "The unique ID of the namespace. Can not be changed once set.",
"minimum": 0
"minimum": 0,
"maximum": 2147483647
},
"config": {
"type": "object",
Expand Down
20 changes: 20 additions & 0 deletions internal/driver/config/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,26 @@ namespaces: file://%s`,
})
}

func TestInvalidNamespaceConfig(t *testing.T) {
config := createFile(t, `
dsn: memory
namespaces:
- name: n0
id: 2147483648
`)
hook := test.Hook{}
l := logrusx.New("test", "today", logrusx.WithHook(&hook))
_, err := NewDefault(
context.Background(),
pflag.NewFlagSet("test", pflag.ContinueOnError),
l,
configx.WithConfigFiles(config),
)

assert.Error(t, err)
assert.Contains(t, err.Error(), "must be <= 2.147483647e+09 but found 2147483648")
}

// Test that the namespaces can be configured through the Ory Permission
// Language.
func TestRewritesNamespaceConfig(t *testing.T) {
Expand Down

0 comments on commit f3c5245

Please sign in to comment.