2005-12-17 06:46:23 +00:00
|
|
|
#!/usr/bin/env ruby
|
2005-07-25 09:34:53 +00:00
|
|
|
|
|
|
|
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..'))
|
|
|
|
|
2005-12-13 06:08:40 +00:00
|
|
|
require 'rex/test'
|
2005-11-30 19:42:19 +00:00
|
|
|
require 'rex/exceptions'
|
2005-07-25 09:34:53 +00:00
|
|
|
require 'rex/proto/dcerpc/uuid'
|
2005-11-30 19:42:19 +00:00
|
|
|
|
2005-07-25 09:34:53 +00:00
|
|
|
class Rex::Proto::DCERPC::UUID::UnitTest < Test::Unit::TestCase
|
|
|
|
|
2005-11-30 19:42:19 +00:00
|
|
|
Klass = Rex::Proto::DCERPC::UUID
|
|
|
|
|
2006-01-27 05:29:06 +00:00
|
|
|
def test_is_uuid
|
|
|
|
assert(Klass.is?('afa8bd80-7d8a-11c9-bef4-08002b102989'), 'valid')
|
|
|
|
assert(!Klass.is?('afa8bd80-7d8a-11c9-bef4-08002b10298'), 'too short')
|
|
|
|
assert(!Klass.is?('afa8bd80-7d8a-11c9-bef4-08002b10298Z'), 'invalid character')
|
|
|
|
assert(!Klass.is?('afa8bd80-7d8a-11c9-bef4a08002b10298a'), 'missing dash')
|
|
|
|
assert(!Klass.is?('afa8bd80-7d8a-11c9-bef-a08002b10298a'), 'dash in wrong place')
|
|
|
|
assert_raise(Rex::ArgumentError, 'pack - too short') { Klass.is?(nil) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_lookup
|
2005-11-30 19:42:19 +00:00
|
|
|
assert_equal(Klass.uuid_by_name('MGMT'), 'afa8bd80-7d8a-11c9-bef4-08002b102989', 'uuid_by_name')
|
|
|
|
assert_equal(Klass.vers_by_name('MGMT'), '2.0', 'vers_by_name')
|
2006-01-27 05:29:06 +00:00
|
|
|
assert(!Klass.uuid_by_name('NO_SUCH_UUID'), 'uuid_by_name - invalid')
|
|
|
|
assert(!Klass.vers_by_name('NO_SUCH_UUID'), 'vers_by_name - invalid')
|
|
|
|
end
|
2005-11-30 19:42:19 +00:00
|
|
|
|
|
|
|
def test_packing
|
|
|
|
uuid = '367abb81-9844-35f1-ad32-98f038001003'
|
2006-01-27 05:29:06 +00:00
|
|
|
assert_equal(Klass.uuid_pack(uuid), "\201\273z6D\230\3615\2552\230\3608\000\020\003", 'pack')
|
|
|
|
assert_equal(Klass.uuid_unpack("\201\273z6D\230\3615\2552\230\3608\000\020\003"), uuid, 'unpack')
|
|
|
|
assert_raise(Rex::ArgumentError, 'pack - too short') { Klass.uuid_pack('foo') }
|
|
|
|
assert_raise(Rex::ArgumentError, 'unpack - too short') { Klass.uuid_unpack('foo') }
|
2005-07-25 09:34:53 +00:00
|
|
|
end
|
2005-11-30 19:42:19 +00:00
|
|
|
|
2006-01-27 05:29:06 +00:00
|
|
|
def test_xfer
|
|
|
|
assert_equal(Klass.xfer_syntax_uuid(), "\004]\210\212\353\034\311\021\237\350\010\000+\020H`", 'xfer_syntax_uuid')
|
|
|
|
assert_equal(Klass.xfer_syntax_vers(), '2.0', 'xfer_syntax_vers')
|
|
|
|
end
|
2005-11-30 19:42:19 +00:00
|
|
|
|
2006-01-27 05:29:06 +00:00
|
|
|
def test_vers
|
|
|
|
assert_equal(Klass.vers_to_nums('2.0'), [2, 0], 'vers_to_nums')
|
|
|
|
assert_equal(Klass.vers_to_nums('2'), [2, 0], 'vers_to_nums (short)')
|
|
|
|
end
|
2008-10-19 21:03:39 +00:00
|
|
|
end
|