Ejemplo n.º 1
0
def test_connection_is_ticket_challenged(router):
    os.environ['WAMPYSECRET'] = "wEx9TPFtHdRr2Zg7rtRE"
    roles = {
        'roles': {
            'subscriber': {},
            'publisher': {},
            'callee': {},
            'caller': {},
        },
        'authmethods': ['ticket'],
        'authid': 'martin',
    }

    client = Client(
        url=router.url,
        roles=roles,
        message_handler_cls=CollectingMessageHandler,
        name="unauthenticated-client"
    )

    client.start()
    messages = wait_for_messages(client, 2)

    # expect a Challenge and Welcome message
    assert messages[0][0] == Challenge.WAMP_CODE
    assert messages[1][0] == Welcome.WAMP_CODE

    client.stop()

    # now also expect a Goodbye message
    assert len(messages) == 3
    assert messages[0][0] == Challenge.WAMP_CODE
    assert messages[1][0] == Welcome.WAMP_CODE
    assert messages[2][0] == Goodbye.WAMP_CODE
Ejemplo n.º 2
0
def test_connection_is_challenged(router):
    os.environ['WAMPYSECRET'] = "prq7+YkJ1/KlW1X0YczMHw=="
    roles = {
        'roles': {
            'subscriber': {},
            'publisher': {},
            'callee': {},
            'caller': {},
        },
        'authmethods': ['wampcra'],
        'authid': 'peter',
    }

    message_handler = CollectingMessageHandler()
    client = Client(router=router,
                    roles=roles,
                    message_handler=message_handler,
                    name="unauthenticated-client")

    client.start()
    messages = wait_for_messages(client, 2)

    # expect a Challenge and Welcome message
    assert messages[0][0] == Challenge.WAMP_CODE
    assert messages[1][0] == Welcome.WAMP_CODE

    client.stop()

    # now also expect a Goodbye message
    assert len(messages) == 3
    assert messages[0][0] == Challenge.WAMP_CODE
    assert messages[1][0] == Welcome.WAMP_CODE
    assert messages[2][0] == Goodbye.WAMP_CODE
Ejemplo n.º 3
0
def test_connection_is_ticket_challenged(router):
    os.environ['WAMPYSECRET'] = "wEx9TPFtHdRr2Zg7rtRE"
    roles = {
        'roles': {
            'subscriber': {},
            'publisher': {},
            'callee': {},
            'caller': {},
        },
        'authmethods': ['ticket'],
        'authid': 'martin',
    }

    client = Client(url=router.url,
                    roles=roles,
                    message_handler_cls=CollectingMessageHandler,
                    name="unauthenticated-client")

    client.start()
    messages = wait_for_messages(client, 2)

    # expect a Challenge and Welcome message
    assert messages[0][0] == Challenge.WAMP_CODE
    assert messages[1][0] == Welcome.WAMP_CODE

    client.stop()

    # now also expect a Goodbye message
    assert len(messages) == 3
    assert messages[0][0] == Challenge.WAMP_CODE
    assert messages[1][0] == Welcome.WAMP_CODE
    assert messages[2][0] == Goodbye.WAMP_CODE
Ejemplo n.º 4
0
def test_peter_cannot_call_get_foo(router, foo_service):
    # `get_foo` can be registered but not called over the wampy role
    os.environ['WAMPYSECRET'] = "prq7+YkJ1/KlW1X0YczMHw=="
    roles = {
        'roles': {
            'subscriber': {},
            'publisher': {},
            'callee': {},
            'caller': {},
        },
        'authmethods': ['wampcra'],
        'authid': 'peter',
    }

    message_handler = CollectingMessageHandler()
    client = Client(
        router=router,
        roles=roles,
        message_handler=message_handler,
        name="unauthenticated-client-three",
    )

    client.start()

    with pytest.raises(NotAuthorisedError):
        client.rpc.get_foo()

    client.stop()

    messages = wait_for_messages(client, 4)

    # now also expect a Goodbye message
    assert len(messages) == 4
    assert messages[0][0] == Challenge.WAMP_CODE
    assert messages[1][0] == Welcome.WAMP_CODE
    assert messages[2][0] == Error.WAMP_CODE
    assert messages[3][0] == Goodbye.WAMP_CODE
Ejemplo n.º 5
0
def test_peter_cannot_call_get_foo(router, foo_service):
    # `get_foo` can be registered but not called over the wampy role
    os.environ['WAMPYSECRET'] = "prq7+YkJ1/KlW1X0YczMHw=="
    roles = {
        'roles': {
            'subscriber': {},
            'publisher': {},
            'callee': {},
            'caller': {},
        },
        'authmethods': ['wampcra'],
        'authid': 'peter',
    }

    client = Client(
        url=router.url,
        roles=roles,
        message_handler_cls=CollectingMessageHandler,
        name="unauthenticated-client-three",
    )

    client.start()

    with pytest.raises(WampyError):
        client.rpc.get_foo()

    client.stop()

    messages = wait_for_messages(client, 4)

    # now also expect a Goodbye message
    assert len(messages) == 4
    assert messages[0][0] == Challenge.WAMP_CODE
    assert messages[1][0] == Welcome.WAMP_CODE
    assert messages[2][0] == Error.WAMP_CODE
    assert messages[3][0] == Goodbye.WAMP_CODE