(t *testing.T)
| 239 | } |
| 240 | |
| 241 | func TestValidateSectorIdentifierURL(t *testing.T) { |
| 242 | reg := testhelpers.NewRegistryMemory(t) |
| 243 | var payload string |
| 244 | |
| 245 | var h http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) { |
| 246 | _, _ = w.Write([]byte(payload)) |
| 247 | } |
| 248 | ts := httptest.NewTLSServer(h) |
| 249 | defer ts.Close() |
| 250 | |
| 251 | v := NewValidator(&fakeHTTP{RegistrySQL: reg, c: ts.Client()}) |
| 252 | for k, tc := range []struct { |
| 253 | p string |
| 254 | r []string |
| 255 | u string |
| 256 | expectErr bool |
| 257 | }{ |
| 258 | { |
| 259 | u: "", |
| 260 | expectErr: true, |
| 261 | }, |
| 262 | { |
| 263 | u: "http://foo/bar", |
| 264 | expectErr: true, |
| 265 | }, |
| 266 | { |
| 267 | u: ts.URL, |
| 268 | expectErr: true, |
| 269 | }, |
| 270 | { |
| 271 | p: `["http://foo"]`, |
| 272 | u: ts.URL, |
| 273 | expectErr: false, |
| 274 | r: []string{"http://foo"}, |
| 275 | }, |
| 276 | { |
| 277 | p: `["http://foo"]`, |
| 278 | u: ts.URL, |
| 279 | expectErr: true, |
| 280 | r: []string{"http://foo", "http://not-foo"}, |
| 281 | }, |
| 282 | } { |
| 283 | t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) { |
| 284 | payload = tc.p |
| 285 | err := v.ValidateSectorIdentifierURL(context.Background(), tc.u, tc.r) |
| 286 | if tc.expectErr { |
| 287 | require.Error(t, err) |
| 288 | } else { |
| 289 | require.NoError(t, err) |
| 290 | } |
| 291 | }) |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | // from https://datatracker.ietf.org/doc/html/rfc7517#appendix-A.2 |
| 296 | const validJWKS = ` |
nothing calls this directly
no test coverage detected