Safer inputs to billboard ENV vars (#19938)
* Safer inputs to billboard ENV vars * Update app/models/display_ad.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update app/models/display_ad.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update app/models/display_ad.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update app/models/display_ad.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update spec/models/display_ad_spec.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update spec/models/display_ad_spec.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update spec/models/display_ad_spec.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update spec/models/display_ad_spec.rb Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
This commit is contained in:
parent
d7b4c77937
commit
3f07d43e72
2 changed files with 22 additions and 2 deletions
|
|
@ -109,15 +109,17 @@ class DisplayAd < ApplicationRecord
|
|||
end
|
||||
|
||||
def self.random_range_max(placement_area)
|
||||
ApplicationConfig["SELDOM_SEEN_MIN_FOR_#{placement_area.upcase}"] ||
|
||||
selected_number = ApplicationConfig["SELDOM_SEEN_MIN_FOR_#{placement_area.upcase}"] ||
|
||||
ApplicationConfig["SELDOM_SEEN_MIN"] ||
|
||||
RANDOM_RANGE_MAX_FALLBACK
|
||||
selected_number.to_i
|
||||
end
|
||||
|
||||
def self.new_and_priority_range_max(placement_area)
|
||||
ApplicationConfig["SELDOM_SEEN_MAX_FOR_#{placement_area.upcase}"] ||
|
||||
selected_number = ApplicationConfig["SELDOM_SEEN_MAX_FOR_#{placement_area.upcase}"] ||
|
||||
ApplicationConfig["SELDOM_SEEN_MAX"] ||
|
||||
NEW_AND_PRIORITY_RANGE_MAX_FALLBACK
|
||||
selected_number.to_i
|
||||
end
|
||||
|
||||
def human_readable_placement_area
|
||||
|
|
|
|||
|
|
@ -107,6 +107,24 @@ RSpec.describe DisplayAd do
|
|||
end
|
||||
end
|
||||
|
||||
context "when range env var is set" do
|
||||
it "translates jiberrish to 0" do
|
||||
allow(ApplicationConfig).to receive(:[]).with("SELDOM_SEEN_MIN_FOR_SIDEBAR_LEFT").and_return("jibberish")
|
||||
expect(described_class.random_range_max("sidebar_left")).to eq 0
|
||||
end
|
||||
|
||||
it "still performs query with number" do
|
||||
allow(ApplicationConfig).to receive(:[]).with("SELDOM_SEEN_MIN_FOR_SIDEBAR_LEFT").and_return("100")
|
||||
expect(described_class.random_range_max("sidebar_left")).to eq 100
|
||||
end
|
||||
|
||||
it "falls back to broadly set range vars" do
|
||||
allow(ApplicationConfig).to receive(:[]).with("SELDOM_SEEN_MIN_FOR_SIDEBAR_LEFT").and_return(nil)
|
||||
allow(ApplicationConfig).to receive(:[]).with("SELDOM_SEEN_MIN").and_return("89")
|
||||
expect(described_class.random_range_max("sidebar_left")).to eq 89
|
||||
end
|
||||
end
|
||||
|
||||
context "when parsing liquid tags" do
|
||||
it "renders username embed" do
|
||||
user = create(:user)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue