def test_disable_association_marks_user_for_deletion(self):
        self.firebase_sdk_stub.create_user('aid')
        firebase_auth_services.associate_auth_id_with_user_id(
            auth_domain.AuthIdUserIdPair('aid', 'uid'))

        self.assertIsNotNone(
            auth_models.UserIdByFirebaseAuthIdModel.get('aid', strict=False))
        self.assertFalse(firebase_admin.auth.get_user('aid').disabled)

        firebase_auth_services.mark_user_for_deletion('uid')

        self.assertIsNone(
            auth_models.UserIdByFirebaseAuthIdModel.get('aid', strict=False))
        self.assertTrue(firebase_admin.auth.get_user('aid').disabled)
Example #2
0
    def test_disable_association_warns_when_firebase_fails_to_init(self):
        firebase_admin.auth.create_user(uid='aid')
        firebase_auth_services.associate_auth_id_with_user_id(
            auth_domain.AuthIdUserIdPair('aid', 'uid'))
        init_swap = self.swap_to_always_raise(
            firebase_admin, 'initialize_app',
            error=firebase_exceptions.UnknownError('could not init'))

        self.assertIsNotNone(
            auth_models.UserIdByFirebaseAuthIdModel.get('aid', strict=False))
        self.assertFalse(firebase_admin.auth.get_user('aid').disabled)

        with init_swap, self.capture_logging() as logs:
            firebase_auth_services.mark_user_for_deletion('uid')

        self.assert_matches_regexps(logs, ['could not init'])
        self.assertIsNone(
            auth_models.UserIdByFirebaseAuthIdModel.get('aid', strict=False))
        self.assertFalse(firebase_admin.auth.get_user('aid').disabled)
Example #3
0
    def test_disable_association_warns_when_firebase_fails_to_update_user(self):
        self.firebase_sdk_stub.create_user('aid')
        firebase_auth_services.associate_auth_id_with_user_id(
            auth_domain.AuthIdUserIdPair('aid', 'uid'))
        update_user_swap = self.swap_to_always_raise(
            firebase_admin.auth, 'update_user',
            error=firebase_exceptions.UnknownError('could not update'))
        log_capturing_context = self.capture_logging()

        self.assertIsNotNone(
            auth_models.UserIdByFirebaseAuthIdModel.get('aid', strict=False))
        self.assertFalse(firebase_admin.auth.get_user('aid').disabled)

        with update_user_swap, log_capturing_context as logs:
            firebase_auth_services.mark_user_for_deletion('uid')

        self.assert_matches_regexps(logs, ['could not update'])
        self.assertIsNone(
            auth_models.UserIdByFirebaseAuthIdModel.get('aid', strict=False))
        self.assertFalse(firebase_admin.auth.get_user('aid').disabled)