Sha256: 6cd9fe58754249a91c9faade4f7c64e6383de55c6e6914393ee2d5ea4f461f83

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

#!/usr/bin/env ruby
# -*- coding: binary -*-

$:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..'))

require 'rex/test'
require 'rex/exceptions'
require 'rex/proto/dcerpc/uuid'

class Rex::Proto::DCERPC::UUID::UnitTest < Test::Unit::TestCase

	Klass = Rex::Proto::DCERPC::UUID

	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
		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')
		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

	def test_packing
		uuid = '367abb81-9844-35f1-ad32-98f038001003'
		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') }
	end

	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

	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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
librex-0.0.68 lib/rex/proto/dcerpc/uuid.rb.ut.rb
librex-0.0.66 lib/rex/proto/dcerpc/uuid.rb.ut.rb