Example #1
0
def test_step_3_wrong_address(client, token_for_dummy_user, mocker):
    """Registration activation page with a token containing the wrong email address"""
    logger = mocker.patch("noggin.controller.registration.app.logger")
    ipa_admin.stageuser_mod(a_uid="dummy", mail="*****@*****.**")
    result = client.get(f'/register/activate?token={token_for_dummy_user}')
    assert_redirects_with_flash(
        result,
        expected_url="/?tab=register",
        expected_message=
        ("The username and the email address don't match the token you used, "
         "please register again."),
        expected_category="warning",
    )
    logger.error.assert_called_once()
Example #2
0
def spamcheck_hook():
    if not app.config.get("BASSET_URL"):
        return jsonify({"error": "Spamcheck disabled"}), 501

    data = request.get_json()
    if not data:
        return jsonify({"error": "Bad payload"}), 400

    try:
        token = data["token"]
        status = data["status"]
    except KeyError as e:
        return jsonify({"error": f"Missing key: {e}"}), 400

    try:
        token_data = read_token(token, audience=Audience.spam_check)
    except jwt.ExpiredSignatureError:
        return jsonify({"error": "The token has expired"}), 400
    except jwt.InvalidTokenError as e:
        return jsonify({"error": f"Invalid token: {e}"}), 400

    username = token_data["sub"]

    if status not in ("active", "spamcheck_denied", "spamcheck_manual"):
        return jsonify({"error": f"Invalid status: {status}."}), 400
    result = ipa_admin.stageuser_mod(a_uid=username, fasstatusnote=status)
    user = User(result["result"])

    if status == "active":
        # Send the address validation email
        _send_validation_email(user)

    return jsonify({"status": "success"})
Example #3
0
def test_step_2_spamchecking_user(client, dummy_stageuser, spamcheck_on):
    """Register a user, step 2, but the user hasn't been checked for spam"""
    ipa_admin.stageuser_mod(a_uid="dummy", fasstatusnote="spamcheck_awaiting")
    result = client.get('/register/confirm?username=dummy')
    assert result.status_code == 401
Example #4
0
def test_spamcheck_wait_active(client, dummy_stageuser):
    """Test the spamcheck_wait endpoint when the user is active"""
    ipa_admin.stageuser_mod(a_uid="dummy", fasstatusnote="active")
    result = client.get('/register/spamcheck-wait?username=dummy')
    assert result.status_code == 302
    assert result.location == "http://localhost/register/confirm?username=dummy"
Example #5
0
def test_spamcheck_wait(client, dummy_stageuser, spamcheck_status):
    """Test the spamcheck_wait endpoint"""
    ipa_admin.stageuser_mod(a_uid="dummy", fasstatusnote=spamcheck_status)
    result = client.get('/register/spamcheck-wait?username=dummy')
    assert result.status_code == 200