Skip to content

Commit

Permalink
Merge pull request ManageIQ#22624 from kbrock/settings_change_key_format
Browse files Browse the repository at this point in the history
validate format for SettingsChange#key
  • Loading branch information
Fryguy authored Jul 28, 2023
2 parents c454ab0 + af56a21 commit 325abb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/settings_change.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class SettingsChange < ApplicationRecord
serialize :value

validates :key, :format => %r{\A/[^/]+(/[^/]+)*\z}
belongs_to :resource, :polymorphic => true

def key_path
Expand Down
9 changes: 9 additions & 0 deletions spec/models/settings_change_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
RSpec.describe SettingsChange do
describe "#key" do
it "validates with a good key" do
expect(described_class.new(:key => "/api/token")).to be_valid
end

it "doesn't validate with a bad key" do
expect(described_class.new(:key => "api/token")).not_to be_valid
end
end
describe "#key_path" do
it "with multiple parts in the key" do
change = described_class.new(:key => "/api/token_ttl")
Expand Down

0 comments on commit 325abb8

Please sign in to comment.