Exemple #1
0
def test_handle_annotation_event_none_for_sender_socket():
    """Should return None if the socket's client_id matches the message's."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('pigeon')

    assert nsq.handle_annotation_event(message, socket) is None
Exemple #2
0
def test_handle_annotation_event_none_if_action_is_read():
    """Should return None if the message action is 'read'."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'read',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert nsq.handle_annotation_event(message, socket) is None
Exemple #3
0
def test_handle_annotation_event_none_if_filter_does_not_match():
    """Should return None if the socket filter doesn't match the message."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.filter.match.return_value = False

    assert nsq.handle_annotation_event(message, socket) is None
Exemple #4
0
def test_handle_annotation_event_none_if_no_socket_filter():
    """Should return None if the socket has no filter."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.filter = None

    assert nsq.handle_annotation_event(message, socket) is None
Exemple #5
0
def test_handle_annotation_event_none_if_action_is_read():
    """Should return None if the message action is 'read'."""
    message = {
        'annotation': {
            'permissions': {
                'read': ['group:__world__']
            }
        },
        'action': 'read',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert nsq.handle_annotation_event(message, socket) is None
Exemple #6
0
def test_handle_annotation_event_none_if_annotation_nipsad():
    """Should return None if the annotation is from a NIPSA'd user."""
    message = {
        'annotation': {
            'user': '******',
            'nipsa': True,
            'permissions': {'read': ['group:__world__']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert nsq.handle_annotation_event(message, socket) is None
Exemple #7
0
def test_handle_annotation_event_annotation_notification_format():
    """Check the format of the returned notification in the happy case."""
    message = {
        'annotation': {'permissions': {'read': ['group:__world__']}},
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert nsq.handle_annotation_event(message, socket) == {
        'payload': [message['annotation']],
        'type': 'annotation-notification',
        'options': {'action': 'update'},
    }
Exemple #8
0
def test_handle_annotation_event_sends_if_in_group():
    """Users should see annotations in groups they are members of."""
    message = {
        'annotation': {
            'user': '******',
            'permissions': {'read': ['group:private-group']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.effective_principals = ['fred', 'group:private-group']

    assert nsq.handle_annotation_event(message, socket) is not None
Exemple #9
0
def test_handle_annotation_event_none_for_sender_socket():
    """Should return None if the socket's client_id matches the message's."""
    message = {
        'annotation': {
            'permissions': {
                'read': ['group:__world__']
            }
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('pigeon')

    assert nsq.handle_annotation_event(message, socket) is None
Exemple #10
0
def test_handle_annotation_event_none_if_filter_does_not_match():
    """Should return None if the socket filter doesn't match the message."""
    message = {
        'annotation': {
            'permissions': {
                'read': ['group:__world__']
            }
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.filter.match.return_value = False

    assert nsq.handle_annotation_event(message, socket) is None
Exemple #11
0
def test_handle_annotation_event_sends_nipsad_annotations_to_owners():
    """NIPSA'd users should see their own annotations."""
    message = {
        'annotation': {
            'user': '******',
            'nipsa': True,
            'permissions': {'read': ['group:__world__']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.authenticated_userid = 'fred'

    assert nsq.handle_annotation_event(message, socket) is not None
Exemple #12
0
def test_handle_annotation_event_none_if_no_socket_filter():
    """Should return None if the socket has no filter."""
    message = {
        'annotation': {
            'permissions': {
                'read': ['group:__world__']
            }
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.filter = None

    assert nsq.handle_annotation_event(message, socket) is None
Exemple #13
0
def test_handle_annotation_event_none_if_annotation_nipsad():
    """Should return None if the annotation is from a NIPSA'd user."""
    message = {
        'annotation': {
            'user': '******',
            'nipsa': True,
            'permissions': {
                'read': ['group:__world__']
            }
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert nsq.handle_annotation_event(message, socket) is None
Exemple #14
0
def test_handle_annotation_event_sends_if_in_group():
    """Users should see annotations in groups they are members of."""
    message = {
        'annotation': {
            'user': '******',
            'permissions': {
                'read': ['group:private-group']
            }
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.effective_principals = ['fred', 'group:private-group']

    assert nsq.handle_annotation_event(message, socket) is not None
Exemple #15
0
def test_handle_annotation_event_sends_nipsad_annotations_to_owners():
    """NIPSA'd users should see their own annotations."""
    message = {
        'annotation': {
            'user': '******',
            'nipsa': True,
            'permissions': {
                'read': ['group:__world__']
            }
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.authenticated_userid = 'fred'

    assert nsq.handle_annotation_event(message, socket) is not None
Exemple #16
0
def test_handle_annotation_event_annotation_notification_format():
    """Check the format of the returned notification in the happy case."""
    message = {
        'annotation': {
            'permissions': {
                'read': ['group:__world__']
            }
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')

    assert nsq.handle_annotation_event(message, socket) == {
        'payload': [message['annotation']],
        'type': 'annotation-notification',
        'options': {
            'action': 'update'
        },
    }
Exemple #17
0
def test_handle_annotation_event_sends_if_annotation_public():
    """
    Everyone should see annotations which are public.

    When logged-out, effective principals contains only
    `pyramid.security.Everyone`. This test ensures that the system
    principal is correctly equated with the annotation principal
    'group:__world__', ensuring that everyone (including logged-out users)
    receives all public annotations.
    """
    message = {
        'annotation': {
            'user': '******',
            'permissions': {'read': ['group:__world__']}
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.effective_principals = [security.Everyone]

    assert nsq.handle_annotation_event(message, socket) is not None
Exemple #18
0
def test_handle_annotation_event_sends_if_annotation_public():
    """
    Everyone should see annotations which are public.

    When logged-out, effective principals contains only
    `pyramid.security.Everyone`. This test ensures that the system
    principal is correctly equated with the annotation principal
    'group:__world__', ensuring that everyone (including logged-out users)
    receives all public annotations.
    """
    message = {
        'annotation': {
            'user': '******',
            'permissions': {
                'read': ['group:__world__']
            }
        },
        'action': 'update',
        'src_client_id': 'pigeon'
    }
    socket = FakeSocket('giraffe')
    socket.request.effective_principals = [security.Everyone]

    assert nsq.handle_annotation_event(message, socket) is not None