Beispiel #1
0
    def test_check_auth_invalid_update_with_incorrect_password_referenced_mntner(
            self, prepare_mocks):
        mock_dq, mock_dh = prepare_mocks

        query_results = iter([[{
            'object_text':
            SAMPLE_INETNUM.replace('test-MNT', 'FAIL-MNT')
        }], [{
            'object_text': SAMPLE_MNTNER
        }], []])
        mock_dh.execute_query = lambda query: next(query_results)

        reference_validator = ReferenceValidator(mock_dh)
        auth_validator = AuthValidator(mock_dh)

        result_inetnum = parse_update_requests(
            SAMPLE_INETNUM + 'password: md5-password', mock_dh, auth_validator,
            reference_validator)[0]
        assert not result_inetnum._check_auth(), result_inetnum
        assert 'Authorisation for inetnum 192.0.2.0 - 192.0.2.255 failed' in result_inetnum.error_messages[
            0]
        assert 'one of: FAIL-MNT' in result_inetnum.error_messages[0]
        assert flatten_mock_calls(mock_dq) == [
            ['sources', (['TEST'], ), {}],
            ['object_classes', (['inetnum'], ), {}],
            ['rpsl_pk', ('192.0.2.0 - 192.0.2.255', ), {}],
            ['sources', (['TEST'], ), {}],
            ['object_classes', (['mntner'], ), {}],
            ['rpsl_pks', (['TEST-MNT'], ), {}],
            ['sources', (['TEST'], ), {}],
            ['object_classes', (['mntner'], ), {}],
            ['rpsl_pks', (['FAIL-MNT'], ), {}],
        ]
Beispiel #2
0
    def test_check_auth_invalid_update_with_nonexistent_referenced_mntner(
            self, prepare_mocks):
        # This is a case that shouldn't happen, but in legacy databases it might.
        mock_dq, mock_dh = prepare_mocks

        query_results = iter([[{
            'object_text':
            SAMPLE_INETNUM.replace('test-MNT', 'FAIL-MNT')
        }], [{
            'object_text': SAMPLE_MNTNER
        }], []])
        mock_dh.execute_query = lambda query: next(query_results)

        reference_validator = ReferenceValidator(mock_dh)
        auth_validator = AuthValidator(mock_dh)

        result_inetnum = parse_change_requests(
            SAMPLE_INETNUM + 'password: md5-password', mock_dh, auth_validator,
            reference_validator)[0]
        assert not result_inetnum._check_auth(), result_inetnum
        assert 'Authorisation for inetnum 192.0.2.0 - 192.0.2.255 failed' in result_inetnum.error_messages[
            0]
        assert 'one of: FAIL-MNT' in result_inetnum.error_messages[0]
        assert result_inetnum.notification_targets() == {'*****@*****.**'}

        assert flatten_mock_calls(mock_dq) == [
            ['sources', (['TEST'], ), {}],
            ['object_classes', (['inetnum'], ), {}],
            ['rpsl_pk', ('192.0.2.0 - 192.0.2.255', ), {}],
            ['sources', (['TEST'], ), {}],
            ['object_classes', (['mntner'], ), {}],
            ['rpsl_pks', ({'TEST-MNT'}, ), {}],
            ['sources', (['TEST'], ), {}],
            ['object_classes', (['mntner'], ), {}],
            ['rpsl_pks', ({'FAIL-MNT'}, ), {}],
        ]
