(t *testing.T)
| 342 | } |
| 343 | |
| 344 | func TestCORSWithConfig_AllowMethods(t *testing.T) { |
| 345 | var testCases = []struct { |
| 346 | name string |
| 347 | givenAllowOrigins []string |
| 348 | givenAllowMethods []string |
| 349 | whenAllowContextKey string |
| 350 | whenOrigin string |
| 351 | expectAllow string |
| 352 | expectAccessControlAllowMethods string |
| 353 | }{ |
| 354 | { |
| 355 | name: "custom AllowMethods, preflight, no origin, sets only allow header from context key", |
| 356 | givenAllowOrigins: []string{"*"}, |
| 357 | givenAllowMethods: []string{http.MethodGet, http.MethodHead}, |
| 358 | whenAllowContextKey: "OPTIONS, GET", |
| 359 | whenOrigin: "", |
| 360 | expectAllow: "OPTIONS, GET", |
| 361 | }, |
| 362 | { |
| 363 | name: "default AllowMethods, preflight, no origin, no allow header in context key and in response", |
| 364 | givenAllowOrigins: []string{"*"}, |
| 365 | givenAllowMethods: nil, |
| 366 | whenAllowContextKey: "", |
| 367 | whenOrigin: "", |
| 368 | expectAllow: "", |
| 369 | }, |
| 370 | { |
| 371 | name: "custom AllowMethods, preflight, existing origin, sets both headers different values", |
| 372 | givenAllowOrigins: []string{"*"}, |
| 373 | givenAllowMethods: []string{http.MethodGet, http.MethodHead}, |
| 374 | whenAllowContextKey: "OPTIONS, GET", |
| 375 | whenOrigin: "http://google.com", |
| 376 | expectAllow: "OPTIONS, GET", |
| 377 | expectAccessControlAllowMethods: "GET,HEAD", |
| 378 | }, |
| 379 | { |
| 380 | name: "default AllowMethods, preflight, existing origin, sets both headers", |
| 381 | givenAllowOrigins: []string{"*"}, |
| 382 | givenAllowMethods: nil, |
| 383 | whenAllowContextKey: "OPTIONS, GET", |
| 384 | whenOrigin: "http://google.com", |
| 385 | expectAllow: "OPTIONS, GET", |
| 386 | expectAccessControlAllowMethods: "OPTIONS, GET", |
| 387 | }, |
| 388 | { |
| 389 | name: "default AllowMethods, preflight, existing origin, no allows, sets only CORS allow methods", |
| 390 | givenAllowOrigins: []string{"*"}, |
| 391 | givenAllowMethods: nil, |
| 392 | whenAllowContextKey: "", |
| 393 | whenOrigin: "http://google.com", |
| 394 | expectAllow: "", |
| 395 | expectAccessControlAllowMethods: "GET,HEAD,PUT,PATCH,POST,DELETE", |
| 396 | }, |
| 397 | } |
| 398 | |
| 399 | for _, tc := range testCases { |
| 400 | t.Run(tc.name, func(t *testing.T) { |
| 401 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…