Пример #1
0
def test_permission_disable_inactive_grants(setup):
    # type: (SetupTest) -> None
    """Test that permission grants to disabled objects are automatically deleted."""
    with setup.transaction():
        setup.grant_permission_to_group(PERMISSION_ADMIN, "", "admins")
        setup.add_user_to_group("*****@*****.**", "admins")
        setup.grant_permission_to_group("some-permission", "argument", "some-group")
        setup.disable_group("some-group")

    mock_ui = MagicMock()
    usecase = setup.usecase_factory.create_disable_permission_usecase("*****@*****.**", mock_ui)
    usecase.disable_permission("some-permission")
    assert mock_ui.mock_calls == [call.disabled_permission("some-permission")]
    permission_grant_repository = setup.repository_factory.create_permission_grant_repository()
    grants = permission_grant_repository.group_grants_for_permission(
        "some-permission", include_disabled_groups=True
    )
    assert grants == []
Пример #2
0
def test_permission_disable(setup):
    # type: (SetupTest) -> None
    with setup.transaction():
        setup.grant_permission_to_group(PERMISSION_ADMIN, "", "admins")
        setup.add_user_to_group("*****@*****.**", "admins")
        setup.create_permission("some-permission")
    mock_ui = MagicMock()
    usecase = setup.usecase_factory.create_disable_permission_usecase("*****@*****.**", mock_ui)

    usecase.disable_permission("some-permission")
    assert mock_ui.mock_calls == [call.disabled_permission("some-permission")]
    assert not Permission.get(setup.session, name="some-permission").enabled

    audit_log_service = setup.service_factory.create_audit_log_service()
    audit_log_entries = audit_log_service.entries_affecting_permission("some-permission", 20)
    assert len(audit_log_entries) == 1
    assert audit_log_entries[0].actor == "*****@*****.**"
    assert audit_log_entries[0].action == "disable_permission"
    assert audit_log_entries[0].on_permission == "some-permission"
Пример #3
0
def test_permission_disable_inactive_grants(setup):
    # type: (SetupTest) -> None
    """Test that permission grants to disabled objects are automatically deleted."""
    with setup.transaction():
        setup.grant_permission_to_group(PERMISSION_ADMIN, "", "admins")
        setup.add_user_to_group("*****@*****.**", "admins")
        setup.grant_permission_to_group("some-permission", "argument",
                                        "some-group")
        setup.disable_group("some-group")

    mock_ui = MagicMock()
    usecase = setup.usecase_factory.create_disable_permission_usecase(
        "*****@*****.**", mock_ui)
    usecase.disable_permission("some-permission")
    assert mock_ui.mock_calls == [call.disabled_permission("some-permission")]
    permission_grant_repository = setup.repository_factory.create_permission_grant_repository(
    )
    grants = permission_grant_repository.group_grants_for_permission(
        "some-permission", include_disabled_groups=True)
    assert grants == []
Пример #4
0
def test_permission_disable(setup):
    # type: (SetupTest) -> None
    with setup.transaction():
        setup.grant_permission_to_group(PERMISSION_ADMIN, "", "admins")
        setup.add_user_to_group("*****@*****.**", "admins")
        setup.create_permission("some-permission")
    mock_ui = MagicMock()
    usecase = setup.usecase_factory.create_disable_permission_usecase(
        "*****@*****.**", mock_ui)

    usecase.disable_permission("some-permission")
    assert mock_ui.mock_calls == [call.disabled_permission("some-permission")]
    assert not Permission.get(setup.session, name="some-permission").enabled

    audit_log_service = setup.service_factory.create_audit_log_service()
    audit_log_entries = audit_log_service.entries_affecting_permission(
        "some-permission", 20)
    assert len(audit_log_entries) == 1
    assert audit_log_entries[0].actor == "*****@*****.**"
    assert audit_log_entries[0].action == "disable_permission"
    assert audit_log_entries[0].on_permission == "some-permission"