Skip to content
Snippets Groups Projects
Commit 51d41e15 authored by azul's avatar azul
Browse files

Merge branch 'feature/katzenpost-keys' into 'master'

feature: hand out other key types like katzenpost keys

See merge request !22
parents a43e6476 0d622c21
Branches
No related tags found
1 merge request!22feature: hand out other key types like katzenpost keys
Pipeline #
...@@ -26,7 +26,7 @@ module Nickserver::CouchDB ...@@ -26,7 +26,7 @@ module Nickserver::CouchDB
protected protected
def key_response def key_response
format address: nick.to_s, openpgp: key format keys.merge(address: nick.to_s)
end end
def not_found_response def not_found_response
...@@ -37,8 +37,15 @@ module Nickserver::CouchDB ...@@ -37,8 +37,15 @@ module Nickserver::CouchDB
response.to_json response.to_json
end end
def key def keys
rows.first['value'] rows.first['value'].map do |k,v|
if k == 'pgp'
# created through webapps deprecated API
['openpgp', v]
else
[k, v['value']]
end
end.to_h
end end
def ok? def ok?
...@@ -46,7 +53,7 @@ module Nickserver::CouchDB ...@@ -46,7 +53,7 @@ module Nickserver::CouchDB
end end
def empty? def empty?
rows.empty? rows.empty? || keys.empty?
end end
def rows def rows
......
...@@ -9,7 +9,7 @@ module Nickserver::CouchDB ...@@ -9,7 +9,7 @@ module Nickserver::CouchDB
class Error < StandardError; end class Error < StandardError; end
class Source < Nickserver::Source class Source < Nickserver::Source
VIEW = '/_design/Identity/_view/pgp_key_by_email'.freeze VIEW = '/_design/Identity/_view/keys_by_email'.freeze
UNEXPECTED_RESPONSE_CODES = [401, 500].freeze UNEXPECTED_RESPONSE_CODES = [401, 500].freeze
def query(nick) def query(nick)
......
...@@ -4,8 +4,14 @@ ...@@ -4,8 +4,14 @@
"rows":[ "rows":[
{ {
"id":"c58e909ee1291985b9c5954efa1f91e7", "id":"c58e909ee1291985b9c5954efa1f91e7",
"key":"blue", "key":"blue@example.org",
"value": {
"openpgp" : {
"type" : "openpgp",
"rev" : "DUMMY_REV",
"value":"-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nVmQGiBEDsRrURBACwk7zArsD89vGDlCoBV55RzBeeIyoiNwg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U4m3L/nOwbTU4Osi5zilQZOTqIooMB+Wq5qCz7rvvzDHPBHF6OHwCg9Wrb\r\n9LT7e0PuRB0qTCyFjIhjB6ED/Ax2ma2D/at4/CVhno0hfZqd3bCCkQDvnArxQfZr\r\nFF3CpnF4djzouGiFYNi3h6y33qaD+ms9/TrewItvvHXgdtPTxHe+12mqWjYTyJPa\r\nN9fXun29YWQrycHLR1NcVo7bLJJ6ESSIhb2Ingo+rsCd5bdqfmMZ7Y0sb0jMrpqB\r\n/MNMA/9EfaKHi/eTREe0/04ZV5rS9tUYAz4elL0yOfwaSbDAgoUatgGAQaQpSBMG\r\n/e+pMyEu07u4Ft2MqG3hPu3Wph0TwWJMANOeFjG4HbJj/9TLYQB1J5mjZa3D091T\r\nxhu7oHzLT5gQL0chCCxHp61lx9tSMqQ/j7F0yZ9WZ8YFV8QDbYhJBCARCgAJBQJP\r\nv/MkAh0CAAoJEKTufqYlGMO1YscAnjrP1HfW10nbOJxxGtRjzdSmESMHAJwIcJMv\r\nX9uCVqwo45h514vu94/N7TPveF2rIEq4yW5IBqxG5aJ0dJDdGjg5GjvmVJtnNIux\r\nonXCYXLcPjkmO+yw8VHZWFUapeIDaWcsXlaBLv/L6uKrrgtrj8v3pUJuOfAuw9td\r\n5nwXz7JXWHEjjMk37HGQHa/fJVwHrRZm99c21jAD4tziZYl4lTM7afBPYiFDO8A0\r\nxBAy4R3dNf2CSBn0\r\n=qogX\r\n-----END PGP PUBLIC KEY BLOCK-----\r\n"
},
"katzenpost_link" : {
"type" : "katzenpost_link",
"value" : {
"one" : "DUMMY_KEY",
"two" : "DUMMY_KEY"
},
"rev" : "DUMMY_REV"
}
},
"key" : "red@test.me",
"id" : "be3af2f749f4dc0a7a786701b09ee11a"
}
],
"total_rows" : 352
}
{
"offset" : 21,
"rows" : [
{
"value" : {
"pgp" :"-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nVmQGiBEDsRrURBACwk7zArsD89vGDlCoBV55RzBeeIyoiNwgQuVlq+t8nGqRdPr+B\r\nZY1mCN6Bj/SOvPgG1DjBbh5CSXuYGzLEw9lkGlAY4VGVvQteHXf3ZpRRtj0SbzEq\r\nUUECLAU4m3L/nOwbTU4Osi5zilQZOTqIooMB+Wq5qCz7rvvzDHPBHF6OHwCg9Wrb\r\n9LT7e0PuRB0qTCyFjIhjB6ED/Ax2ma2D/at4/CVhno0hfZqd3bCCkQDvnArxQfZr\r\nFF3CpnF4djzouGiFYNi3h6y33qaD+ms9/TrewItvvHXgdtPTxHe+12mqWjYTyJPa\r\nN9fXun29YWQrycHLR1NcVo7bLJJ6ESSIhb2Ingo+rsCd5bdqfmMZ7Y0sb0jMrpqB\r\n/MNMA/9EfaKHi/eTREe0/04ZV5rS9tUYAz4elL0yOfwaSbDAgoUatgGAQaQpSBMG\r\n/e+pMyEu07u4Ft2MqG3hPu3Wph0TwWJMANOeFjG4HbJj/9TLYQB1J5mjZa3D091T\r\nxhu7oHzLT5gQL0chCCxHp61lx9tSMqQ/j7F0yZ9WZ8YFV8QDbYhJBCARCgAJBQJP\r\nv/MkAh0CAAoJEKTufqYlGMO1YscAnjrP1HfW10nbOJxxGtRjzdSmESMHAJwIcJMv\r\nX9uCVqwo45h514vu94/N7TPveF2rIEq4yW5IBqxG5aJ0dJDdGjg5GjvmVJtnNIux\r\nonXCYXLcPjkmO+yw8VHZWFUapeIDaWcsXlaBLv/L6uKrrgtrj8v3pUJuOfAuw9td\r\n5nwXz7JXWHEjjMk37HGQHa/fJVwHrRZm99c21jAD4tziZYl4lTM7afBPYiFDO8A0\r\nxBAy4R3dNf2CSBn0\r\n=qogX\r\n-----END PGP PUBLIC KEY BLOCK-----\r\n"
},
"key" : "red@test.me",
"id" : "be3af2f749f4dc0a7a786701b09ee11a"
}
],
"total_rows" : 352
}
...@@ -11,20 +11,58 @@ class Nickserver::CouchDB::ResponseTest < Minitest::Test ...@@ -11,20 +11,58 @@ class Nickserver::CouchDB::ResponseTest < Minitest::Test
assert_equal 404, response.status assert_equal 404, response.status
end end
def test_200_with_empty_response def test_404_because_of_empty_response
response = response_for 'stompy@example.org', response = response_for 'stompy@example.org',
status: 200, body: file_content(:empty_couchdb_result) status: 200,
body: file_content(:empty_couchdb_result)
assert_equal 404, response.status assert_equal 404, response.status
end end
def test_200_with_success def test_200_with_success
response = response_for 'blue@example.org', response = response_for 'blue@example.org',
status: 200, body: file_content(:blue_couchdb_result) status: 200, body:
file_content(:blue_couchdb_result)
assert_equal 200, response.status assert_equal 200, response.status
assert_equal file_content(:blue_nickserver_result), response.content assert_equal JSON.parse(file_content(:blue_nickserver_result)),
JSON.parse(response.content)
end
def test_200_with_other_keys
body_with_other_type = change_type(file_content(:blue_couchdb_result))
response = response_for 'blue@example.org',
status: 200,
body: body_with_other_type
assert_equal 200, response.status
expected = JSON.parse change_type(file_content(:blue_nickserver_result))
assert_equal expected, JSON.parse(response.content)
end
def test_openpgp_key_from_old_data_format
response = response_for 'red@example.org',
status: 200,
body: file_content(:red_couchdb_result_with_old_format)
assert_equal 200, response.status
data = JSON.parse response.content
assert_includes data.keys, 'address'
assert_includes data.keys, 'openpgp'
end
def test_katzenpost_key
response = response_for 'red@example.org',
status: 200,
body: file_content(:red_couchdb_result_with_katzenpost)
assert_equal 200, response.status
data = JSON.parse response.content
assert_includes data.keys, 'address'
assert_includes data.keys, 'katzenpost_link'
end end
def response_for(uid, couch_response = {}) def response_for(uid, couch_response = {})
Nickserver::CouchDB::Response.new uid, couch_response Nickserver::CouchDB::Response.new uid, couch_response
end end
def change_type(string)
string.gsub('openpgp', 'other')
end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment