def test_deleting_security_key(
    app_,
    client_request,
    api_nongov_user_active,
    mock_get_security_keys_with_key,
    mocker,
):
    delete_mock = mocker.patch("app.user_api_client.delete_security_key_user")
    key_id = "security_key_id"

    # Listing keys
    with captured_templates(app_) as templates:
        client_request.get(("main.user_profile_security_keys_confirm_delete"),
                           keyid=key_id)
        template, context = templates[0]
        assert template.name == "views/user-profile/security-keys.html"

    # Clicking on the button
    client_request.post(
        ("main.user_profile_security_keys_confirm_delete"),
        keyid=key_id,
        _expected_status=302,
        _expected_redirect=url_for(
            "main.user_profile_security_keys",
            _external=True,
        ),
    )

    delete_mock.assert_called_once_with(api_nongov_user_active["id"],
                                        key=key_id)
def test_should_list_security_keys(app_, client_request,
                                   api_nongov_user_active,
                                   mock_get_security_keys_with_key):
    with captured_templates(app_) as templates:
        page = client_request.get(("main.user_profile_security_keys"))
        template, context = templates[0]
        assert template.name == "views/user-profile/security-keys.html"
        assert page.select("tr")[-1].text.split() == ["Name", "Key", "Remove"]
예제 #3
0
def test_view_edit_user_org_permissions(
    client_request,
    mock_get_organisation,
    api_user_active,
    app_,
):
    with captured_templates(app_) as templates:
        client_request.get(
            ".edit_user_org_permissions",
            org_id=ORGANISATION_ID,
            user_id=api_user_active["id"],
        )
        template, _ = templates[0]
        assert template.name == "views/organisations/organisation/users/user/index.html"
예제 #4
0
def test_should_render_security_key_on_email_two_factor_page(
        app_, client, api_user_active, mock_get_security_keys_with_key,
        mock_get_user):
    with client.session_transaction() as session:
        session["user_details"] = {
            "id": api_user_active["id"],
            "email": api_user_active["email_address"],
        }

    with captured_templates(app_) as templates:
        response = client.get(url_for("main.two_factor_email_sent"))
        assert response.status_code == 200
        assert "<div id='two-factor-fido'" in response.data.decode(
            "utf-8")  # JS relies on this

        template, context = templates[0]
        assert template.name == "views/two-factor-fido.html"
def test_adding_security_key(app_, client_request, api_nongov_user_active,
                             mocker):
    register_mock = mocker.patch("app.user_api_client.register_security_key",
                                 return_value={"data": "blob"})

    # Listing keys
    with captured_templates(app_) as templates:
        page = client_request.get(("main.user_profile_add_security_keys"))
        assert 'data-button-id="register-key"' in str(page)  # Used by JS
        template, context = templates[0]
        assert template.name == "views/user-profile/add-security-keys.html"

    # Register key
    client_request.post(
        ("main.user_profile_add_security_keys"),
        _expected_status=200,
    )
    register_mock.assert_called_once_with(api_nongov_user_active["id"])