summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2018-01-19 14:11:24 +0100
committerAzul <azul@riseup.net>2018-01-19 14:11:24 +0100
commit54653f75cf44890310a06c3a8a6be59625629d2a (patch)
tree3a1c851033c46e1a140de3e3b5a17ad4b7f2647e /test
parentb8ba4f27a82868e0b3338b4af761f7c44226e729 (diff)
API: implement deleting keys through new keys api
Diffstat (limited to 'test')
-rw-r--r--test/unit/identity_test.rb8
-rw-r--r--test/unit/keyring_test.rb40
2 files changed, 48 insertions, 0 deletions
diff --git a/test/unit/identity_test.rb b/test/unit/identity_test.rb
index 6836487..43f644a 100644
--- a/test/unit/identity_test.rb
+++ b/test/unit/identity_test.rb
@@ -80,6 +80,14 @@ class IdentityTest < ActiveSupport::TestCase
assert_equal pgp_key_string, @id.keys[:pgp]
end
+ test "deleting pgp key" do
+ @id = Identity.for(@user)
+ @id.set_key(:pgp, pgp_key_string)
+ @id.delete_key(:pgp)
+ assert_nil @id.keys[:pgp]
+ assert_equal Hash.new, @id.keys
+ end
+
test "querying pgp key via couch" do
@id = Identity.for(@user)
@id.set_key(:pgp, pgp_key_string)
diff --git a/test/unit/keyring_test.rb b/test/unit/keyring_test.rb
index 059b8dd..c7df63e 100644
--- a/test/unit/keyring_test.rb
+++ b/test/unit/keyring_test.rb
@@ -21,6 +21,13 @@ class KeyringTest < ActiveSupport::TestCase
assert_equal 'new value', keyring.key_of_type('type')['value']
end
+ test 'raise on updating missing key' do
+ assert_raises Keyring::NotFound do
+ keyring.update 'type', rev: nil ,value: 'new value'
+ end
+ assert_nil keyring.key_of_type('type')
+ end
+
test 'raise on updating without rev' do
keyring.create 'type', 'value'
assert_raises Keyring::Error do
@@ -37,6 +44,35 @@ class KeyringTest < ActiveSupport::TestCase
assert_equal 'value', keyring.key_of_type('type')['value']
end
+ test 'delete key' do
+ keyring.create 'type', 'value'
+ initial_rev = keyring.key_of_type('type')['rev']
+ keyring.delete 'type', rev: initial_rev
+ assert_nil keyring.key_of_type('type')
+ end
+
+ test 'raise on deleting missing key' do
+ assert_raises Keyring::NotFound do
+ keyring.delete 'type', rev: nil
+ end
+ end
+
+ test 'raise on deleting without rev' do
+ keyring.create 'type', 'value'
+ assert_raises Keyring::Error do
+ keyring.delete 'type', rev: nil
+ end
+ assert_equal 'value', keyring.key_of_type('type')['value']
+ end
+
+ test 'raise on deleting with wrong rev' do
+ keyring.create 'type', 'value'
+ assert_raises Keyring::Error do
+ keyring.delete 'type', rev: 'wrong rev'
+ end
+ assert_equal 'value', keyring.key_of_type('type')['value']
+ end
+
protected
@@ -54,6 +90,10 @@ class KeyringTest < ActiveSupport::TestCase
self
end
+ def dummy.delete_key(type)
+ self.delete(type)
+ end
+
def dummy.save; end
end
end