diff options
author | Azul <azul@riseup.net> | 2016-05-25 13:13:30 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-05-25 14:13:30 +0200 |
commit | 8a81429f0eb8aa5041d47557d0c5b5359bb959e6 (patch) | |
tree | 10f5d3db69883c685408edc3365d1e762f13e322 /test | |
parent | 5c0fa0fb7b10820f2956807cb457421bf1e00708 (diff) |
copy over all files from rewritten attempt
I started a nickserver from scratch to implement the things that are independent of our choice of stack (eventmachine or other).
This commit copies them over and tests both things in parallel.
Diffstat (limited to 'test')
-rw-r--r-- | test/file_content.rb | 11 | ||||
-rw-r--r-- | test/integration/couch_db/source_test.rb | 29 | ||||
-rw-r--r-- | test/test_helper.rb | 1 | ||||
-rw-r--r-- | test/unit/adapters/couch_db.rb | 15 | ||||
-rw-r--r-- | test/unit/adapters/local_test.rb | 5 | ||||
-rw-r--r-- | test/unit/couch_db/response_test.rb | 30 | ||||
-rw-r--r-- | test/unit/couch_db/source_unit_test.rb | 17 | ||||
-rw-r--r-- | test/unit/hkp/v_index_response_test.rb | 17 | ||||
-rw-r--r-- | test/unit/hkp_test.rb | 16 | ||||
-rw-r--r-- | test/unit/invalid_source_test.rb | 16 | ||||
-rw-r--r-- | test/unit/lookup_test.rb | 23 | ||||
-rw-r--r-- | test/unit/nickname_test.rb | 28 | ||||
-rw-r--r-- | test/unit/response_test.rb | 11 |
13 files changed, 211 insertions, 8 deletions
diff --git a/test/file_content.rb b/test/file_content.rb new file mode 100644 index 0000000..0d0ac21 --- /dev/null +++ b/test/file_content.rb @@ -0,0 +1,11 @@ +module FileContent + + def file_content(filename) + (@file_contents ||= {})[filename] ||= File.read(file_path(filename)) + end + + def file_path(filename) + "%s/files/%s" % [File.dirname(__FILE__), filename] + end + +end diff --git a/test/integration/couch_db/source_test.rb b/test/integration/couch_db/source_test.rb new file mode 100644 index 0000000..9e319f4 --- /dev/null +++ b/test/integration/couch_db/source_test.rb @@ -0,0 +1,29 @@ +require 'test_helper' +require 'file_content' +require 'nickserver/couch_db/source' + +module Nickserver::CouchDB + class SourceTest < Minitest::Test + include FileContent + + class TestAdapter + def initialize(status, content) + @status = status + @content = content + end + + def get(url, opts) + yield @status, @content + end + end + + def test_couch_query_and_response + adapter = TestAdapter.new 200, file_content(:blue_couchdb_result) + source = Source.new adapter + source.query 'blue@example.org' do |response| + assert_equal 200, response.status + assert_equal file_content(:blue_nickserver_result), response.content + end + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index d4765bc..842f05f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,6 +5,7 @@ require 'bundler/setup' require 'minitest/autorun' require 'webmock/minitest' require 'nickserver' +require 'minitest/pride' TESTING = true diff --git a/test/unit/adapters/couch_db.rb b/test/unit/adapters/couch_db.rb new file mode 100644 index 0000000..339e4f4 --- /dev/null +++ b/test/unit/adapters/couch_db.rb @@ -0,0 +1,15 @@ +require 'testhelper' +require 'nickserver/adapters/couch_db' + +class Nickserver::Adapters::CouchDBTest < Minitest::Test + + def test_query_404 + adapter.query(nil) do |status, content| + assert_equal 404, status + end + end + + def adapter + @adapter ||= Nickserver::Adapters::CouchDB.new + end +end diff --git a/test/unit/adapters/local_test.rb b/test/unit/adapters/local_test.rb new file mode 100644 index 0000000..97d394f --- /dev/null +++ b/test/unit/adapters/local_test.rb @@ -0,0 +1,5 @@ +require 'test_helper' +require 'nickserver/adapters/local' + +class Nickserver::Adapters::LocalTest < Minitest::Test +end diff --git a/test/unit/couch_db/response_test.rb b/test/unit/couch_db/response_test.rb new file mode 100644 index 0000000..d44760d --- /dev/null +++ b/test/unit/couch_db/response_test.rb @@ -0,0 +1,30 @@ +require 'test_helper' +require 'file_content' +require 'nickserver/couch_db/response' + +class Nickserver::CouchDB::ResponseTest < Minitest::Test + include FileContent + + def test_404 + response = response_for "bananas@example.org", + status: 404, body: "{}" + assert_equal 404, response.status + end + + def test_200_with_empty_response + response = response_for "stompy@example.org", + status: 200, body: file_content(:empty_couchdb_result) + assert_equal 404, response.status + end + + def test_200_with_success + response = response_for "blue@example.org", + status: 200, body: file_content(:blue_couchdb_result) + assert_equal 200, response.status + assert_equal file_content(:blue_nickserver_result), response.content + end + + def response_for(uid, couch_response = {}) + Nickserver::CouchDB::Response.new uid, couch_response + end +end diff --git a/test/unit/couch_db/source_unit_test.rb b/test/unit/couch_db/source_unit_test.rb new file mode 100644 index 0000000..19ea9bc --- /dev/null +++ b/test/unit/couch_db/source_unit_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' +require 'nickserver/couch_db/source' + +module Nickserver::CouchDB + class SourceUnitTest < Minitest::Test + + def test_query + address = "nick@domain.tl" + adapter = Minitest::Mock.new + adapter.expect :get, nil, + [String, {query: { reduce: "false", key: "\"#{address}\"" }}] + query = Source.new(adapter) + query.query address + adapter.verify + end + end +end diff --git a/test/unit/hkp/v_index_response_test.rb b/test/unit/hkp/v_index_response_test.rb new file mode 100644 index 0000000..d909520 --- /dev/null +++ b/test/unit/hkp/v_index_response_test.rb @@ -0,0 +1,17 @@ +require 'test_helper' +require 'file_content' +require 'nickserver/hkp/v_index_response' + +class Nickserver::Hkp::VIndexResponseTest < Minitest::Test + include FileContent + + def test_leap_public_key + response = response_for 'cloudadmin@leap.se', + body: file_content(:leap_vindex_result) + assert_equal 'E818C478D3141282F7590D29D041EB11B1647490', response.keys.first.keyid + end + + def response_for(uid, hkp_response = {}) + Nickserver::Hkp::VIndexResponse.new uid, hkp_response + end +end diff --git a/test/unit/hkp_test.rb b/test/unit/hkp_test.rb index 0ecde2d..fc3cf97 100644 --- a/test/unit/hkp_test.rb +++ b/test/unit/hkp_test.rb @@ -29,7 +29,7 @@ class HkpTest < Minitest::Test def test_key_info_not_found uid = 'leaping_lemur@leap.se' stub_sks_vindex_reponse(uid, status: 404) - test_em_errback "Nickserver::HKP::FetchKeyInfo.new.search '#{uid}'" do |error| + test_em_errback "Nickserver::Hkp::FetchKeyInfo.new.search '#{uid}'" do |error| assert_equal 404, error end end @@ -37,7 +37,7 @@ class HkpTest < Minitest::Test def test_no_matching_key_found uid = 'leaping_lemur@leap.se' stub_sks_vindex_reponse(uid, status: 200) - test_em_errback "Nickserver::HKP::FetchKeyInfo.new.search '#{uid}'" do |error| + test_em_errback "Nickserver::Hkp::FetchKeyInfo.new.search '#{uid}'" do |error| assert_equal 404, error end end @@ -48,7 +48,7 @@ class HkpTest < Minitest::Test stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result)) stub_sks_get_reponse(key_id, body: file_content(:leap_public_key)) - test_em_callback "Nickserver::HKP::FetchKey.new.get '#{uid}'" do |key_text| + test_em_callback "Nickserver::Hkp::FetchKey.new.get '#{uid}'" do |key_text| assert_equal file_content(:leap_public_key), key_text end end @@ -60,7 +60,7 @@ class HkpTest < Minitest::Test stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result)) stub_sks_get_reponse(key_id, status: 404) - test_em_errback "Nickserver::HKP::FetchKey.new.get '#{uid}'" do |error| + test_em_errback "Nickserver::Hkp::FetchKey.new.get '#{uid}'" do |error| assert_equal 404, error end end @@ -70,7 +70,7 @@ class HkpTest < Minitest::Test key_id = '9A753A6B' stub_sks_vindex_reponse(uid, body: file_content(:short_key_vindex_result)) - test_em_errback "Nickserver::HKP::FetchKey.new.get '#{uid}'" do |error| + test_em_errback "Nickserver::Hkp::FetchKey.new.get '#{uid}'" do |error| assert_equal 500, error end end @@ -83,7 +83,7 @@ class HkpTest < Minitest::Test def test_key_info_real_network real_network do uid = 'elijah@riseup.net' - test_em_callback "Nickserver::HKP::FetchKeyInfo.new.search '#{uid}'" do |keys| + test_em_callback "Nickserver::Hkp::FetchKeyInfo.new.search '#{uid}'" do |keys| assert_equal 1, keys.size assert keys.first.keyid =~ /00440025$/ end @@ -100,7 +100,7 @@ class HkpTest < Minitest::Test #stub_config(:hkp_ca_file, file_path('autistici-ca.pem')) do assert File.exist?(Nickserver::Config.hkp_ca_file) uid = 'elijah@riseup.net' - test_em_callback "Nickserver::HKP::FetchKeyInfo.new.search '#{uid}'" do |keys| + test_em_callback "Nickserver::Hkp::FetchKeyInfo.new.search '#{uid}'" do |keys| assert_equal 1, keys.size assert keys.first.keyid =~ /00440025$/ end @@ -157,7 +157,7 @@ class HkpTest < Minitest::Test def fetch_key_info(body_source, uid, &block) stub_sks_vindex_reponse(uid, body: file_content(body_source)) - test_em_callback "Nickserver::HKP::FetchKeyInfo.new.search '#{uid}'", &block + test_em_callback "Nickserver::Hkp::FetchKeyInfo.new.search '#{uid}'", &block end end diff --git a/test/unit/invalid_source_test.rb b/test/unit/invalid_source_test.rb new file mode 100644 index 0000000..37a38fc --- /dev/null +++ b/test/unit/invalid_source_test.rb @@ -0,0 +1,16 @@ +require 'test_helper' +require 'nickserver/invalid_source' + +class Nickserver::InvalidSourceTest < Minitest::Test + + def test_query + adapter.query(nil) do |status, content| + assert_equal 500, status + assert_equal "Not a valid address", content + end + end + + def adapter + Nickserver::InvalidSource.new + end +end diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb new file mode 100644 index 0000000..ac827e0 --- /dev/null +++ b/test/unit/lookup_test.rb @@ -0,0 +1,23 @@ +require 'test_helper' +require 'minitest/mock' +require 'nickserver/lookup' + +class TestLookup < Nickserver::Lookup + + def query + yield 200, 'yeah' + end + +end + +class LookupTest < Minitest::Test + + def test_responding + responder = Minitest::Mock.new + responder.expect :send_response, nil, + [{status: 200, content: 'yeah'}] + lookup = TestLookup.new nil + lookup.respond_with responder + responder.verify + end +end diff --git a/test/unit/nickname_test.rb b/test/unit/nickname_test.rb new file mode 100644 index 0000000..8681545 --- /dev/null +++ b/test/unit/nickname_test.rb @@ -0,0 +1,28 @@ +require 'test_helper' +require 'nickserver/nickname' + +class NicknameTest < Minitest::Test + + def test_local + nick = Nickserver::Nickname.new 'nick@test.me' + assert nick.local? + assert !nick.remote? + end + + def test_remote + nick = Nickserver::Nickname.new 'nick@remote.domain' + assert !nick.local? + assert nick.remote? + end + + def test_valid + nick = Nickserver::Nickname.new 'nick@remote.domain' + assert nick.valid? + end + + def test_invalid + nick = Nickserver::Nickname.new 'asdf' + assert nick.invalid? + end + +end diff --git a/test/unit/response_test.rb b/test/unit/response_test.rb new file mode 100644 index 0000000..8a53066 --- /dev/null +++ b/test/unit/response_test.rb @@ -0,0 +1,11 @@ +require 'test_helper' +require 'nickserver/response' + +class ResponseTest < Minitest::Test + + def test_content + response = Nickserver::Response.new 500, "Not a valid address" + assert_equal "500 Not a valid address", response.content + end + +end |