Skip to content

Commit b2021b3

Browse files
authored
Merge pull request #178 from codeRIT/issue_164
fix: Validate asset config values are URLs
2 parents 7a8ab14 + b9b256e commit b2021b3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

app/controllers/manage/configs_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ def update
1717
value = params[:hackathon_config][key]
1818
value = true if value == "true"
1919
value = false if value == "false"
20-
if @config.value != value
20+
if @config.var.end_with?("_asset") && !value.start_with?('http://', 'https://')
21+
flash[:alert] = "Config \"#{key}\" must start with http:// or https://"
22+
render :edit
23+
elsif @config.value != value
2124
@config.value = value
2225
@config.save
2326
redirect_to manage_configs_path, notice: "Config \"#{key}\" has been updated."

test/controllers/manage/configs_controller_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,20 @@ class Manage::ConfigsControllerTest < ActionController::TestCase
115115
assert_redirected_to manage_configs_path
116116
end
117117

118+
should "update logo_asset with a url" do
119+
HackathonConfig["logo_asset"] = ''
120+
patch :update, params: { id: "logo_asset", hackathon_config: { logo_asset: "https://picsum.photos/200" } }
121+
assert_equal "https://picsum.photos/200", HackathonConfig["logo_asset"]
122+
assert_redirected_to manage_configs_path
123+
end
124+
125+
should "not update logo_asset with an asset that is not URL based" do
126+
HackathonConfig["logo_asset"] = ''
127+
patch :update, params: { id: "logo_asset", hackathon_config: { logo_asset: "test" } }
128+
assert_equal '', HackathonConfig["logo_asset"]
129+
assert_redirected_to edit_manage_config_path("logo_asset")
130+
end
131+
118132
should "update config CSS variables when custom_css is blank" do
119133
HackathonConfig["custom_css"] = ""
120134
patch :update, params: { id: "custom_css", hackathon_config: { custom_css: ":root {\n --foo: #fff;\n}" } }

0 commit comments

Comments
 (0)