Пример #1
0
async def test_enabling_remote_trusted_networks_local6(hass, hass_ws_client,
                                                       setup_api,
                                                       mock_cloud_login):
    """Test we cannot enable remote UI when trusted networks active."""
    hass.auth._providers[("trusted_networks",
                          None)] = tn_auth.TrustedNetworksAuthProvider(
                              hass,
                              None,
                              tn_auth.CONFIG_SCHEMA({
                                  "type": "trusted_networks",
                                  "trusted_networks": ["::1"]
                              }),
                          )

    client = await hass_ws_client(hass)

    with patch("hass_nabucasa.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
Пример #2
0
async def test_enabling_remote_trusted_networks_other(hass, hass_ws_client,
                                                      setup_api,
                                                      mock_cloud_login):
    """Test we can enable remote UI when trusted networks active."""
    hass.auth._providers[("trusted_networks",
                          None)] = tn_auth.TrustedNetworksAuthProvider(
                              hass,
                              None,
                              tn_auth.CONFIG_SCHEMA({
                                  "type":
                                  "trusted_networks",
                                  "trusted_networks": ["192.168.0.0/24"]
                              }),
                          )

    client = await hass_ws_client(hass)
    cloud = hass.data[DOMAIN]

    with patch("hass_nabucasa.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
Пример #3
0
async def test_enabling_remote_trusted_networks_local6(hass, hass_ws_client,
                                                       setup_api,
                                                       mock_cloud_login):
    """Test we cannot enable remote UI when trusted networks active."""
    hass.auth._providers[('trusted_networks', None)] = \
        tn_auth.TrustedNetworksAuthProvider(
            hass, None, tn_auth.CONFIG_SCHEMA({
                'type': 'trusted_networks',
                'trusted_networks': [
                    '::1'
                ]
            })
        )

    client = await hass_ws_client(hass)

    with patch('hass_nabucasa.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
Пример #4
0
async def test_enabling_remote_trusted_networks_other(hass, hass_ws_client,
                                                      setup_api,
                                                      mock_cloud_login):
    """Test we can enable remote UI when trusted networks active."""
    hass.auth._providers[('trusted_networks', None)] = \
        tn_auth.TrustedNetworksAuthProvider(
            hass, None, tn_auth.CONFIG_SCHEMA({
                'type': 'trusted_networks',
                'trusted_networks': [
                    '192.168.0.0/24'
                ]
            })
        )

    client = await hass_ws_client(hass)
    cloud = hass.data[DOMAIN]

    with patch('hass_nabucasa.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
Пример #5
0
def trusted_networks_auth(hass):
    """Load trusted networks auth provider."""
    prv = trusted_networks.TrustedNetworksAuthProvider(
        hass, hass.auth._store, {
            'type': 'trusted_networks',
            'trusted_networks': TRUSTED_NETWORKS,
        })
    hass.auth._providers[(prv.type, prv.id)] = prv
    return prv
Пример #6
0
def trusted_networks_auth(hass):
    """Load trusted networks auth provider."""
    prv = trusted_networks.TrustedNetworksAuthProvider(
        hass,
        hass.auth._store,
        {"type": "trusted_networks", "trusted_networks": TRUSTED_NETWORKS},
    )
    hass.auth._providers[(prv.type, prv.id)] = prv
    return prv
Пример #7
0
def provider(hass, store):
    """Mock provider."""
    return tn_auth.TrustedNetworksAuthProvider(
        hass, store, tn_auth.CONFIG_SCHEMA({
            'type': 'trusted_networks',
            'trusted_networks': [
                '192.168.0.1',
                '192.168.128.0/24',
                '::1',
                'fd00::/8'
            ]
        })
    )
def provider(hass, store):
    """Mock provider."""
    return tn_auth.TrustedNetworksAuthProvider(
        hass,
        store,
        tn_auth.CONFIG_SCHEMA({
            "type":
            "trusted_networks",
            "trusted_networks": [
                "192.168.0.1",
                "192.168.128.0/24",
                "::1",
                "fd00::/8",
            ],
        }),
    )
Пример #9
0
def provider_bypass_login(hass, store):
    """Mock provider with allow_bypass_login config."""
    return tn_auth.TrustedNetworksAuthProvider(
        hass, 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_bypass_login(hass, store):
    """Mock provider with allow_bypass_login config."""
    return tn_auth.TrustedNetworksAuthProvider(
        hass,
        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,
            }
        ),
    )
Пример #11
0
def provider_with_user(hass, store):
    """Mock provider with trusted users config."""
    return tn_auth.TrustedNetworksAuthProvider(
        hass,
        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': [],
            },
        }))
def provider_with_user(hass, store):
    """Mock provider with trusted users config."""
    return tn_auth.TrustedNetworksAuthProvider(
        hass,
        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": [],
            },
        }),
    )
def provider(hass, store):
    """Mock provider."""
    return tn_auth.TrustedNetworksAuthProvider(hass, store,
                                               {'type': 'trusted_networks'})