Skip to content

Commit

Permalink
broken implementation of hiding behind setting, merge #585 first
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsasha committed Dec 18, 2021
1 parent 642fe8a commit 8fb661f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
6 changes: 3 additions & 3 deletions irrd/updates/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ def __init__(self, rpsl_text_submitted: str, database_handler: DatabaseHandler,
return

source = self.rpsl_obj_new.source()
if not get_setting(f'sources.{source}.authoritative'):
logger.debug(f'{id(self)}: suspension is for non-authoritative source {source}, rejected')
self.error_messages.append(f'This instance is not authoritative for source {source}')
if not get_setting(f'sources.{source}.suspension_enabled'):
logger.debug(f'{id(self)}: source of suspension request is {source}, does not have suspension support enabled, request rejected')
self.error_messages.append(f'This instance is not authoritative for source {source} or suspension is not enabled')
self.status = UpdateRequestStatus.ERROR_NON_AUTHORITIVE
return

Expand Down
30 changes: 19 additions & 11 deletions irrd/updates/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,8 @@ class TestSuspensionRequest:
source: TEST
""").strip() + '\n'

def test_valid_suspension(self, prepare_mocks, monkeypatch):
def test_valid_suspension(self, prepare_mocks, monkeypatch, config_override):
config_override({'sources': {'TEST': {'suspension_enabled': True}}})
mock_dq, mock_dh = prepare_mocks
mock_auth_validator = Mock(spec=AuthValidator)
mock_suspend_for_mntner = Mock(suspend_for_mntner)
Expand Down Expand Up @@ -1227,7 +1228,8 @@ def test_valid_suspension(self, prepare_mocks, monkeypatch):
"INFO: Suspended route/192.0.2.0/24/TEST\n"
)

def test_valid_reactivation(self, prepare_mocks, monkeypatch):
def test_valid_reactivation(self, prepare_mocks, monkeypatch, config_override):
config_override({'sources': {'TEST': {'suspension_enabled': True}}})
mock_dq, mock_dh = prepare_mocks
mock_auth_validator = Mock(spec=AuthValidator)
mock_reactivate_for_mntner = Mock(reactivate_for_mntner)
Expand Down Expand Up @@ -1257,7 +1259,8 @@ def test_valid_reactivation(self, prepare_mocks, monkeypatch):
assert mock_reactivate_for_mntner.call_args[0][1].pk() == 'MNT-SUSPEND'
assert flatten_mock_calls(mock_auth_validator) == [['check_override', (), {}]]

def test_failed_reactivation(self, prepare_mocks, monkeypatch):
def test_failed_reactivation(self, prepare_mocks, monkeypatch, config_override):
config_override({'sources': {'TEST': {'suspension_enabled': True}}})
mock_dq, mock_dh = prepare_mocks
mock_auth_validator = Mock(spec=AuthValidator)
mock_reactivate_for_mntner = Mock(reactivate_for_mntner)
Expand All @@ -1274,12 +1277,12 @@ def test_failed_reactivation(self, prepare_mocks, monkeypatch):
assert not r.info_messages
assert 'failure' in r.submitter_report_human()

def test_not_authoritative(self, prepare_mocks, monkeypatch):
def test_not_authoritative(self, prepare_mocks, monkeypatch, config_override):
config_override({'sources': {'TEST': {'suspension_enabled': False}}})
mock_dq, mock_dh = prepare_mocks
mock_auth_validator = Mock(spec=AuthValidator)

request = self.default_request.replace('TEST', 'TEST-NOTAUTH')
(r, *_) = parse_change_requests(request, mock_dh, mock_auth_validator, None)
(r, *_) = parse_change_requests(self.default_request, mock_dh, mock_auth_validator, None)

assert r.request_type == SuspensionRequestType.SUSPEND
assert r.status == UpdateRequestStatus.ERROR_NON_AUTHORITIVE
Expand All @@ -1291,7 +1294,8 @@ def test_not_authoritative(self, prepare_mocks, monkeypatch):
with pytest.raises(ValueError):
r.save()

def test_unknown_suspension(self, prepare_mocks, monkeypatch):
def test_unknown_suspension(self, prepare_mocks, monkeypatch, config_override):
config_override({'sources': {'TEST': {'suspension_enabled': True}}})
mock_dq, mock_dh = prepare_mocks
mock_auth_validator = Mock(spec=AuthValidator)

Expand All @@ -1305,7 +1309,8 @@ def test_unknown_suspension(self, prepare_mocks, monkeypatch):
]
assert not r.is_valid()

def test_invalid_rpsl_object(self, prepare_mocks, monkeypatch):
def test_invalid_rpsl_object(self, prepare_mocks, monkeypatch, config_override):
config_override({'sources': {'TEST': {'suspension_enabled': True}}})
mock_dq, mock_dh = prepare_mocks
mock_auth_validator = Mock(spec=AuthValidator)

Expand All @@ -1318,7 +1323,8 @@ def test_invalid_rpsl_object(self, prepare_mocks, monkeypatch):
]
assert not r.is_valid()

def test_invalid_rpsl_object_class(self, prepare_mocks, monkeypatch):
def test_invalid_rpsl_object_class(self, prepare_mocks, monkeypatch, config_override):
config_override({'sources': {'TEST': {'suspension_enabled': True}}})
mock_dq, mock_dh = prepare_mocks
mock_auth_validator = Mock(spec=AuthValidator)

Expand All @@ -1331,7 +1337,8 @@ def test_invalid_rpsl_object_class(self, prepare_mocks, monkeypatch):
]
assert not r.is_valid()

def test_incorrect_object_class(self, prepare_mocks, monkeypatch):
def test_incorrect_object_class(self, prepare_mocks, monkeypatch, config_override):
config_override({'sources': {'TEST': {'suspension_enabled': True}}})
mock_dq, mock_dh = prepare_mocks
mock_auth_validator = Mock(spec=AuthValidator)

Expand All @@ -1344,7 +1351,8 @@ def test_incorrect_object_class(self, prepare_mocks, monkeypatch):
]
assert not r.is_valid()

def test_invalid_override_password(self, prepare_mocks, monkeypatch):
def test_invalid_override_password(self, prepare_mocks, monkeypatch, config_override):
config_override({'sources': {'TEST': {'suspension_enabled': True}}})
mock_dq, mock_dh = prepare_mocks
mock_auth_validator = Mock(spec=AuthValidator)
mock_auth_validator.check_override.return_value = False
Expand Down

0 comments on commit 8fb661f

Please sign in to comment.