Skip to content

Commit

Permalink
Merge 59b0e2e into 436fca1
Browse files Browse the repository at this point in the history
  • Loading branch information
gmikeska-r7 committed Jun 11, 2015
2 parents 436fca1 + 59b0e2e commit 09fc608
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 5 additions & 2 deletions app/models/mdm/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
class Mdm::Tag < ActiveRecord::Base
include Metasploit::Model::Search

TAG_CHAR_VALIDATION_MSG = "Tag names can only contain alphanumeric characters, dots, dashes, and underscores."

TAG_LENGTH_VALIDATION_MSG = "desc must be less than 8k."
#
# Associations
#
Expand Down Expand Up @@ -82,11 +85,11 @@ class Mdm::Tag < ActiveRecord::Base
validates :desc,
:length => {
:maximum => ((8 * (2 ** 10)) - 1),
:message => "desc must be less than 8k."
:message => TAG_LENGTH_VALIDATION_MSG
}
validates :name,
:format => {
:with => /\A[A-Za-z0-9\x2e\x2d_]+\z/, :message => "must be alphanumeric, dots, dashes, or underscores"
:with => /\A[A-Za-z0-9\x2e\x2d_]+\z/, :message => TAG_CHAR_VALIDATION_MSG
},
:presence => true

Expand Down
11 changes: 6 additions & 5 deletions spec/app/models/mdm/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
end

context 'name' do
let(:error_msg) {Mdm::Tag::TAG_CHAR_VALIDATION_MSG}
it 'must be present' do
nameless_tag = FactoryGirl.build(:mdm_tag, :name => nil)
expect(nameless_tag).not_to be_valid
Expand All @@ -49,19 +50,19 @@
#Test for various bad inputs we should never allow
mytag = FactoryGirl.build(:mdm_tag, :name => "A'1")
expect(mytag).not_to be_valid
expect(mytag.errors[:name]).to include('must be alphanumeric, dots, dashes, or underscores')
expect(mytag.errors[:name]).to include(error_msg)
mytag = FactoryGirl.build(:mdm_tag, :name => "A;1")
expect(mytag).not_to be_valid
expect(mytag.errors[:name]).to include('must be alphanumeric, dots, dashes, or underscores')
expect(mytag.errors[:name]).to include(error_msg)
mytag = FactoryGirl.build(:mdm_tag, :name => "A%1")
expect(mytag).not_to be_valid
expect(mytag.errors[:name]).to include('must be alphanumeric, dots, dashes, or underscores')
expect(mytag.errors[:name]).to include(error_msg)
mytag = FactoryGirl.build(:mdm_tag, :name => "A=1")
expect(mytag).not_to be_valid
expect(mytag.errors[:name]).to include('must be alphanumeric, dots, dashes, or underscores')
expect(mytag.errors[:name]).to include(error_msg)
mytag = FactoryGirl.build(:mdm_tag, :name => "#A1")
expect(mytag).not_to be_valid
expect(mytag.errors[:name]).to include('must be alphanumeric, dots, dashes, or underscores')
expect(mytag.errors[:name]).to include(error_msg)
end
end
end
Expand Down

0 comments on commit 09fc608

Please sign in to comment.