diff options
Diffstat (limited to 'users')
-rw-r--r-- | users/app/models/identity.rb | 11 | ||||
-rw-r--r-- | users/app/models/user.rb | 3 | ||||
-rw-r--r-- | users/test/unit/identity_test.rb | 19 |
3 files changed, 32 insertions, 1 deletions
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb index 4dff93a..b862590 100644 --- a/users/app/models/identity.rb +++ b/users/app/models/identity.rb @@ -6,6 +6,7 @@ class Identity < CouchRest::Model::Base property :address, LocalEmail property :destination, Email + property :keys, Hash validate :unique_forward validate :alias_available @@ -14,6 +15,16 @@ class Identity < CouchRest::Model::Base view :by_user_id view :by_address_and_destination view :by_address + view :pgp_key_by_email, + map: <<-EOJS + function(doc) { + if (doc.type != 'Identity') { + return; + } + emit(doc.address, doc.keys["pgp"]); + } + EOJS + end protected diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 62fb7ec..fb7f0aa 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -62,7 +62,8 @@ class User < CouchRest::Model::Base def build_identity(attribs = {}, &block) attribs.reverse_merge! user_id: self.id, address: self.email_address, - destination: self.email_address + destination: self.email_address, + keys: {} Identity.new(attribs, &block) end diff --git a/users/test/unit/identity_test.rb b/users/test/unit/identity_test.rb index 4ebd72e..6b0a6b1 100644 --- a/users/test/unit/identity_test.rb +++ b/users/test/unit/identity_test.rb @@ -55,7 +55,22 @@ class IdentityTest < ActiveSupport::TestCase other_user.destroy end + test "setting and getting pgp key" do + id = @user.build_identity + id.keys[:pgp] = pgp_key_string + assert_equal pgp_key_string, id.keys[:pgp] + end + test "querying pgp key via couch" do + id = @user.build_identity + id.keys[:pgp] = pgp_key_string + id.save + view = Identity.pgp_key_by_email.key(id.address) + assert_equal 1, view.rows.count + assert result = view.rows.first + assert_equal id.address, result["key"] + assert_equal id.keys[:pgp], result["value"] + end def alias_name @alias_name ||= Faker::Internet.user_name @@ -64,4 +79,8 @@ class IdentityTest < ActiveSupport::TestCase def forward_address @forward_address ||= Faker::Internet.email end + + def pgp_key_string + @pgp_key ||= "DUMMY PGP KEY ... "+SecureRandom.base64(4096) + end end |