diff --git a/app/models/miq_request_workflow/dialog_field_validation.rb b/app/models/miq_request_workflow/dialog_field_validation.rb index 3a0cbc5082e..7032a5fb0ef 100644 --- a/app/models/miq_request_workflow/dialog_field_validation.rb +++ b/app/models/miq_request_workflow/dialog_field_validation.rb @@ -37,4 +37,12 @@ def validate_regex(_field, _values, dlg, fld, value) error end end + + def validate_blacklist(_field, _values, dlg, fld, value) + blacklist = fld[:blacklist] + return _("%{name} is required") % {:name => required_description(dlg, fld)} if value.blank? + if blacklist && blacklist.include?(value) + _("%{name} may not contain blacklisted value") % {:name => required_description(dlg, fld)} + end + end end diff --git a/spec/models/miq_request_workflow_spec.rb b/spec/models/miq_request_workflow_spec.rb index 19bb7e92d86..67769bf415a 100644 --- a/spec/models/miq_request_workflow_spec.rb +++ b/spec/models/miq_request_workflow_spec.rb @@ -358,6 +358,22 @@ end end + context "#validate_blacklist" do + let(:blacklist) { {:blacklist => ['foo', 'bar']} } + + it "returns nil if the value is not blacklisted" do + expect(workflow.validate_blacklist(nil, {}, {}, blacklist, 'test')).to be_nil + end + + it "returns a formatted message when the value is blacklisted" do + expect(workflow.validate_blacklist(nil, {}, {}, blacklist, 'foo')).to eq("'/' may not contain blacklisted value") + end + + it "returns an error when no value exists" do + expect(workflow.validate_blacklist(nil, {}, {}, blacklist, '')).to eq "'/' is required" + end + end + context "#validate regex" do let(:regex) { {:required_regex => "^n@test.com$"} } let(:regex_two) { {:required_regex => "^n$"} }