diff --git a/homeassistant/components/cloud/auth_api.py b/homeassistant/components/cloud/auth_api.py index 118a9857158..dcf7567482a 100644 --- a/homeassistant/components/cloud/auth_api.py +++ b/homeassistant/components/cloud/auth_api.py @@ -17,14 +17,6 @@ class UserNotConfirmed(CloudError): """Raised when a user has not confirmed email yet.""" -class ExpiredCode(CloudError): - """Raised when an expired code is encountered.""" - - -class InvalidCode(CloudError): - """Raised when an invalid code is submitted.""" - - class PasswordChangeRequired(CloudError): """Raised when a password change is required.""" @@ -42,10 +34,8 @@ class UnknownError(CloudError): AWS_EXCEPTIONS = { 'UserNotFoundException': UserNotFound, 'NotAuthorizedException': Unauthenticated, - 'ExpiredCodeException': ExpiredCode, 'UserNotConfirmedException': UserNotConfirmed, 'PasswordResetRequiredException': PasswordChangeRequired, - 'CodeMismatchException': InvalidCode, } @@ -69,17 +59,6 @@ def register(cloud, email, password): raise _map_aws_exception(err) -def confirm_register(cloud, confirmation_code, email): - """Confirm confirmation code after registration.""" - from botocore.exceptions import ClientError - - cognito = _cognito(cloud) - try: - cognito.confirm_sign_up(confirmation_code, email) - except ClientError as err: - raise _map_aws_exception(err) - - def resend_email_confirm(cloud, email): """Resend email confirmation.""" from botocore.exceptions import ClientError @@ -107,18 +86,6 @@ def forgot_password(cloud, email): raise _map_aws_exception(err) -def confirm_forgot_password(cloud, confirmation_code, email, new_password): - """Confirm forgotten password code and change password.""" - from botocore.exceptions import ClientError - - cognito = _cognito(cloud, username=email) - - try: - cognito.confirm_forgot_password(confirmation_code, new_password) - except ClientError as err: - raise _map_aws_exception(err) - - def login(cloud, email, password): """Log user in and fetch certificate.""" cognito = _authenticate(cloud, email, password) diff --git a/homeassistant/components/cloud/http_api.py b/homeassistant/components/cloud/http_api.py index f7f327f2f2c..3065de24180 100644 --- a/homeassistant/components/cloud/http_api.py +++ b/homeassistant/components/cloud/http_api.py @@ -23,10 +23,8 @@ def async_setup(hass): hass.http.register_view(CloudLogoutView) hass.http.register_view(CloudAccountView) hass.http.register_view(CloudRegisterView) - hass.http.register_view(CloudConfirmRegisterView) hass.http.register_view(CloudResendConfirmView) hass.http.register_view(CloudForgotPasswordView) - hass.http.register_view(CloudConfirmForgotPasswordView) _CLOUD_ERRORS = { @@ -34,8 +32,6 @@ _CLOUD_ERRORS = { auth_api.UserNotConfirmed: (400, 'Email not confirmed.'), auth_api.Unauthenticated: (401, 'Authentication failed.'), auth_api.PasswordChangeRequired: (400, 'Password change required.'), - auth_api.ExpiredCode: (400, 'Confirmation code has expired.'), - auth_api.InvalidCode: (400, 'Invalid confirmation code.'), asyncio.TimeoutError: (502, 'Unable to reach the Home Assistant cloud.') } @@ -149,31 +145,6 @@ class CloudRegisterView(HomeAssistantView): return self.json_message('ok') -class CloudConfirmRegisterView(HomeAssistantView): - """Confirm registration on the Home Assistant cloud.""" - - url = '/api/cloud/confirm_register' - name = 'api:cloud:confirm_register' - - @_handle_cloud_errors - @RequestDataValidator(vol.Schema({ - vol.Required('confirmation_code'): str, - vol.Required('email'): str, - })) - @asyncio.coroutine - def post(self, request, data): - """Handle registration confirmation request.""" - hass = request.app['hass'] - cloud = hass.data[DOMAIN] - - with async_timeout.timeout(REQUEST_TIMEOUT, loop=hass.loop): - yield from hass.async_add_job( - auth_api.confirm_register, cloud, data['confirmation_code'], - data['email']) - - return self.json_message('ok') - - class CloudResendConfirmView(HomeAssistantView): """Resend email confirmation code.""" @@ -220,33 +191,6 @@ class CloudForgotPasswordView(HomeAssistantView): return self.json_message('ok') -class CloudConfirmForgotPasswordView(HomeAssistantView): - """View to finish Forgot Password flow..""" - - url = '/api/cloud/confirm_forgot_password' - name = 'api:cloud:confirm_forgot_password' - - @_handle_cloud_errors - @RequestDataValidator(vol.Schema({ - vol.Required('confirmation_code'): str, - vol.Required('email'): str, - vol.Required('new_password'): vol.All(str, vol.Length(min=6)) - })) - @asyncio.coroutine - def post(self, request, data): - """Handle forgot password confirm request.""" - hass = request.app['hass'] - cloud = hass.data[DOMAIN] - - with async_timeout.timeout(REQUEST_TIMEOUT, loop=hass.loop): - yield from hass.async_add_job( - auth_api.confirm_forgot_password, cloud, - data['confirmation_code'], data['email'], - data['new_password']) - - return self.json_message('ok') - - def _account_data(cloud): """Generate the auth data JSON response.""" claims = cloud.claims diff --git a/tests/components/cloud/test_auth_api.py b/tests/components/cloud/test_auth_api.py index 70cd5d83f41..a50a4d796aa 100644 --- a/tests/components/cloud/test_auth_api.py +++ b/tests/components/cloud/test_auth_api.py @@ -94,24 +94,6 @@ def test_register_fails(mock_cognito): auth_api.register(cloud, 'email@home-assistant.io', 'password') -def test_confirm_register(mock_cognito): - """Test confirming a registration of an account.""" - cloud = MagicMock() - auth_api.confirm_register(cloud, '123456', 'email@home-assistant.io') - assert len(mock_cognito.confirm_sign_up.mock_calls) == 1 - result_code, result_user = mock_cognito.confirm_sign_up.mock_calls[0][1] - assert result_user == 'email@home-assistant.io' - assert result_code == '123456' - - -def test_confirm_register_fails(mock_cognito): - """Test an error during confirmation of an account.""" - cloud = MagicMock() - mock_cognito.confirm_sign_up.side_effect = aws_error('SomeError') - with pytest.raises(auth_api.CloudError): - auth_api.confirm_register(cloud, '123456', 'email@home-assistant.io') - - def test_resend_email_confirm(mock_cognito): """Test starting forgot password flow.""" cloud = MagicMock() @@ -143,27 +125,6 @@ def test_forgot_password_fails(mock_cognito): auth_api.forgot_password(cloud, 'email@home-assistant.io') -def test_confirm_forgot_password(mock_cognito): - """Test confirming forgot password.""" - cloud = MagicMock() - auth_api.confirm_forgot_password( - cloud, '123456', 'email@home-assistant.io', 'new password') - assert len(mock_cognito.confirm_forgot_password.mock_calls) == 1 - result_code, result_password = \ - mock_cognito.confirm_forgot_password.mock_calls[0][1] - assert result_code == '123456' - assert result_password == 'new password' - - -def test_confirm_forgot_password_fails(mock_cognito): - """Test failure when confirming forgot password.""" - cloud = MagicMock() - mock_cognito.confirm_forgot_password.side_effect = aws_error('SomeError') - with pytest.raises(auth_api.CloudError): - auth_api.confirm_forgot_password( - cloud, '123456', 'email@home-assistant.io', 'new password') - - def test_check_token_writes_new_token_on_refresh(mock_cognito): """Test check_token writes new token if refreshed.""" cloud = MagicMock() diff --git a/tests/components/cloud/test_http_api.py b/tests/components/cloud/test_http_api.py index 69cd540e7d5..98ddebb5db3 100644 --- a/tests/components/cloud/test_http_api.py +++ b/tests/components/cloud/test_http_api.py @@ -231,53 +231,6 @@ def test_register_view_unknown_error(mock_cognito, cloud_client): assert req.status == 502 -@asyncio.coroutine -def test_confirm_register_view(mock_cognito, cloud_client): - """Test logging out.""" - req = yield from cloud_client.post('/api/cloud/confirm_register', json={ - 'email': 'hello@bla.com', - 'confirmation_code': '123456' - }) - assert req.status == 200 - assert len(mock_cognito.confirm_sign_up.mock_calls) == 1 - result_code, result_email = mock_cognito.confirm_sign_up.mock_calls[0][1] - assert result_email == 'hello@bla.com' - assert result_code == '123456' - - -@asyncio.coroutine -def test_confirm_register_view_bad_data(mock_cognito, cloud_client): - """Test logging out.""" - req = yield from cloud_client.post('/api/cloud/confirm_register', json={ - 'email': 'hello@bla.com', - 'not_confirmation_code': '123456' - }) - assert req.status == 400 - assert len(mock_cognito.confirm_sign_up.mock_calls) == 0 - - -@asyncio.coroutine -def test_confirm_register_view_request_timeout(mock_cognito, cloud_client): - """Test timeout while logging out.""" - mock_cognito.confirm_sign_up.side_effect = asyncio.TimeoutError - req = yield from cloud_client.post('/api/cloud/confirm_register', json={ - 'email': 'hello@bla.com', - 'confirmation_code': '123456' - }) - assert req.status == 502 - - -@asyncio.coroutine -def test_confirm_register_view_unknown_error(mock_cognito, cloud_client): - """Test unknown error while logging out.""" - mock_cognito.confirm_sign_up.side_effect = auth_api.UnknownError - req = yield from cloud_client.post('/api/cloud/confirm_register', json={ - 'email': 'hello@bla.com', - 'confirmation_code': '123456' - }) - assert req.status == 502 - - @asyncio.coroutine def test_forgot_password_view(mock_cognito, cloud_client): """Test logging out.""" @@ -358,61 +311,3 @@ def test_resend_confirm_view_unknown_error(mock_cognito, cloud_client): 'email': 'hello@bla.com', }) assert req.status == 502 - - -@asyncio.coroutine -def test_confirm_forgot_password_view(mock_cognito, cloud_client): - """Test logging out.""" - req = yield from cloud_client.post( - '/api/cloud/confirm_forgot_password', json={ - 'email': 'hello@bla.com', - 'confirmation_code': '123456', - 'new_password': 'hello2', - }) - assert req.status == 200 - assert len(mock_cognito.confirm_forgot_password.mock_calls) == 1 - result_code, result_new_password = \ - mock_cognito.confirm_forgot_password.mock_calls[0][1] - assert result_code == '123456' - assert result_new_password == 'hello2' - - -@asyncio.coroutine -def test_confirm_forgot_password_view_bad_data(mock_cognito, cloud_client): - """Test logging out.""" - req = yield from cloud_client.post( - '/api/cloud/confirm_forgot_password', json={ - 'email': 'hello@bla.com', - 'not_confirmation_code': '123456', - 'new_password': 'hello2', - }) - assert req.status == 400 - assert len(mock_cognito.confirm_forgot_password.mock_calls) == 0 - - -@asyncio.coroutine -def test_confirm_forgot_password_view_request_timeout(mock_cognito, - cloud_client): - """Test timeout while logging out.""" - mock_cognito.confirm_forgot_password.side_effect = asyncio.TimeoutError - req = yield from cloud_client.post( - '/api/cloud/confirm_forgot_password', json={ - 'email': 'hello@bla.com', - 'confirmation_code': '123456', - 'new_password': 'hello2', - }) - assert req.status == 502 - - -@asyncio.coroutine -def test_confirm_forgot_password_view_unknown_error(mock_cognito, - cloud_client): - """Test unknown error while logging out.""" - mock_cognito.confirm_forgot_password.side_effect = auth_api.UnknownError - req = yield from cloud_client.post( - '/api/cloud/confirm_forgot_password', json={ - 'email': 'hello@bla.com', - 'confirmation_code': '123456', - 'new_password': 'hello2', - }) - assert req.status == 502