Commit c0020cc9 authored by mashony's avatar mashony
Browse files

fix: allow extra attrs for broker_info section

parent 487e8c3a
......@@ -147,4 +147,4 @@ help:
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
@echo ''
\ No newline at end of file
@echo ''
......@@ -87,7 +87,9 @@ def load_auth(file_path: str) -> None:
for group_users in config.values():
for user, user_data in group_users.items():
user_data['name'] = user
user_data['broker_info'] = BrokerInfo(**user_data.get('broker_info', {}))
broker_info_data = user_data.get('broker_info', {})
legal_name = broker_info_data.get("legal_name") if broker_info_data else None
user_data['broker_info'] = BrokerInfo(legal_name=legal_name)
users[user_data['token']] = User(**user_data)
AUTH_FILE = users
......
auction:
auction:
token: d968fff1fa406e91912814cde923717ab80bf3123c8854879e4d03106d1bac3f
broker_info:
legal_name:
uk_UA: auction
en_US: auction
procedures:
renewables:
- procedure
......@@ -22,9 +18,6 @@ brokers:
auto_tests:
token: bc8025adfec6bbeec7c6a97ba8d0bcab2e388c5ee2e67e910977b9d35739e6db
broker_info:
legal_name:
uk_UA: auto_tests
en_US: auto_tests
procedures:
renewables:
- procedure
......@@ -41,6 +34,8 @@ brokers:
legal_name:
uk_UA: test_broker_1
en_US: test_broker_1
some:
test_value: 1123
procedures:
renewables:
- procedure
......@@ -73,3 +68,26 @@ brokers:
railwayCargo:
- procedure
- bids
test_broker_ips:
token: 8d8314b0f231264980a4e85acd487a2fe2ad0cf0e0040c7e5cc75d0d62764c32
broker_info:
legal_name:
uk_UA: test_broker_ips
en_US: test_broker_ips
ips:
- 255.255.255.255
- 0.0.0.0/30
- 255.255.255.128/30
procedures:
renewables:
- procedure
- bids
timber:
- procedure
- bids
subsoil:
- procedure
- bids
railwayCargo:
- procedure
- bids
......@@ -33,7 +33,7 @@ class UserTestCase(unittest.TestCase):
class AuthTestCase(unittest.TestCase):
auth_file = '/secrets/auth.yml'
auth_file = 'test/test_secrets/auth.yml'
def test_load_auth(self):
auth.AUTH_FILE = None
......@@ -47,6 +47,27 @@ class AuthTestCase(unittest.TestCase):
self.assertEqual(u.name, 'test_broker_2')
self.assertEqual(len(u.procedures), 4)
def test_user_has_access_by_ips(self):
auth.load_auth(self.auth_file)
u = auth._get_user_by_token('test_ips')
self.assertEqual(u.name, 'test_broker_ips')
self.assertEqual(len(u.procedures), 4)
self.assertTrue(u.has_access_by_ip('255.255.255.255'))
self.assertFalse(u.has_access_by_ip('255.255.255.254'))
# check subnet mask
self.assertTrue(u.has_access_by_ip('0.0.0.0'))
self.assertTrue(u.has_access_by_ip('0.0.0.1'))
self.assertTrue(u.has_access_by_ip('0.0.0.2'))
self.assertTrue(u.has_access_by_ip('0.0.0.3'))
self.assertFalse(u.has_access_by_ip('0.0.0.4'))
self.assertTrue(u.has_access_by_ip('255.255.255.128'))
self.assertTrue(u.has_access_by_ip('255.255.255.129'))
self.assertTrue(u.has_access_by_ip('255.255.255.130'))
self.assertTrue(u.has_access_by_ip('255.255.255.131'))
self.assertFalse(u.has_access_by_ip('255.255.255.132'))
def test_user_legal_name(self):
auth.load_auth(self.auth_file)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment