mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 03:27:23 -05:00 
			
		
		
		
	Merge pull request #483 from benschumacher/master
letsencrypt: Make plaintext redirect hosts honor the Bind settings
This commit is contained in:
		
						commit
						cae9880800
					
				@ -42,8 +42,8 @@ func init() {
 | 
				
			|||||||
var directiveOrder = []directive{
 | 
					var directiveOrder = []directive{
 | 
				
			||||||
	// Essential directives that initialize vital configuration settings
 | 
						// Essential directives that initialize vital configuration settings
 | 
				
			||||||
	{"root", setup.Root},
 | 
						{"root", setup.Root},
 | 
				
			||||||
	{"tls", setup.TLS}, // letsencrypt is set up just after tls
 | 
					 | 
				
			||||||
	{"bind", setup.BindHost},
 | 
						{"bind", setup.BindHost},
 | 
				
			||||||
 | 
						{"tls", setup.TLS}, // letsencrypt is set up just after tls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Other directives that don't create HTTP handlers
 | 
						// Other directives that don't create HTTP handlers
 | 
				
			||||||
	{"startup", setup.Startup},
 | 
						{"startup", setup.Startup},
 | 
				
			||||||
 | 
				
			|||||||
@ -445,8 +445,9 @@ func redirPlaintextHost(cfg server.Config) server.Config {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return server.Config{
 | 
						return server.Config{
 | 
				
			||||||
		Host: cfg.Host,
 | 
							Host:     cfg.Host,
 | 
				
			||||||
		Port: "http",
 | 
							BindHost: cfg.BindHost,
 | 
				
			||||||
 | 
							Port:     "http",
 | 
				
			||||||
		Middleware: map[string][]middleware.Middleware{
 | 
							Middleware: map[string][]middleware.Middleware{
 | 
				
			||||||
			"/": []middleware.Middleware{redirMidware},
 | 
								"/": []middleware.Middleware{redirMidware},
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 | 
				
			|||||||
@ -38,14 +38,18 @@ func TestHostQualifies(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestRedirPlaintextHost(t *testing.T) {
 | 
					func TestRedirPlaintextHost(t *testing.T) {
 | 
				
			||||||
	cfg := redirPlaintextHost(server.Config{
 | 
						cfg := redirPlaintextHost(server.Config{
 | 
				
			||||||
		Host: "example.com",
 | 
							Host:     "example.com",
 | 
				
			||||||
		Port: "http",
 | 
							BindHost: "93.184.216.34",
 | 
				
			||||||
 | 
							Port:     "http",
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check host and port
 | 
						// Check host and port
 | 
				
			||||||
	if actual, expected := cfg.Host, "example.com"; actual != expected {
 | 
						if actual, expected := cfg.Host, "example.com"; actual != expected {
 | 
				
			||||||
		t.Errorf("Expected redir config to have host %s but got %s", expected, actual)
 | 
							t.Errorf("Expected redir config to have host %s but got %s", expected, actual)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if actual, expected := cfg.BindHost, "93.184.216.34"; actual != expected {
 | 
				
			||||||
 | 
							t.Errorf("Expected redir config to have bindhost %s but got %s", expected, actual)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if actual, expected := cfg.Port, "http"; actual != expected {
 | 
						if actual, expected := cfg.Port, "http"; actual != expected {
 | 
				
			||||||
		t.Errorf("Expected redir config to have port '%s' but got '%s'", expected, actual)
 | 
							t.Errorf("Expected redir config to have port '%s' but got '%s'", expected, actual)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user