mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-25 15:52:45 -04:00 
			
		
		
		
	caddyfile: Reject global request matchers earlier (#6339)
This commit is contained in:
		
							parent
							
								
									2ce5c65269
								
							
						
					
					
						commit
						f6d2c293e7
					
				| @ -214,7 +214,12 @@ func (p *parser) addresses() error { | ||||
| 		value := p.Val() | ||||
| 		token := p.Token() | ||||
| 
 | ||||
| 		// special case: import directive replaces tokens during parse-time | ||||
| 		// Reject request matchers if trying to define them globally | ||||
| 		if strings.HasPrefix(value, "@") { | ||||
| 			return p.Errf("request matchers may not be defined globally, they must be in a site block; found %s", value) | ||||
| 		} | ||||
| 
 | ||||
| 		// Special case: import directive replaces tokens during parse-time | ||||
| 		if value == "import" && p.isNewLine() { | ||||
| 			err := p.doImport(0) | ||||
| 			if err != nil { | ||||
|  | ||||
| @ -857,6 +857,29 @@ func TestSnippetAcrossMultipleFiles(t *testing.T) { | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func TestRejectsGlobalMatcher(t *testing.T) { | ||||
| 	p := testParser(` | ||||
| 		@rejected path /foo | ||||
| 
 | ||||
| 		(common) { | ||||
| 			gzip foo | ||||
| 			errors stderr | ||||
| 		} | ||||
| 
 | ||||
| 		http://example.com { | ||||
| 			import common | ||||
| 		} | ||||
| 	`) | ||||
| 	_, err := p.parseAll() | ||||
| 	if err == nil { | ||||
| 		t.Fatal("Expected an error, but got nil") | ||||
| 	} | ||||
| 	expected := "request matchers may not be defined globally, they must be in a site block; found @rejected, at Testfile:2" | ||||
| 	if err.Error() != expected { | ||||
| 		t.Errorf("Expected error to be '%s' but got '%v'", expected, err) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func testParser(input string) parser { | ||||
| 	return parser{Dispenser: NewTestDispenser(input)} | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user