MCPcopy Create free account
hub / github.com/AbelChe/evil_minio / TestIsValidObjectName

Function TestIsValidObjectName

cmd/object-api-utils_test.go:152–209  ·  view source on GitHub ↗

Tests for validate object name.

(t *testing.T)

Source from the content-addressed store, hash-verified

150
151// Tests for validate object name.
152func TestIsValidObjectName(t *testing.T) {
153 testCases := []struct {
154 objectName string
155 shouldPass bool
156 }{
157 // cases which should pass the test.
158 // passing in valid object name.
159 {"object", true},
160 {"The Shining Script <v1>.pdf", true},
161 {"Cost Benefit Analysis (2009-2010).pptx", true},
162 {"117Gn8rfHL2ACARPAhaFd0AGzic9pUbIA/5OCn5A", true},
163 {"SHØRT", true},
164 {"f*le", true},
165 {"contains-^-carret", true},
166 {"contains-|-pipe", true},
167 {"contains-`-tick", true},
168 {"..test", true},
169 {".. test", true},
170 {". test", true},
171 {".test", true},
172 {"There are far too many object names, and far too few bucket names!", true},
173 {"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~/!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~)", true},
174 {"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", true},
175 {"␀␁␂␃␄␅␆␇␈␉␊␋␌␍␎␏␐␑␒␓␔␕␖␗␘␙␚␛␜␝␞␟␡", true},
176 {"trailing VT␋/trailing VT␋", true},
177 {"␋leading VT/␋leading VT", true},
178 {"~leading tilde", true},
179 {"\rleading CR", true},
180 {"\nleading LF", true},
181 {"\tleading HT", true},
182 {"trailing CR\r", true},
183 {"trailing LF\n", true},
184 {"trailing HT\t", true},
185 // cases for which test should fail.
186 // passing invalid object names.
187 {"", false},
188 {"a/b/c/", false},
189 {"../../etc", false},
190 {"../../", false},
191 {"/../../etc", false},
192 {" ../etc", false},
193 {"./././", false},
194 {"./etc", false},
195 {`contains//double/forwardslash`, false},
196 {`//contains/double-forwardslash-prefix`, false},
197 {string([]byte{0xff, 0xfe, 0xfd}), false},
198 }
199
200 for i, testCase := range testCases {
201 isValidObjectName := IsValidObjectName(testCase.objectName)
202 if testCase.shouldPass && !isValidObjectName {
203 t.Errorf("Test case %d: Expected \"%s\" to be a valid object name", i+1, testCase.objectName)
204 }
205 if !testCase.shouldPass && isValidObjectName {
206 t.Errorf("Test case %d: Expected object name \"%s\" to be invalid", i+1, testCase.objectName)
207 }
208 }
209}

Callers

nothing calls this directly

Calls 1

IsValidObjectNameFunction · 0.85

Tested by

no test coverage detected