|
| 1 | +# Copyright 2021 The Matrix.org Foundation C.I.C. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +from twisted.test.proto_helpers import MemoryReactor |
| 15 | + |
| 16 | +from synapse.api.constants import AccountDataTypes |
| 17 | +from synapse.rest import admin |
| 18 | +from synapse.rest.client import account, login |
| 19 | +from synapse.server import HomeServer |
| 20 | +from synapse.util import Clock |
| 21 | + |
| 22 | +from tests.unittest import HomeserverTestCase |
| 23 | + |
| 24 | + |
| 25 | +class DeactivateAccountTestCase(HomeserverTestCase): |
| 26 | + servlets = [ |
| 27 | + login.register_servlets, |
| 28 | + admin.register_servlets, |
| 29 | + account.register_servlets, |
| 30 | + ] |
| 31 | + |
| 32 | + def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: |
| 33 | + super(DeactivateAccountTestCase, self).prepare(reactor, clock, hs) |
| 34 | + self._store = hs.get_datastore() |
| 35 | + |
| 36 | + self.user = self.register_user("user", "pass") |
| 37 | + self.token = self.login("user", "pass") |
| 38 | + |
| 39 | + def test_account_data_deleted_upon_deactivation(self) -> None: |
| 40 | + """ |
| 41 | + Tests that account data is removed upon deactivation. |
| 42 | + """ |
| 43 | + # Add some account data |
| 44 | + self.get_success( |
| 45 | + self._store.add_account_data_for_user( |
| 46 | + self.user, |
| 47 | + AccountDataTypes.DIRECT, |
| 48 | + {"@someone:remote": ["!somewhere:remote"]}, |
| 49 | + ) |
| 50 | + ) |
| 51 | + |
| 52 | + # Request the deactivation of our account |
| 53 | + req = self.get_success( |
| 54 | + self.make_request( |
| 55 | + "POST", |
| 56 | + "account/deactivate", |
| 57 | + { |
| 58 | + "auth": { |
| 59 | + "type": "m.login.password", |
| 60 | + "user": self.user, |
| 61 | + "password": "pass", |
| 62 | + }, |
| 63 | + "erase": True, |
| 64 | + }, |
| 65 | + access_token=self.token, |
| 66 | + ) |
| 67 | + ) |
| 68 | + self.assertEqual(req.code, 200, req) |
| 69 | + |
| 70 | + # Check that the account data does not persist. |
| 71 | + self.assertIsNone( |
| 72 | + self.get_success( |
| 73 | + self._store.get_global_account_data_by_type_for_user( |
| 74 | + AccountDataTypes.DIRECT, |
| 75 | + self.user, |
| 76 | + ) |
| 77 | + ), |
| 78 | + ) |
0 commit comments