FIX: Perform better email validation (#12497)

Using UserEmail for validation is not sufficient because it checks the
emails of staged users too.
This commit is contained in:
Bianca Nenciu
2021-03-23 23:44:51 +02:00
committed by GitHub
parent be5ed73f08
commit f3eab6a86a
2 changed files with 40 additions and 9 deletions

View File

@ -1592,6 +1592,11 @@ describe UsersController do
expect(response.parsed_body["success"]).to be_present
end
it 'returns success if email is empty' do
get "/u/check_email.json"
expect(response.parsed_body["success"]).to be_present
end
it 'returns failure if email is not valid' do
get "/u/check_email.json", params: { email: "invalid" }
expect(response.parsed_body["failed"]).to be_present
@ -1600,12 +1605,20 @@ describe UsersController do
it 'returns failure if email exists' do
get "/u/check_email.json", params: { email: user.email }
expect(response.parsed_body["failed"]).to be_present
get "/u/check_email.json", params: { email: user.email.upcase }
expect(response.parsed_body["failed"]).to be_present
end
it 'returns success if email does not exists' do
get "/u/check_email.json", params: { email: "available@example.com" }
expect(response.parsed_body["success"]).to be_present
end
it 'return success if user email is taken by staged user' do
get "/u/check_email.json", params: { email: Fabricate(:staged).email }
expect(response.parsed_body["success"]).to be_present
end
end
describe '#invited' do