(t *testing.T)
| 169 | } |
| 170 | |
| 171 | func 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 | |
| 208 | func TestUserSecretValueValid(t *testing.T) { |
| 209 | t.Parallel() |
nothing calls this directly
no test coverage detected