MCPcopy Index your code
hub / github.com/coder/coder / TestUserSecretFilePathValid

Function TestUserSecretFilePathValid

codersdk/usersecretvalidation_test.go:171–206  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

169}
170
171func TestUserSecretFilePathValid(t *testing.T) {
172 t.Parallel()
173
174 tests := []struct {
175 name string
176 input string
177 wantErr bool
178 }{
179 // Valid paths.
180 {name: "TildePath", input: "~/foo"},
181 {name: "TildeSSH", input: "~/.ssh/id_rsa"},
182 {name: "AbsolutePath", input: "/home/coder/.ssh/id_rsa"},
183 {name: "RootPath", input: "/"},
184 {name: "Empty", input: ""},
185
186 // Invalid paths.
187 {name: "BareRelative", input: "foo/bar", wantErr: true},
188 {name: "DotRelative", input: ".ssh/id_rsa", wantErr: true},
189 {name: "JustFilename", input: "credentials", wantErr: true},
190 {name: "TildeNoSlash", input: "~foo", wantErr: true},
191 {name: "NullByte", input: "/home/\x00coder", wantErr: true},
192 {name: "TooLong", input: "/" + strings.Repeat("a", 4096), wantErr: true},
193 }
194
195 for _, tt := range tests {
196 t.Run(tt.name, func(t *testing.T) {
197 t.Parallel()
198 err := codersdk.UserSecretFilePathValid(tt.input)
199 if tt.wantErr {
200 assert.Error(t, err)
201 } else {
202 assert.NoError(t, err)
203 }
204 })
205 }
206}
207
208func TestUserSecretValueValid(t *testing.T) {
209 t.Parallel()

Callers

nothing calls this directly

Calls 3

UserSecretFilePathValidFunction · 0.92
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected