mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 02:27:19 -04:00 
			
		
		
		
	Merge pull request #1637 from devangels/bugfix1628
Bugfix for issue #1628 where `Caddyfile` is not being hidden correctly
This commit is contained in:
		
						commit
						b3dd604904
					
				| @ -70,7 +70,7 @@ func hideCaddyfile(cctx caddy.Context) error { | |||||||
| 			return err | 			return err | ||||||
| 		} | 		} | ||||||
| 		if strings.HasPrefix(absOriginCaddyfile, absRoot) { | 		if strings.HasPrefix(absOriginCaddyfile, absRoot) { | ||||||
| 			cfg.HiddenFiles = append(cfg.HiddenFiles, strings.TrimPrefix(absOriginCaddyfile, absRoot)) | 			cfg.HiddenFiles = append(cfg.HiddenFiles, filepath.ToSlash(strings.TrimPrefix(absOriginCaddyfile, absRoot))) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	return nil | 	return nil | ||||||
|  | |||||||
| @ -209,3 +209,27 @@ func TestContextSaveConfig(t *testing.T) { | |||||||
| 		t.Errorf("Expected len(siteConfigs) == %d, but was %d", want, got) | 		t.Errorf("Expected len(siteConfigs) == %d, but was %d", want, got) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | // Test to make sure we are correctly hiding the Caddyfile | ||||||
|  | func TestHideCaddyfile(t *testing.T) { | ||||||
|  | 	ctx := newContext().(*httpContext) | ||||||
|  | 	ctx.saveConfig("test", &SiteConfig{ | ||||||
|  | 		Root:            Root, | ||||||
|  | 		originCaddyfile: "Testfile", | ||||||
|  | 	}) | ||||||
|  | 	err := hideCaddyfile(ctx) | ||||||
|  | 	if err != nil { | ||||||
|  | 		t.Fatalf("Failed to hide Caddyfile, got: %v", err) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 	if len(ctx.siteConfigs[0].HiddenFiles) == 0 { | ||||||
|  | 		t.Fatal("Failed to add Caddyfile to HiddenFiles.") | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 	for _, file := range ctx.siteConfigs[0].HiddenFiles { | ||||||
|  | 		if file == "/Testfile" { | ||||||
|  | 			return | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	t.Fatal("Caddyfile missing from HiddenFiles") | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user