Beispiel #3
0
    def test_user_report(self, prepare_mocks):
        mock_dq, mock_dh = prepare_mocks

        query_results = iter([
            [{
                'object_text': SAMPLE_INETNUM
            }],
            [],
        ])
        mock_dh.execute_query = lambda query: next(query_results)

        result_inetnum, result_as_set, result_unknown, result_invalid = parse_change_requests(
            self._request_text(), mock_dh, AuthValidator(mock_dh), None)
        report_inetnum = result_inetnum.submitter_report()
        report_as_set = result_as_set.submitter_report()
        report_unknown = result_unknown.submitter_report()
        report_invalid = result_invalid.submitter_report()

        assert 'Delete succeeded' in report_inetnum
        assert 'remarks: ' in report_inetnum  # full RPSL object should be included
        assert 'INFO: Address range 192' in report_inetnum

        assert report_as_set == 'Create succeeded: [as-set] AS-SETTEST\n'

        assert 'FAILED' in report_unknown
        assert 'ERROR: unknown object class' in report_unknown

        assert 'FAILED' in report_invalid
        assert 'aut-num: pw1'  # full RPSL object should be included
        assert 'ERROR: Mandatory attribute' in report_invalid
        assert 'ERROR: Invalid AS number PW1' in report_invalid

        query_results = iter([
            [{
                'object_text': SAMPLE_INETNUM
            }],
            [],
        ])
        mock_dh.execute_query = lambda query: next(query_results)

        assert result_inetnum.notification_target_report(
        ) == textwrap.dedent("""
            Delete succeeded for object below: [inetnum] 192.0.2.0 - 192.0.2.255:
            
            inetnum:        192.0.2.0 - 192.0.2.255
            netname:        NET-TEST-V4
            descr:          description
            country:        IT
            notify:         [email protected]
            admin-c:        PERSON-TEST
            tech-c:         PERSON-TEST
            status:         ASSIGNED PA
            mnt-by:         test-MNT
            changed:        [email protected] 20190701 # comment
            source:         TEST
            remarks:        remark
        """).strip() + '\n'

        assert result_as_set.notification_target_report(
        ) == textwrap.dedent("""
            Create succeeded for object below: [as-set] AS-SETTEST:
            
            as-set:         AS-SETTEST
            descr:          description
            members:        AS65538,AS65539
            members:        AS65537
            tech-c:         PERSON-TEST
            admin-c:        PERSON-TEST
            notify:         [email protected]
            mnt-by:         TEST-MNT
            changed:        [email protected] 20190701 # comment
            source:         TEST
            remarks:        remark
        """).strip() + '\n'

        inetnum_modify = SAMPLE_INETNUM.replace('PERSON-TEST', 'NEW-TEST')
        result_inetnum_modify = parse_change_requests(inetnum_modify, mock_dh,
                                                      AuthValidator(mock_dh),
                                                      None)[0]
        assert result_inetnum_modify.notification_target_report(
        ) == textwrap.dedent("""
            Modify succeeded for object below: [inetnum] 192.0.2.0 - 192.0.2.255:
            
            @@ -3,8 +3,8 @@
             descr:          description
             country:        IT
             notify:         [email protected]
            -admin-c:        PERSON-TEST
            -tech-c:         PERSON-TEST
            +admin-c:        NEW-TEST
            +tech-c:         NEW-TEST
             status:         ASSIGNED PA
             mnt-by:         test-MNT
             changed:        [email protected] 20190701 # comment
            
            New version of this object:
            
            inetnum:        192.0.2.0 - 192.0.2.255
            netname:        NET-TEST-V4
            descr:          description
            country:        IT
            notify:         [email protected]
            admin-c:        NEW-TEST
            tech-c:         NEW-TEST
            status:         ASSIGNED PA
            mnt-by:         test-MNT
            changed:        [email protected] 20190701 # comment
            source:         TEST
            remarks:        remark
        """).strip() + '\n'

        # Fake the result to look like an authentication failure
        result_inetnum_modify.status = UpdateRequestStatus.ERROR_AUTH
        assert result_inetnum_modify.notification_target_report(
        ) == textwrap.dedent("""
            Modify FAILED AUTHORISATION for object below: [inetnum] 192.0.2.0 - 192.0.2.255:
            
            @@ -3,8 +3,8 @@
             descr:          description
             country:        IT
             notify:         [email protected]
            -admin-c:        PERSON-TEST
            -tech-c:         PERSON-TEST
            +admin-c:        NEW-TEST
            +tech-c:         NEW-TEST
             status:         ASSIGNED PA
             mnt-by:         test-MNT
             changed:        [email protected] 20190701 # comment
            
            *Rejected* new version of this object:
            
            inetnum:        192.0.2.0 - 192.0.2.255
            netname:        NET-TEST-V4
            descr:          description
            country:        IT
            notify:         [email protected]
            admin-c:        NEW-TEST
            tech-c:         NEW-TEST
            status:         ASSIGNED PA
            mnt-by:         test-MNT
            changed:        [email protected] 20190701 # comment
            source:         TEST
            remarks:        remark
        """).strip() + '\n'

        with pytest.raises(ValueError) as ve:
            result_unknown.notification_target_report()
        assert 'changes that are valid or have failed authorisation' in str(
            ve.value)