async def test_enabling_remote_trusted_networks_other(opp, opp_ws_client,
                                                      setup_api,
                                                      mock_cloud_login):
    """Test we can enable remote UI when trusted networks active."""
    opp.auth._providers[("trusted_networks",
                         None)] = tn_auth.TrustedNetworksAuthProvider(
                             opp,
                             None,
                             tn_auth.CONFIG_SCHEMA({
                                 "type":
                                 "trusted_networks",
                                 "trusted_networks": ["192.168.0.0/24"]
                             }),
                         )

    client = await opp_ws_client(opp)
    cloud = opp.data[DOMAIN]

    with patch("opp_cloud.remote.RemoteUI.connect",
               return_value=mock_coro()) as mock_connect:
        await client.send_json({"id": 5, "type": "cloud/remote/connect"})
        response = await client.receive_json()

    assert response["success"]
    assert cloud.client.remote_autostart

    assert len(mock_connect.mock_calls) == 1
async def test_enabling_remote_trusted_networks_local6(opp, opp_ws_client,
                                                       setup_api,
                                                       mock_cloud_login):
    """Test we cannot enable remote UI when trusted networks active."""
    opp.auth._providers[("trusted_networks",
                         None)] = tn_auth.TrustedNetworksAuthProvider(
                             opp,
                             None,
                             tn_auth.CONFIG_SCHEMA({
                                 "type": "trusted_networks",
                                 "trusted_networks": ["::1"]
                             }),
                         )

    client = await opp_ws_client(opp)

    with patch("opp_cloud.remote.RemoteUI.connect",
               side_effect=AssertionError) as mock_connect:
        await client.send_json({"id": 5, "type": "cloud/remote/connect"})
        response = await client.receive_json()

    assert not response["success"]
    assert response["error"]["code"] == 500
    assert (
        response["error"]["message"] ==
        "Remote UI not compatible with 127.0.0.1/::1 as a trusted network.")

    assert len(mock_connect.mock_calls) == 0
Beispiel #3
0
def trusted_networks_auth(opp):
    """Load trusted networks auth provider."""
    prv = trusted_networks.TrustedNetworksAuthProvider(
        opp,
        opp.auth._store,
        {
            "type": "trusted_networks",
            "trusted_networks": TRUSTED_NETWORKS
        },
    )
    opp.auth._providers[(prv.type, prv.id)] = prv
    return prv
def provider(opp, store):
    """Mock provider."""
    return tn_auth.TrustedNetworksAuthProvider(
        opp,
        store,
        tn_auth.CONFIG_SCHEMA({
            "type":
            "trusted_networks",
            "trusted_networks": [
                "192.168.0.1",
                "192.168.128.0/24",
                "::1",
                "fd00::/8",
            ],
        }),
    )
def provider_bypass_login(opp, store):
    """Mock provider with allow_bypass_login config."""
    return tn_auth.TrustedNetworksAuthProvider(
        opp,
        store,
        tn_auth.CONFIG_SCHEMA({
            "type":
            "trusted_networks",
            "trusted_networks": [
                "192.168.0.1",
                "192.168.128.0/24",
                "::1",
                "fd00::/8",
            ],
            "allow_bypass_login":
            True,
        }),
    )
def provider_with_user(opp, store):
    """Mock provider with trusted users config."""
    return tn_auth.TrustedNetworksAuthProvider(
        opp,
        store,
        tn_auth.CONFIG_SCHEMA({
            "type":
            "trusted_networks",
            "trusted_networks": [
                "192.168.0.1",
                "192.168.128.0/24",
                "::1",
                "fd00::/8",
            ],
            # user_id will be injected in test
            "trusted_users": {
                "192.168.0.1": [],
                "192.168.128.0/24": [],
                "fd00::/8": [],
            },
        }),
    )