Skip to content

Commit

Permalink
reorganize tests to match current conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Mell committed Nov 3, 2011
1 parent d0638ce commit 9c112b0
Show file tree
Hide file tree
Showing 81 changed files with 221 additions and 255 deletions.
2 changes: 1 addition & 1 deletion test/testutil.rb → test/support/test_data_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module OpenID
module TestDataMixin
TESTS_DIR = Pathname.new(__FILE__).dirname
TEST_DATA_DIR = Pathname.new('data')
TEST_DATA_DIR = Pathname.new('yadis_data')

def read_data_file(filename, lines=true, data_dir=TEST_DATA_DIR)
fname = TESTS_DIR.join(data_dir, filename)
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test/discoverdata.rb → test/support/yadis_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

module OpenID

module DiscoverData
module YadisData

include TestDataMixin
include Util
include TestUtil

TESTLIST = [
# success, input_name, id_name, result_name
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions test/test_accept.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

require 'test/unit'
require "test_helper"
require 'openid/yadis/accept'
require 'openid/extras'
require 'openid/util'
Expand Down
3 changes: 2 additions & 1 deletion test/test_association.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "test/unit"
require 'test_helper'
require 'support/test_util'
require "openid/association"

module OpenID
Expand Down
4 changes: 2 additions & 2 deletions test/test_associationmanager.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'test_helper'
require 'support/test_util'
require "openid/consumer/associationmanager"
require "openid/association"
require "openid/dh"
require "openid/util"
require "openid/cryptutil"
require "openid/message"
require "openid/store/memory"
require "test/unit"
require "util"
require "time"

module OpenID
Expand Down
5 changes: 2 additions & 3 deletions test/test_checkid_request.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require 'test_helper'
require 'support/test_util'
require "openid/consumer/checkid_request"
require "openid/message"
require "test/unit"
require "testutil"
require "util"

module OpenID
class Consumer
Expand Down
4 changes: 2 additions & 2 deletions test/test_consumer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'
require 'support/test_util'
require "openid/consumer"
require "test/unit"
require "testutil"

module OpenID
class Consumer
Expand Down
180 changes: 90 additions & 90 deletions test/test_cryptutil.rb
Original file line number Diff line number Diff line change
@@ -1,119 +1,119 @@
# coding: ASCII-8BIT
require 'test/unit'
require "test_helper"
require "openid/cryptutil"
require "pathname"

class CryptUtilTestCase < Test::Unit::TestCase
BIG = 2 ** 256
module OpenID
class CryptUtilTestCase < Test::Unit::TestCase
include TestDataMixin

def test_rand
# If this is not true, the rest of our test won't work
assert(BIG.is_a?(Bignum))
BIG = 2 ** 256

# It's possible that these will be small enough for fixnums, but
# extraorindarily unlikely.
a = OpenID::CryptUtil.rand(BIG)
b = OpenID::CryptUtil.rand(BIG)
assert(a.is_a?(Bignum))
assert(b.is_a?(Bignum))
assert_not_equal(a, b)
end
def test_rand
# If this is not true, the rest of our test won't work
assert(BIG.is_a?(Bignum))

def test_rand_doesnt_depend_on_srand
Kernel.srand(1)
a = OpenID::CryptUtil.rand(BIG)
Kernel.srand(1)
b = OpenID::CryptUtil.rand(BIG)
assert_not_equal(a, b)
end
# It's possible that these will be small enough for fixnums, but
# extraorindarily unlikely.
a = OpenID::CryptUtil.rand(BIG)
b = OpenID::CryptUtil.rand(BIG)
assert(a.is_a?(Bignum))
assert(b.is_a?(Bignum))
assert_not_equal(a, b)
end

def test_random_binary_convert
(0..500).each do
n = (0..10).inject(0) {|sum, element| sum + OpenID::CryptUtil.rand(BIG) }
s = OpenID::CryptUtil.num_to_binary n
assert(s.is_a?(String))
n_converted_back = OpenID::CryptUtil.binary_to_num(s)
assert_equal(n, n_converted_back)
def test_rand_doesnt_depend_on_srand
Kernel.srand(1)
a = OpenID::CryptUtil.rand(BIG)
Kernel.srand(1)
b = OpenID::CryptUtil.rand(BIG)
assert_not_equal(a, b)
end
end

def test_enumerated_binary_convert
{
"\x00" => 0,
"\x01" => 1,
"\x7F" => 127,
"\x00\xFF" => 255,
"\x00\x80" => 128,
"\x00\x81" => 129,
"\x00\x80\x00" => 32768,
"OpenID is cool" => 1611215304203901150134421257416556,
}.each do |str, num|
num_prime = OpenID::CryptUtil.binary_to_num(str)
str_prime = OpenID::CryptUtil.num_to_binary(num)
assert_equal(num, num_prime)
assert_equal(str, str_prime)
def test_random_binary_convert
(0..500).each do
n = (0..10).inject(0) {|sum, element| sum + OpenID::CryptUtil.rand(BIG) }
s = OpenID::CryptUtil.num_to_binary n
assert(s.is_a?(String))
n_converted_back = OpenID::CryptUtil.binary_to_num(s)
assert_equal(n, n_converted_back)
end
end

def test_enumerated_binary_convert
{
"\x00" => 0,
"\x01" => 1,
"\x7F" => 127,
"\x00\xFF" => 255,
"\x00\x80" => 128,
"\x00\x81" => 129,
"\x00\x80\x00" => 32768,
"OpenID is cool" => 1611215304203901150134421257416556,
}.each do |str, num|
num_prime = OpenID::CryptUtil.binary_to_num(str)
str_prime = OpenID::CryptUtil.num_to_binary(num)
assert_equal(num, num_prime)
assert_equal(str, str_prime)
end
end
end

def with_n2b64
test_dir = Pathname.new(__FILE__).dirname
filename = test_dir.join('data', 'n2b64')
File.open(filename) do |file|
file.each_line do |line|
def with_n2b64
read_data_file( 'n2b64').each do |line|
base64, base10 = line.chomp.split
yield base64, base10.to_i
end
end
end

def test_base64_to_num
with_n2b64 do |base64, num|
assert_equal(num, OpenID::CryptUtil.base64_to_num(base64))
def test_base64_to_num
with_n2b64 do |base64, num|
assert_equal(num, OpenID::CryptUtil.base64_to_num(base64))
end
end
end

def test_base64_to_num_invalid
assert_raises(ArgumentError) {
OpenID::CryptUtil.base64_to_num('!@#$')
}
end
def test_base64_to_num_invalid
assert_raises(ArgumentError) {
OpenID::CryptUtil.base64_to_num('!@#$')
}
end

def test_num_to_base64
with_n2b64 do |base64, num|
assert_equal(base64, OpenID::CryptUtil.num_to_base64(num))
def test_num_to_base64
with_n2b64 do |base64, num|
assert_equal(base64, OpenID::CryptUtil.num_to_base64(num))
end
end
end

def test_randomstring
s1 = OpenID::CryptUtil.random_string(42)
assert_equal(42, s1.length)
s2 = OpenID::CryptUtil.random_string(42)
assert_equal(42, s2.length)
assert_not_equal(s1, s2)
end
def test_randomstring
s1 = OpenID::CryptUtil.random_string(42)
assert_equal(42, s1.length)
s2 = OpenID::CryptUtil.random_string(42)
assert_equal(42, s2.length)
assert_not_equal(s1, s2)
end

def test_randomstring_population
s1 = OpenID::CryptUtil.random_string(42, "XO")
assert_match(/[XO]{42}/, s1)
end
def test_randomstring_population
s1 = OpenID::CryptUtil.random_string(42, "XO")
assert_match(/[XO]{42}/, s1)
end

def test_sha1
assert_equal("\x11\xf6\xad\x8e\xc5*)\x84\xab\xaa\xfd|;Qe\x03x\\ r",
OpenID::CryptUtil.sha1('x'))
end
def test_sha1
assert_equal("\x11\xf6\xad\x8e\xc5*)\x84\xab\xaa\xfd|;Qe\x03x\\ r",
OpenID::CryptUtil.sha1('x'))
end

def test_hmac_sha1
assert_equal("\x8bo\xf7O\xa7\x18*\x90\xac ah\x16\xf7\xb8\x81JB\x9f|",
OpenID::CryptUtil.hmac_sha1('x', 'x'))
end
def test_hmac_sha1
assert_equal("\x8bo\xf7O\xa7\x18*\x90\xac ah\x16\xf7\xb8\x81JB\x9f|",
OpenID::CryptUtil.hmac_sha1('x', 'x'))
end

def test_sha256
assert_equal("-q\x16B\xb7&\xb0D\x01b|\xa9\xfb\xac2\xf5\xc8S\x0f\xb1\x90<\xc4\xdb\x02%\x87\x17\x92\x1aH\x81",
OpenID::CryptUtil.sha256('x'))
end
def test_sha256
assert_equal("-q\x16B\xb7&\xb0D\x01b|\xa9\xfb\xac2\xf5\xc8S\x0f\xb1\x90<\xc4\xdb\x02%\x87\x17\x92\x1aH\x81",
OpenID::CryptUtil.sha256('x'))
end

def test_hmac_sha256
assert_equal("\x94{\xd2w\xb2\xd3\\\xfc\x07\xfb\xc7\xe3b\xf2iuXz1\xf8:}\xffx\x8f\xda\xc1\xfaC\xc4\xb2\x87",
OpenID::CryptUtil.hmac_sha256('x', 'x'))
def test_hmac_sha256
assert_equal("\x94{\xd2w\xb2\xd3\\\xfc\x07\xfb\xc7\xe3b\xf2iuXz1\xf8:}\xffx\x8f\xda\xc1\xfaC\xc4\xb2\x87",
OpenID::CryptUtil.hmac_sha256('x', 'x'))
end
end
end
3 changes: 1 addition & 2 deletions test/test_dh.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'test/unit'
require "test_helper"
require 'openid/dh'
require 'testutil'

module OpenID
class DiffieHellmanExposed < OpenID::DiffieHellman
Expand Down
10 changes: 3 additions & 7 deletions test/test_discover.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@

require 'testutil'
require 'util'

require 'test/unit'
require 'test_helper'
require 'openid/fetchers'
require 'openid/yadis/discovery'
require 'openid/consumer/discovery'
Expand Down Expand Up @@ -48,7 +44,7 @@ def test_discovery_failure
@responses.each { |response_set|
@url = response_set[0].final_url
OpenID.fetcher = SimpleMockFetcher.new(self, response_set)

expected_status = response_set[-1].code
begin
OpenID.discover(@url)
Expand Down Expand Up @@ -228,7 +224,7 @@ def test_blank
# def readDataFile(filename):
# module_directory = os.path.dirname(os.path.abspath(__file__))
# filename = os.path.join(
# module_directory, 'data', 'test_discover', filename)
# module_directory, 'yadis_data', 'test_discover', filename)
# return file(filename).read()

class TestDiscovery < BaseTestDiscovery
Expand Down
7 changes: 2 additions & 5 deletions test/test_discovery_manager.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

require 'test/unit'
require "test_helper"
require 'openid/consumer/discovery_manager'
require 'openid/extras'

require 'testutil'

module OpenID
class TestDiscoveredServices < Test::Unit::TestCase
def setup
Expand Down Expand Up @@ -41,7 +38,7 @@ def test_started
@disco_services.next
assert(@disco_services.started?)
@disco_services.next
assert(@disco_services.started?)
assert(@disco_services.started?)
@disco_services.next
assert(!@disco_services.started?)
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_extension.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'test_helper'
require 'openid/extension'
require 'openid/message'
require 'test/unit'

module OpenID
class DummyExtension < OpenID::Extension
Expand Down Expand Up @@ -29,7 +29,7 @@ def test_OpenID1
assert_equal(DummyExtension::TEST_ALIAS,
namespaces.get_alias(DummyExtension::TEST_URI))
end

def test_OpenID2
oid2_msg = Message.new(OPENID2_NS)
ext = DummyExtension.new
Expand Down
2 changes: 1 addition & 1 deletion test/test_extras.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'test/unit'
require "test_helper"
require 'openid/extras'

class StartsWithTestCase < Test::Unit::TestCase
Expand Down
Loading

0 comments on commit 9c112b0

Please sign in to comment.