mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 18:48:08 +00:00 
			
		
		
		
	Ignore special HTTP fields in response validation tests (#19530)
This commit is contained in:
		 Anton Averchenkov
					Anton Averchenkov
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							cc3b0130b6
						
					
				
				
					commit
					ce420de231
				
			| @@ -44,18 +44,6 @@ var pathFetchReadSchema = map[int][]framework.Response{ | ||||
| 				Description: `Issuing CA Chain`, | ||||
| 				Required:    false, | ||||
| 			}, | ||||
| 			"http_content_type": { | ||||
| 				Type:     framework.TypeString, | ||||
| 				Required: false, | ||||
| 			}, | ||||
| 			"http_raw_body": { | ||||
| 				Type:     framework.TypeString, | ||||
| 				Required: false, | ||||
| 			}, | ||||
| 			"http_status_code": { | ||||
| 				Type:     framework.TypeString, | ||||
| 				Required: false, | ||||
| 			}, | ||||
| 		}, | ||||
| 	}}, | ||||
| } | ||||
|   | ||||
| @@ -66,6 +66,24 @@ func validateResponseDataImpl(schema *framework.Response, data map[string]interf | ||||
| 		return fmt.Errorf("failed to unmashal data: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	// these are special fields that will not show up in the final response and | ||||
| 	// should be ignored | ||||
| 	for _, field := range []string{ | ||||
| 		logical.HTTPContentType, | ||||
| 		logical.HTTPRawBody, | ||||
| 		logical.HTTPStatusCode, | ||||
| 		logical.HTTPRawBodyAlreadyJSONDecoded, | ||||
| 		logical.HTTPCacheControlHeader, | ||||
| 		logical.HTTPPragmaHeader, | ||||
| 		logical.HTTPWWWAuthenticateHeader, | ||||
| 	} { | ||||
| 		delete(dataWithStringValues, field) | ||||
|  | ||||
| 		if _, ok := schema.Fields[field]; ok { | ||||
| 			return fmt.Errorf("encountered a reserved field in response schema: %s", field) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// Validate | ||||
| 	fd := framework.FieldData{ | ||||
| 		Raw:    dataWithStringValues, | ||||
| @@ -79,7 +97,7 @@ func validateResponseDataImpl(schema *framework.Response, data map[string]interf | ||||
| 	return fd.Validate() | ||||
| } | ||||
|  | ||||
| // FindResponseSchema is a test helper to extract the response schema from a given framework path / operation | ||||
| // FindResponseSchema is a test helper to extract response schema from the given framework path / operation | ||||
| func FindResponseSchema(t *testing.T, paths []*framework.Path, pathIdx int, operation logical.Operation) *framework.Response { | ||||
| 	t.Helper() | ||||
|  | ||||
|   | ||||
| @@ -249,6 +249,60 @@ func TestValidateResponse(t *testing.T) { | ||||
| 			strict:        false, | ||||
| 			errorExpected: false, | ||||
| 		}, | ||||
|  | ||||
| 		"empty schema, response has http_raw_body, strict": { | ||||
| 			schema: &framework.Response{ | ||||
| 				Fields: map[string]*framework.FieldSchema{}, | ||||
| 			}, | ||||
| 			response: map[string]interface{}{ | ||||
| 				"http_raw_body": "foo", | ||||
| 			}, | ||||
| 			strict:        true, | ||||
| 			errorExpected: false, | ||||
| 		}, | ||||
|  | ||||
| 		"empty schema, response has http_raw_body, not strict": { | ||||
| 			schema: &framework.Response{ | ||||
| 				Fields: map[string]*framework.FieldSchema{}, | ||||
| 			}, | ||||
| 			response: map[string]interface{}{ | ||||
| 				"http_raw_body": "foo", | ||||
| 			}, | ||||
| 			strict:        false, | ||||
| 			errorExpected: false, | ||||
| 		}, | ||||
|  | ||||
| 		"schema has http_raw_body, strict": { | ||||
| 			schema: &framework.Response{ | ||||
| 				Fields: map[string]*framework.FieldSchema{ | ||||
| 					"http_raw_body": { | ||||
| 						Type:     framework.TypeString, | ||||
| 						Required: false, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 			response: map[string]interface{}{ | ||||
| 				"http_raw_body": "foo", | ||||
| 			}, | ||||
| 			strict:        true, | ||||
| 			errorExpected: true, | ||||
| 		}, | ||||
|  | ||||
| 		"schema has http_raw_body, not strict": { | ||||
| 			schema: &framework.Response{ | ||||
| 				Fields: map[string]*framework.FieldSchema{ | ||||
| 					"http_raw_body": { | ||||
| 						Type:     framework.TypeString, | ||||
| 						Required: false, | ||||
| 					}, | ||||
| 				}, | ||||
| 			}, | ||||
| 			response: map[string]interface{}{ | ||||
| 				"http_raw_body": "foo", | ||||
| 			}, | ||||
| 			strict:        false, | ||||
| 			errorExpected: true, | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	for name, tc := range cases { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user