Ejemplo n.º 1
0
def test_reregister(client, user_info, user2_info, test_config):
    "A user account which is unconfirmed after two days can be re-registered."
    rv = client.get(url_for("auth.register"))
    data = dict(
        csrf_token=csrf_token(rv.data),
        username=user_info["username"],
        password=user_info["password"],
        confirm=user_info["password"],
        invitecode="",
        accept_tos=True,
        email_required=user_info["email"],
        captcha="xyzzy",
    )
    client.post(url_for("auth.register"), data=data, follow_redirects=True)

    new_user = User.get(User.name == user_info["username"])
    assert new_user.status == UserStatus.PROBATION
    new_user.joindate -= timedelta(days=3)
    new_user.save()

    rv = client.get(url_for("auth.register"))
    with mail.record_messages() as outbox:
        data = dict(
            csrf_token=csrf_token(rv.data),
            username=user_info["username"],
            password=user_info["password"],
            confirm=user_info["password"],
            invitecode="",
            email_required=user2_info["email"],
            accept_tos=True,
        )
        rv = client.post(url_for("auth.register"), data=data, follow_redirects=True)

        assert b"spam" in rv.data  # Telling user to go check it.
        message = outbox[-1]
        assert message.send_to == {user2_info["email"]}
        soup = BeautifulSoup(message.html, "html.parser")
        token = soup.a["href"].split("/")[-1]
        rv = client.get(
            url_for("auth.login_with_token", token=token), follow_redirects=True
        )
        assert b"Log out" in rv.data

    assert auth_provider.get_user_by_email(user_info["email"]) is None
    assert (
        auth_provider.get_user_by_email(user2_info["email"]).name
        == user_info["username"]
    )
Ejemplo n.º 2
0
def test_registration_login(client, test_config):
    """The registration page logs a user in if they register correctly."""
    rv = client.get(url_for("auth.register"))
    with mail.record_messages() as outbox:
        data = dict(
            csrf_token=csrf_token(rv.data),
            username="******",
            password="******",
            confirm="Safe123#$@lolnot",
            invitecode="",
            accept_tos=True,
            captcha="xyzzy",
        )
        if email_validation_is_required():
            data["email_required"] = "*****@*****.**"
        else:
            data["email_optional"] = "*****@*****.**"
        rv = client.post(url_for("auth.register"),
                         data=data,
                         follow_redirects=True)

        if email_validation_is_required():
            assert b"spam" in rv.data  # Telling user to go check it.
            message = outbox[-1]
            soup = BeautifulSoup(message.html, "html.parser")
            token = soup.a["href"].split("/")[-1]
            rv = client.get(url_for("auth.login_with_token", token=token),
                            follow_redirects=True)

        assert auth_provider.get_user_by_email(
            "*****@*****.**").name == "supertester"
        assert b"Log out" in rv.data
Ejemplo n.º 3
0
def test_registration_login(client):
    """The registration page logs a user in if they register correctly."""
    rv = client.get(url_for('auth.register'))
    with mail.record_messages() as outbox:
        data = dict(csrf_token=csrf_token(rv.data),
                    username='******',
                    password='******',
                    confirm='Safe123#$@lolnot',
                    invitecode='',
                    accept_tos=True,
                    captcha='xyzzy')
        if email_validation_is_required():
            data['email_required'] = '*****@*****.**'
        else:
            data['email_optional'] = '*****@*****.**'
        rv = client.post(url_for('auth.register'),
                         data=data,
                         follow_redirects=True)

        if email_validation_is_required():
            assert b'spam' in rv.data  # Telling user to go check it.
            message = outbox[-1]
            soup = BeautifulSoup(message.html, 'html.parser')
            token = soup.a['href'].split('/')[-1]
            rv = client.get(url_for('auth.login_with_token', token=token),
                            follow_redirects=True)

        assert auth_provider.get_user_by_email(
            '*****@*****.**').name == 'supertester'
        assert b'Log out' in rv.data
Ejemplo n.º 4
0
def test_reregister(client, user_info, user2_info):
    "A user account which is unconfirmed after two days can be re-registered."
    rv = client.get(url_for('auth.register'))
    data = dict(csrf_token=csrf_token(rv.data),
                username=user_info['username'],
                password=user_info['password'],
                confirm=user_info['password'],
                invitecode='',
                accept_tos=True,
                email_required=user_info['email'],
                captcha='xyzzy')
    rv = client.post(url_for('auth.register'),
                     data=data,
                     follow_redirects=True)

    new_user = User.get(User.name == user_info['username'])
    assert new_user.status == UserStatus.PROBATION
    new_user.joindate -= timedelta(days=3)
    new_user.save()

    rv = client.get(url_for('auth.register'))
    with mail.record_messages() as outbox:
        data = dict(
            csrf_token=csrf_token(rv.data),
            username=user_info['username'],
            password=user_info['password'],
            confirm=user_info['password'],
            invitecode='',
            email_required=user2_info['email'],
            accept_tos=True,
        )
        rv = client.post(url_for('auth.register'),
                         data=data,
                         follow_redirects=True)

        assert b'spam' in rv.data  # Telling user to go check it.
        message = outbox[-1]
        assert message.send_to == {user2_info['email']}
        soup = BeautifulSoup(message.html, 'html.parser')
        token = soup.a['href'].split('/')[-1]
        rv = client.get(url_for('auth.login_with_token', token=token),
                        follow_redirects=True)
        assert b'Log out' in rv.data

    assert auth_provider.get_user_by_email(user_info['email']) == None
    assert (auth_provider.get_user_by_email(
        user2_info['email']).name == user_info['username'])