-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
admin: reject non-canonical config array indices #7592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
36a0e79
7f61013
2968378
99c8a4f
2ee79d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ import ( | |
| "crypto/x509" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "maps" | ||
| "net/http" | ||
| "net/http/httptest" | ||
|
|
@@ -956,3 +957,37 @@ MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDRS0LmTwUT0iwP | |
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestUnsyncedConfigAccessCanonicalArrayIndices(t *testing.T) { | ||
| rawCfg = map[string]any{ | ||
| rawConfigKey: map[string]any{ | ||
| "list": []any{"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"}, | ||
| }, | ||
| } | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| path string | ||
| wantErr bool | ||
| }{ | ||
| {name: "allow zero", path: "/" + rawConfigKey + "/list/0"}, | ||
| {name: "allow one", path: "/" + rawConfigKey + "/list/1"}, | ||
| {name: "allow ten", path: "/" + rawConfigKey + "/list/10"}, | ||
| {name: "reject leading zero", path: "/" + rawConfigKey + "/list/01", wantErr: true}, | ||
| {name: "reject multiple leading zeros", path: "/" + rawConfigKey + "/list/002", wantErr: true}, | ||
| {name: "reject plus sign", path: "/" + rawConfigKey + "/list/+1", wantErr: true}, | ||
| {name: "reject negative zero", path: "/" + rawConfigKey + "/list/-0", wantErr: true}, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| err := unsyncedConfigAccess(http.MethodGet, tc.path, nil, io.Discard) | ||
| if tc.wantErr && err == nil { | ||
| t.Fatal("expected error, got nil") | ||
| } | ||
| if !tc.wantErr && err != nil { | ||
| t.Fatalf("expected no error, got %v", err) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error messages should describe which test case (numerical index) and the name of the test case (the name field), and what the input was, and what was expected, and what the actual output was. Also, probably don't use Fatal. Use Error.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the canonical array index regression test diagnostics to include the test index, case name, input path, Validation:
|
||
| } | ||
| }) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.