1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
###############################################################################
#
# The MIT License (MIT)
#
# Copyright (c) Crossbar.io Technologies GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
###############################################################################
from autobahn.wamp.message import check_or_raise_realm_name, identity_realm_name_category
from autobahn.wamp.exception import InvalidUriError
import unittest
class TestWampIdentifiers(unittest.TestCase):
def test_valid_realm_names(self):
for name in [
'realm1',
'com.example.myapp1',
'myapp1.example.com',
'eth.wamp-proto',
'wamp-proto.eth',
'eth.wamp-proto.myapp1',
'myapp1.wamp-proto.eth',
'aaa',
'Abc',
'a00',
'A00',
'0x0000000000000000000000000000000000000000',
'0xe59C7418403CF1D973485B36660728a5f4A8fF9c',
]:
self.assertEqual(name, check_or_raise_realm_name(name))
def test_invalid_realm_names(self):
for name in [
None,
23,
{},
'',
'.realm1',
'123realm',
'0x' + '00' * 64,
'0x' + '00' * 32,
'0x' + 'zz' * 40,
'rlm$test',
'a' * 256,
]:
self.assertRaises(InvalidUriError, check_or_raise_realm_name, name)
def test_realm_name_categories(self):
for name, category in [
# valid
('realm1', 'normal'),
('com.example.myapp1', 'normal'),
('myapp1.example.com', 'normal'),
('eth.wamp-proto', 'reverse_ens'),
('wamp-proto.eth', 'ens'),
('eth.wamp-proto.myapp1', 'reverse_ens'),
('myapp1.wamp-proto.eth', 'ens'),
('aaa', 'normal'),
('Abc', 'normal'),
('a00', 'normal'),
('A00', 'normal'),
('0x0000000000000000000000000000000000000000', 'eth'),
('0xe59C7418403CF1D973485B36660728a5f4A8fF9c', 'eth'),
# invalid
(None, None),
(23, None),
({}, None),
('', None),
('.realm1', None),
('123realm', None),
('0x' + '00' * 64, None),
('0x' + '00' * 32, None),
('0x' + 'zz' * 40, None),
('rlm$test', None),
('a' * 256, None),
]:
self.assertEqual(category, identity_realm_name_category(name))
|