Beispiel #1
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
Beispiel #2
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
Beispiel #3
0
def register_user(client, user_info):
    """Register a user with the client and leave them logged in."""
    rv = client.get(url_for("home.index"))
    client.post(
        url_for("do.logout"),
        data=dict(csrf_token=csrf_token(rv.data)),
        follow_redirects=True,
    )
    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="",
            accept_tos=True,
            captcha="xyzzy",
        )
        if email_validation_is_required():
            data["email_required"] = user_info["email"]
        else:
            data["email_optional"] = user_info["email"]

        client.post(url_for("auth.register"), data=data, follow_redirects=True)

        if email_validation_is_required():
            message = outbox[-1]
            soup = BeautifulSoup(message.html, "html.parser")
            token = soup.a["href"].split("/")[-1]
            client.get(url_for("auth.login_with_token", token=token),
                       follow_redirects=True)
Beispiel #4
0
def register_user(client, user_info):
    """Register a user with the client and leave them logged in."""
    rv = client.get(url_for('home.index'))
    client.post(url_for('do.logout'),
                data=dict(csrf_token=csrf_token(rv.data)),
                follow_redirects=True)
    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='',
                    accept_tos=True,
                    captcha='xyzzy')
        if email_validation_is_required():
            data['email_required'] = user_info['email']
        else:
            data['email_optional'] = user_info['email']

        client.post(url_for('auth.register'), data=data, follow_redirects=True)

        if email_validation_is_required():
            message = outbox[-1]
            soup = BeautifulSoup(message.html, 'html.parser')
            token = soup.a['href'].split('/')[-1]
            client.get(url_for('auth.login_with_token', token=token),
                       follow_redirects=True)
Beispiel #5
0
def test_change_password_recovery_email(client, user_info, test_config):
    """The user can change their password recovery email."""
    register_user(client, user_info)
    new_email = "*****@*****.**"
    assert new_email != user_info["email"]

    rv = client.get(url_for("user.edit_account"))
    data = dict(
        csrf_token=csrf_token(rv.data),
        oldpassword=user_info["password"],
        password="",
        confirm="",
    )
    if email_validation_is_required():
        data["email_required"] = new_email
    else:
        data["email_optional"] = new_email

    with mail.record_messages() as outbox:
        rv = client.post(url_for("do.edit_account"),
                         data=data,
                         follow_redirects=True)
        log_out_current_user(client)

        if email_validation_is_required():
            message = outbox.pop()

            # Make sure that password recovery emails go to the former address
            # if the new one has not yet been confirmed.
            rv = client.get(url_for("user.password_recovery"))
            rv = client.post(
                url_for("user.password_recovery"),
                data=dict(csrf_token=csrf_token(rv.data),
                          email=new_email,
                          captcha="xyzzy"),
            )
            assert len(outbox) == 0

            rv = client.get(url_for("user.password_recovery"))
            rv = client.post(
                url_for("user.password_recovery"),
                data=dict(
                    csrf_token=csrf_token(rv.data),
                    email=user_info["email"],
                    captcha="xyzzy",
                ),
            )
            assert outbox.pop().send_to == {user_info["email"]}

            # Now click the confirm link.
            assert message.send_to == {new_email}
            soup = BeautifulSoup(message.html, "html.parser")
            token = soup.a["href"].split("/")[-1]
            rv = client.get(url_for("user.confirm_email_change", token=token),
                            follow_redirects=True)
        else:
            assert len(outbox) == 0

    # Verify password recovery email goes to the right place.
    with mail.record_messages() as outbox:
        rv = client.get(url_for("user.password_recovery"))
        rv = client.post(
            url_for("user.password_recovery"),
            data=dict(
                csrf_token=csrf_token(rv.data),
                email=user_info["email"],
                captcha="xyzzy",
            ),
        )
        assert len(outbox) == 0
        rv = client.get(url_for("user.password_recovery"))
        rv = client.post(
            url_for("user.password_recovery"),
            data=dict(csrf_token=csrf_token(rv.data),
                      email=new_email,
                      captcha="xyzzy"),
        )
        assert outbox.pop().send_to == {new_email}
Beispiel #6
0
def test_change_password_recovery_email(client, user_info):
    """The user can change their password recovery email."""
    register_user(client, user_info)
    new_email = '*****@*****.**'
    assert new_email != user_info['email']

    rv = client.get(url_for('user.edit_account'))
    data = dict(csrf_token=csrf_token(rv.data),
                oldpassword=user_info['password'],
                password='',
                confirm='')
    if email_validation_is_required():
        data['email_required'] = new_email
    else:
        data['email_optional'] = new_email

    with mail.record_messages() as outbox:
        rv = client.post(url_for('do.edit_account'),
                         data=data,
                         follow_redirects=True)
        log_out_current_user(client)

        if email_validation_is_required():
            message = outbox.pop()

            # Make sure that password recovery emails go to the former address
            # if the new one has not yet been confirmed.
            rv = client.get(url_for('user.password_recovery'))
            rv = client.post(url_for('user.password_recovery'),
                             data=dict(csrf_token=csrf_token(rv.data),
                                       email=new_email,
                                       captcha='xyzzy'))
            assert len(outbox) == 0

            rv = client.get(url_for('user.password_recovery'))
            rv = client.post(url_for('user.password_recovery'),
                             data=dict(csrf_token=csrf_token(rv.data),
                                       email=user_info['email'],
                                       captcha='xyzzy'))
            assert outbox.pop().send_to == {user_info['email']}

            # Now click the confirm link.
            assert message.send_to == {new_email}
            soup = BeautifulSoup(message.html, 'html.parser')
            token = soup.a['href'].split('/')[-1]
            rv = client.get(url_for('user.confirm_email_change', token=token),
                            follow_redirects=True)
        else:
            assert len(outbox) == 0

    # Verify password recovery email goes to the right place.
    with mail.record_messages() as outbox:
        rv = client.get(url_for('user.password_recovery'))
        rv = client.post(url_for('user.password_recovery'),
                         data=dict(csrf_token=csrf_token(rv.data),
                                   email=user_info['email'],
                                   captcha='xyzzy'))
        assert len(outbox) == 0
        rv = client.get(url_for('user.password_recovery'))
        rv = client.post(url_for('user.password_recovery'),
                         data=dict(csrf_token=csrf_token(rv.data),
                                   email=new_email,
                                   captcha='xyzzy'))
        assert outbox.pop().send_to == {new_email}