Exemplo n.º 1
0
def test_valid_user(app):
    # Login with a valid user.
    someuser = model.user.get_user("devtable")
    login_user(LoginWrappedDBUser(someuser.uuid, someuser))

    result = validate_session_cookie()
    assert result.authed_user == someuser
    assert result.context.identity is not None
    assert result.has_nonrobot_user
    assert result.error_message is None
Exemplo n.º 2
0
    def wrapper(*args, **kwargs):
        result = validate_session_cookie()
        if result.has_nonrobot_user:
            result.apply_to_context()
            authentication_count.labels(result.kind, True).inc()
            return func(*args, **kwargs)
        elif not result.missing:
            authentication_count.labels(result.kind, False).inc()

        abort(401, message="Method requires login and no valid login could be loaded.")
Exemplo n.º 3
0
def test_disabled_user(app):
    # "Login" with a disabled user.
    someuser = model.user.get_user("disabled")
    login_user(LoginWrappedDBUser(someuser.uuid, someuser))

    # Ensure we get an invalid session cookie format error.
    result = validate_session_cookie()
    assert result.authed_user is None
    assert result.context.identity is None
    assert not result.has_nonrobot_user
    assert result.error_message == "User account is disabled"
Exemplo n.º 4
0
def test_invalidformatted_cookie(app):
    # "Login" with a non-UUID reference.
    someuser = model.user.get_user("devtable")
    login_user(LoginWrappedDBUser("somenonuuid", someuser))

    # Ensure we get an invalid session cookie format error.
    result = validate_session_cookie()
    assert result.authed_user is None
    assert result.context.identity is None
    assert not result.has_nonrobot_user
    assert result.error_message == "Invalid session cookie format"
Exemplo n.º 5
0
def test_valid_organization(app):
    # "Login" with a valid organization.
    someorg = model.user.get_namespace_user("buynlarge")
    someorg.uuid = str(uuid.uuid4())
    someorg.verified = True
    someorg.save()

    login_user(LoginWrappedDBUser(someorg.uuid, someorg))

    result = validate_session_cookie()
    assert result.authed_user is None
    assert result.context.identity is None
    assert not result.has_nonrobot_user
    assert result.error_message == "Cannot login to organization"
Exemplo n.º 6
0
    def wrapper(*args, **kwargs):
        result = validate_session_cookie()
        if result.has_nonrobot_user:
            result.apply_to_context()
            metric_queue.authentication_count.Inc(
                labelvalues=[result.kind, True])
            return func(*args, **kwargs)
        elif not result.missing:
            metric_queue.authentication_count.Inc(
                labelvalues=[result.kind, False])

        abort(
            401,
            message='Method requires login and no valid login could be loaded.'
        )
Exemplo n.º 7
0
def test_anonymous_cookie(app):
    assert validate_session_cookie().missing