mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 02:02:43 +00:00 
			
		
		
		
	Add PATCH to CORS allowed request methods (#24373)
* add PATCH to cors request methods * changelog
This commit is contained in:
		
							
								
								
									
										3
									
								
								changelog/24373.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								changelog/24373.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | ||||
| ```release-note:bug | ||||
| http: Include PATCH in the list of allowed CORS methods | ||||
| ``` | ||||
| @@ -18,6 +18,7 @@ var allowedMethods = []string{ | ||||
| 	http.MethodOptions, | ||||
| 	http.MethodPost, | ||||
| 	http.MethodPut, | ||||
| 	http.MethodPatch, | ||||
| 	"LIST", // LIST is not an official HTTP method, but Vault supports it. | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -118,6 +118,28 @@ func TestHandler_parseMFAHandler(t *testing.T) { | ||||
| 	} | ||||
| } | ||||
|  | ||||
| // TestHandler_CORS_Patch verifies that http PATCH is included in the list of | ||||
| // allowed request methods | ||||
| func TestHandler_CORS_Patch(t *testing.T) { | ||||
| 	core, _, _ := vault.TestCoreUnsealed(t) | ||||
| 	ln, addr := TestServer(t, core) | ||||
| 	defer ln.Close() | ||||
|  | ||||
| 	corsConfig := core.CORSConfig() | ||||
| 	err := corsConfig.Enable(context.Background(), []string{addr}, nil) | ||||
| 	require.NoError(t, err) | ||||
| 	req, err := http.NewRequest(http.MethodOptions, addr+"/v1/sys/seal-status", nil) | ||||
| 	require.NoError(t, err) | ||||
|  | ||||
| 	req.Header.Set("Origin", addr) | ||||
| 	req.Header.Set("Access-Control-Request-Method", http.MethodPatch) | ||||
|  | ||||
| 	client := cleanhttp.DefaultClient() | ||||
| 	resp, err := client.Do(req) | ||||
| 	require.NoError(t, err) | ||||
| 	require.Equal(t, http.StatusOK, resp.StatusCode) | ||||
| } | ||||
|  | ||||
| func TestHandler_cors(t *testing.T) { | ||||
| 	core, _, _ := vault.TestCoreUnsealed(t) | ||||
| 	ln, addr := TestServer(t, core) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 miagilepner
					miagilepner