summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-09-23 12:23:08 -0700
committerjessib <jessib@riseup.net>2013-09-23 12:23:08 -0700
commita9c68ba0bbba7a95e9b4a3ff24554d1b0af6cbc5 (patch)
treec8a3bf7fe4c8001718ea31e56d036b267ee362e6 /users
parent906e177b35606835c4f10a9de65d9bd83cbe21ad (diff)
This ensures that email addresses contain only lowercase letters, and that an identity's destination is a valid Email.
Diffstat (limited to 'users')
-rw-r--r--users/app/models/email.rb8
-rw-r--r--users/app/models/identity.rb6
-rw-r--r--users/test/unit/identity_test.rb17
3 files changed, 27 insertions, 4 deletions
diff --git a/users/app/models/email.rb b/users/app/models/email.rb
index 89c31bb..f38f2f5 100644
--- a/users/app/models/email.rb
+++ b/users/app/models/email.rb
@@ -3,10 +3,16 @@ class Email < String
validates :email,
:format => {
- :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/,
+ :with => /\A([^@\s]+)@((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})\Z/, #checks format, but allows lowercase
:message => "needs to be a valid email address"
}
+ validates :email,
+ :format => {
+ :with => /\A[^A-Z]*\Z/, #forbids uppercase characters
+ :message => "letters must be lowercase"
+ }
+
def to_partial_path
"emails/email"
end
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb
index 91345a0..e0a24e9 100644
--- a/users/app/models/identity.rb
+++ b/users/app/models/identity.rb
@@ -12,6 +12,7 @@ class Identity < CouchRest::Model::Base
validate :unique_forward
validate :alias_available
validate :address_local_email
+ validate :destination_email
design do
view :by_user_id
@@ -91,4 +92,9 @@ class Identity < CouchRest::Model::Base
self.errors.add(:address, address.errors.messages[:email].first) #assumes only one error
end
+ def destination_email
+ return if destination.valid? #this ensures it is Email
+ self.errors.add(:destination, destination.errors.messages[:email].first) #assumes only one error #TODO
+ end
+
end
diff --git a/users/test/unit/identity_test.rb b/users/test/unit/identity_test.rb
index b3918f1..02f14c0 100644
--- a/users/test/unit/identity_test.rb
+++ b/users/test/unit/identity_test.rb
@@ -70,13 +70,13 @@ class IdentityTest < ActiveSupport::TestCase
id.destroy
end
- test "fail to end non-local email address as identity address" do
- id = Identity.for @user, address: 'blah@sdlfksjdfljk.com'
+ test "fail to add non-local email address as identity address" do
+ id = Identity.for @user, address: forward_address
assert !id.valid?
assert_match /needs to end in/, id.errors[:address].first
end
- test "only lowercase alias" do
+ test "alias must meet some conditions as login" do
id = Identity.create_for @user, address: alias_name.capitalize
assert !id.valid?
#hacky way to do this, but okay for now:
@@ -84,6 +84,17 @@ class IdentityTest < ActiveSupport::TestCase
assert id.errors.messages.flatten(2).include? "Only lowercase letters, digits, . - and _ allowed."
end
+ test "destination must be valid email address" do
+ id = Identity.create_for @user, address: @user.email_address, destination: 'ASKJDLFJD'
+ assert !id.valid?
+ assert id.errors.messages[:destination].include? "needs to be a valid email address"
+ end
+
+ test "only lowercase destination" do
+ id = Identity.create_for @user, address: @user.email_address, destination: forward_address.capitalize
+ assert !id.valid?
+ assert id.errors.messages[:destination].include? "letters must be lowercase"
+ end
def alias_name
@alias_name ||= Faker::Internet.user_name