-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
{path} gets escaped in URL parsing and makes round-tripping awkward.
- Loading branch information
1 parent
37fac6a
commit 871fde9
Showing
5 changed files
with
66 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,24 @@ import ( | |
"github.com/chriskuehl/fluffy/testfunc" | ||
) | ||
|
||
var configWithEverything = []byte(` | ||
branding = "foo" | ||
custom_footer_html = "<p>foo</p>" | ||
abuse_contact_email = "[email protected]" | ||
max_upload_bytes = 123 | ||
max_multipart_memory_bytes = 456 | ||
home_url = "http://foo.com" | ||
object_url_pattern = "http://i.foo.com/o/:path:" | ||
html_url_pattern = "http://i.foo.com/h/:path:" | ||
forbidden_file_extensions = ["foo", "bar"] | ||
host = "192.168.1.100" | ||
port = 5555 | ||
[filesystem_storage_backend] | ||
object_root = "/tmp/objects" | ||
html_root = "/tmp/html" | ||
`) | ||
|
||
func TestLoadConfigTOMLEmptyFile(t *testing.T) { | ||
configPath := t.TempDir() + "/config.toml" | ||
if err := os.WriteFile(configPath, []byte(""), 0644); err != nil { | ||
|
@@ -30,31 +48,13 @@ func TestLoadConfigTOMLEmptyFile(t *testing.T) { | |
|
||
func TestLoadConfigTOMLWithEverything(t *testing.T) { | ||
configPath := t.TempDir() + "/config.toml" | ||
if err := os.WriteFile(configPath, []byte(` | ||
branding = "foo" | ||
custom_footer_html = "<p>foo</p>" | ||
abuse_contact_email = "[email protected]" | ||
max_upload_bytes = 123 | ||
max_multipart_memory_bytes = 456 | ||
home_url = "http://foo.com" | ||
object_url_pattern = "http://i.foo.com/o/{path}" | ||
html_url_pattern = "http://i.foo.com/h/{path}" | ||
forbidden_file_extensions = ["foo", "bar"] | ||
host = "192.168.1.100" | ||
port = 5555 | ||
[filesystem_storage_backend] | ||
object_root = "/tmp/objects" | ||
html_root = "/tmp/html" | ||
`), 0644); err != nil { | ||
if err := os.WriteFile(configPath, configWithEverything, 0644); err != nil { | ||
t.Fatalf("failed to write file: %v", err) | ||
} | ||
|
||
conf := testfunc.NewConfig() | ||
if err := LoadConfigTOML(conf, configPath); err != nil { | ||
t.Fatalf("failed to load config: %v", err) | ||
} | ||
|
||
errs := conf.Validate() | ||
if len(errs) != 0 { | ||
t.Fatalf("config validation failed: %v", errs) | ||
|
@@ -67,8 +67,8 @@ html_root = "/tmp/html" | |
MaxUploadBytes: 123, | ||
MaxMultipartMemoryBytes: 456, | ||
HomeURL: url.URL{Scheme: "http", Host: "foo.com"}, | ||
ObjectURLPattern: url.URL{Scheme: "http", Host: "i.foo.com", Path: "/o/{path}", RawPath: "/o/{path}"}, | ||
HTMLURLPattern: url.URL{Scheme: "http", Host: "i.foo.com", Path: "/h/{path}", RawPath: "/h/{path}"}, | ||
ObjectURLPattern: url.URL{Scheme: "http", Host: "i.foo.com", Path: "/o/:path:"}, | ||
HTMLURLPattern: url.URL{Scheme: "http", Host: "i.foo.com", Path: "/h/:path:"}, | ||
ForbiddenFileExtensions: map[string]struct{}{"foo": {}, "bar": {}}, | ||
Host: "192.168.1.100", | ||
Port: 5555, | ||
|
@@ -82,3 +82,40 @@ html_root = "/tmp/html" | |
t.Fatalf("config mismatch (-want +got):\n%s", diff) | ||
} | ||
} | ||
|
||
func TestRoundtripDumpLoadConfigTOML(t *testing.T) { | ||
configPath := t.TempDir() + "/config.toml" | ||
if err := os.WriteFile(configPath, configWithEverything, 0644); err != nil { | ||
t.Fatalf("failed to write file: %v", err) | ||
} | ||
conf := testfunc.NewConfig() | ||
if err := LoadConfigTOML(conf, configPath); err != nil { | ||
t.Fatalf("failed to load config: %v", err) | ||
} | ||
errs := conf.Validate() | ||
if len(errs) != 0 { | ||
t.Fatalf("config validation failed: %v", errs) | ||
} | ||
|
||
newConfigPath := t.TempDir() + "/new_config.toml" | ||
configText, err := DumpConfigTOML(conf) | ||
if err != nil { | ||
t.Fatalf("failed to dump config: %v", err) | ||
} | ||
if err := os.WriteFile(newConfigPath, []byte(configText), 0644); err != nil { | ||
t.Fatalf("failed to write file: %v", err) | ||
} | ||
|
||
newConf := testfunc.NewConfig() | ||
if err := LoadConfigTOML(newConf, newConfigPath); err != nil { | ||
t.Fatalf("failed to load config: %v", err) | ||
} | ||
errs = newConf.Validate() | ||
if len(errs) != 0 { | ||
t.Fatalf("config validation failed: %v", errs) | ||
} | ||
|
||
if diff := cmp.Diff(conf, newConf); diff != "" { | ||
t.Fatalf("config mismatch (-want +got):\n%s", diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters