FIX: validate Invite email against `EmailValidator.email_regex` (#6975)
This commit is contained in:
parent
ca03b2ff30
commit
ab2c2ea605
|
@ -16,7 +16,7 @@ class Invite < ActiveRecord::Base
|
|||
has_many :topic_invites
|
||||
has_many :topics, through: :topic_invites, source: :topic
|
||||
validates_presence_of :invited_by_id
|
||||
validates :email, email: true
|
||||
validates :email, email: true, format: { with: EmailValidator.email_regex }
|
||||
|
||||
before_create do
|
||||
self.invite_key ||= SecureRandom.hex
|
||||
|
|
|
@ -25,9 +25,15 @@ describe Invite do
|
|||
|
||||
context 'email validators' do
|
||||
let(:coding_horror) { Fabricate(:coding_horror) }
|
||||
let(:invite) { Invite.create(email: "test@mailinator.com", invited_by: coding_horror) }
|
||||
|
||||
it "should not allow an invite with unformatted email address" do
|
||||
expect {
|
||||
Fabricate(:invite, email: "John Doe <john.doe@example.com>")
|
||||
}.to raise_error(ActiveRecord::RecordInvalid)
|
||||
end
|
||||
|
||||
it "should not allow an invite with blacklisted email" do
|
||||
invite = Invite.create(email: "test@mailinator.com", invited_by: coding_horror)
|
||||
expect(invite).not_to be_valid
|
||||
end
|
||||
|
||||
|
|
|
@ -214,8 +214,9 @@ describe InvitesController do
|
|||
end
|
||||
|
||||
context 'with an invalid invite record' do
|
||||
let(:invite) { Fabricate(:invite, email: "John Doe <john.doe@example.com>") }
|
||||
let(:invite) { Fabricate(:invite) }
|
||||
it "responds with error message" do
|
||||
invite.update_attribute(:email, "John Doe <john.doe@example.com>")
|
||||
put "/invites/show/#{invite.invite_key}.json"
|
||||
expect(response.status).to eq(200)
|
||||
json = JSON.parse(response.body)
|
||||
|
|
Loading…
Reference in New Issue