From 54653f75cf44890310a06c3a8a6be59625629d2a Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 19 Jan 2018 14:11:24 +0100 Subject: API: implement deleting keys through new keys api --- features/2/keys.feature | 89 ++++++++++++++++++++++++++++++++-- features/step_definitions/key_steps.rb | 6 +++ 2 files changed, 91 insertions(+), 4 deletions(-) (limited to 'features') diff --git a/features/2/keys.feature b/features/2/keys.feature index cc87da0..83e70e7 100644 --- a/features/2/keys.feature +++ b/features/2/keys.feature @@ -114,6 +114,19 @@ Feature: Handle current users collection of keys } """ + Scenario: Publishing an empty key fails + When I send a POST request to "2/keys" with the following: + """ + {} + """ + Then the response status should be "422" + And the response should be: + """ + { + "error": "param is missing or the value is empty: type" + } + """ + Scenario: Updating an existing key Given I have published a "openpgp" key When I send a PATCH request to "2/keys/openpgp" with the following: @@ -127,6 +140,24 @@ Feature: Handle current users collection of keys Then the response status should be "204" And I should have published a "openpgp" key with value "QWER" + Scenario: Updating a missing key raises + When I send a PATCH request to "2/keys/openpgp" with the following: + """ + { + "type": "openpgp", + "value": "QWER", + "rev": "DUMMY_REV" + } + """ + Then the response status should be "404" + And the response should be: + """ + { + "error": "no such key: openpgp" + } + """ + And I should not have published a "openpgp" key + Scenario: Updating an existing key require revision Given I have published a "openpgp" key When I send a PATCH request to "2/keys/openpgp" with the following: @@ -162,15 +193,65 @@ Feature: Handle current users collection of keys } """ - Scenario: Publishing an empty key fails - When I send a POST request to "2/keys" with the following: + Scenario: Deleting an existing key + Given I have published a "openpgp" key + When I send a DELETE request to "2/keys/openpgp" with the following: """ - {} + { + "type": "openpgp", + "rev": "DUMMY_REV" + } + """ + Then the response status should be "204" + And I should not have published a "openpgp" key + + Scenario: Deleting a missing key raises + When I send a DELETE request to "2/keys/openpgp" with the following: + """ + { + "type": "openpgp", + "rev": "DUMMY_REV" + } + """ + Then the response status should be "404" + And the response should be: + """ + { + "error": "no such key: openpgp" + } + """ + + Scenario: Deleting an existing key require revision + Given I have published a "openpgp" key + When I send a DELETE request to "2/keys/openpgp" with the following: + """ + { + "type": "openpgp" + } """ Then the response status should be "422" And the response should be: """ { - "error": "param is missing or the value is empty: type" + "error": "param is missing or the value is empty: rev" + } + """ + And I should have published a "openpgp" key + + Scenario: Deleting an existing key require right revision + Given I have published a "openpgp" key + When I send a DELETE request to "2/keys/openpgp" with the following: + """ + { + "type": "openpgp", + "rev": "WRONG_REV" } """ + Then the response status should be "422" + And the response should be: + """ + { + "error": "wrong revision: WRONG_REV" + } + """ + And I should have published a "openpgp" key diff --git a/features/step_definitions/key_steps.rb b/features/step_definitions/key_steps.rb index 70a13bd..3d5e015 100644 --- a/features/step_definitions/key_steps.rb +++ b/features/step_definitions/key_steps.rb @@ -18,3 +18,9 @@ Then /^I should have published an? "([^"]*)" key(?: with value "([^"]*)")?$/ do assert_includes keys.keys, type assert_equal value, JSON.parse(keys[type])['value'] if value end + +Then /^I should not have published an? "([^"]*)" key$/ do |type| + identity = Identity.for(@user) + keys = identity.keys + refute_includes keys.keys, type +end -- cgit v1.2.3