summaryrefslogtreecommitdiff
path: root/test/support/http_stub_helper.rb
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2017-07-24 09:55:28 +0200
committerAzul <azul@riseup.net>2017-07-24 10:03:22 +0200
commitb1738a78ccf5768f92068a27255f9f69be1c3147 (patch)
tree6cad7ae458d6bc349a0ba925f82477feb2010fa1 /test/support/http_stub_helper.rb
parentcfa6395c7e5728de02221b94b5f9cfe8a4debf09 (diff)
fix: #3 handle domains without A-record
If a domain only has an mx record but no A record it will trigger a ConnectionError when attempting the nicknym key lookup. We need to detect and handle this in the http adapter already because once the exception is handled by Celluloid our actor will be terminated. So now we allow for handing a rescue option to the adapter with a string that is checked for inclusion in the error message. If the string is found the exception will be caught and the adapter returns nil. We only make use of this when checking the availability of nicknym so far. That should be the only http request going out.
Diffstat (limited to 'test/support/http_stub_helper.rb')
-rw-r--r--test/support/http_stub_helper.rb27
1 files changed, 13 insertions, 14 deletions
diff --git a/test/support/http_stub_helper.rb b/test/support/http_stub_helper.rb
index c9f2bfa..4e3d89b 100644
--- a/test/support/http_stub_helper.rb
+++ b/test/support/http_stub_helper.rb
@@ -10,32 +10,31 @@ module HttpStubHelper
end
def stub_nicknym_available_response(domain, response = {})
- stub_http_request :get, "https://#{domain}/provider.json",
- response: response
+ stub_http_get "https://#{domain}/provider.json",
+ response,
+ Hash
end
def stub_sks_vindex_reponse(uid, response = {})
- stub_http_request :get, config.hkp_url,
- query: {op: 'vindex', search: uid, exact: 'on', options: 'mr', fingerprint: 'on'},
- response: response
+ stub_http_get config.hkp_url, response,
+ query: {op: 'vindex', search: uid, exact: 'on', options: 'mr', fingerprint: 'on'}
end
def stub_sks_get_reponse(key_id, response = {})
- stub_http_request :get, config.hkp_url,
- query: {op: 'get', search: "0x"+key_id, exact: 'on', options: 'mr'},
- response: response
+ stub_http_get config.hkp_url, response,
+ query: {op: 'get', search: "0x"+key_id, exact: 'on', options: 'mr'}
end
def stub_couch_response(uid, response = {})
query = "\?key=#{"%22#{uid}%22"}&reduce=false"
- stub_http_request :get,
- /#{Regexp.escape(config.couch_url)}.*#{query}/,
- response: response
+ stub_http_get /#{Regexp.escape(config.couch_url)}.*#{query}/,
+ response
end
- def stub_http_request(verb, url, options = {})
- response = {status: 200, body: ""}.merge(options.delete(:response) || {})
- options = nil if options == {}
+ private
+
+ def stub_http_get(url, response, options = nil)
+ response = {status: 200, body: ""}.merge(response || {})
adapter.expect :get, [response[:status], response[:body]],
[url, options].compact
end