Don't connect to cloud if subscription expired (#11163)
* Final touch for cloud component * Fix test
This commit is contained in:
parent
c4d71e934d
commit
b56675a7bb
4 changed files with 14 additions and 25 deletions
|
@ -27,7 +27,7 @@ CONF_RELAYER = 'relayer'
|
||||||
CONF_USER_POOL_ID = 'user_pool_id'
|
CONF_USER_POOL_ID = 'user_pool_id'
|
||||||
|
|
||||||
MODE_DEV = 'development'
|
MODE_DEV = 'development'
|
||||||
DEFAULT_MODE = MODE_DEV
|
DEFAULT_MODE = 'production'
|
||||||
DEPENDENCIES = ['http']
|
DEPENDENCIES = ['http']
|
||||||
|
|
||||||
ALEXA_SCHEMA = vol.Schema({
|
ALEXA_SCHEMA = vol.Schema({
|
||||||
|
@ -42,10 +42,10 @@ CONFIG_SCHEMA = vol.Schema({
|
||||||
vol.Optional(CONF_MODE, default=DEFAULT_MODE):
|
vol.Optional(CONF_MODE, default=DEFAULT_MODE):
|
||||||
vol.In([MODE_DEV] + list(SERVERS)),
|
vol.In([MODE_DEV] + list(SERVERS)),
|
||||||
# Change to optional when we include real servers
|
# Change to optional when we include real servers
|
||||||
vol.Required(CONF_COGNITO_CLIENT_ID): str,
|
vol.Optional(CONF_COGNITO_CLIENT_ID): str,
|
||||||
vol.Required(CONF_USER_POOL_ID): str,
|
vol.Optional(CONF_USER_POOL_ID): str,
|
||||||
vol.Required(CONF_REGION): str,
|
vol.Optional(CONF_REGION): str,
|
||||||
vol.Required(CONF_RELAYER): str,
|
vol.Optional(CONF_RELAYER): str,
|
||||||
vol.Optional(CONF_ALEXA): ALEXA_SCHEMA
|
vol.Optional(CONF_ALEXA): ALEXA_SCHEMA
|
||||||
}),
|
}),
|
||||||
}, extra=vol.ALLOW_EXTRA)
|
}, extra=vol.ALLOW_EXTRA)
|
||||||
|
@ -117,10 +117,6 @@ class Cloud:
|
||||||
@property
|
@property
|
||||||
def subscription_expired(self):
|
def subscription_expired(self):
|
||||||
"""Return a boolen if the subscription has expired."""
|
"""Return a boolen if the subscription has expired."""
|
||||||
# For now, don't enforce subscriptions to exist
|
|
||||||
if 'custom:sub-exp' not in self.claims:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return dt_util.utcnow() > self.expiration_date
|
return dt_util.utcnow() > self.expiration_date
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -4,13 +4,12 @@ CONFIG_DIR = '.cloud'
|
||||||
REQUEST_TIMEOUT = 10
|
REQUEST_TIMEOUT = 10
|
||||||
|
|
||||||
SERVERS = {
|
SERVERS = {
|
||||||
# Example entry:
|
'production': {
|
||||||
# 'production': {
|
'cognito_client_id': '60i2uvhvbiref2mftj7rgcrt9u',
|
||||||
# 'cognito_client_id': '',
|
'user_pool_id': 'us-east-1_87ll5WOP8',
|
||||||
# 'user_pool_id': '',
|
'region': 'us-east-1',
|
||||||
# 'region': '',
|
'relayer': 'wss://cloud.hass.io:8000/websocket'
|
||||||
# 'relayer': ''
|
}
|
||||||
# }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MESSAGE_EXPIRATION = """
|
MESSAGE_EXPIRATION = """
|
||||||
|
|
|
@ -110,6 +110,9 @@ sensor:
|
||||||
tts:
|
tts:
|
||||||
- platform: google
|
- platform: google
|
||||||
|
|
||||||
|
# Cloud
|
||||||
|
cloud:
|
||||||
|
|
||||||
group: !include groups.yaml
|
group: !include groups.yaml
|
||||||
automation: !include automations.yaml
|
automation: !include automations.yaml
|
||||||
script: !include scripts.yaml
|
script: !include scripts.yaml
|
||||||
|
|
|
@ -132,15 +132,6 @@ def test_write_user_info():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
|
||||||
def test_subscription_not_expired_without_sub_in_claim():
|
|
||||||
"""Test that we do not enforce subscriptions yet."""
|
|
||||||
cl = cloud.Cloud(None, cloud.MODE_DEV)
|
|
||||||
cl.id_token = jwt.encode({}, 'test')
|
|
||||||
|
|
||||||
assert not cl.subscription_expired
|
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_subscription_expired():
|
def test_subscription_expired():
|
||||||
"""Test subscription being expired."""
|
"""Test subscription being expired."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue