diff options
-rw-r--r-- | tests/twisted/Makefile.am | 2 | ||||
-rw-r--r-- | tests/twisted/account-storage/5-12.py | 3 | ||||
-rw-r--r-- | tests/twisted/account-storage/5-14.py | 3 | ||||
-rw-r--r-- | tests/twisted/account-storage/5-17.py | 29 | ||||
-rw-r--r-- | tests/twisted/account-storage/5-99-5.py | 29 | ||||
-rw-r--r-- | tests/twisted/account-storage/storage_helper.py | 169 |
6 files changed, 226 insertions, 9 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index c09a6d3b..05bc4791 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -76,6 +76,8 @@ TWISTED_SPECIAL_BUILD_TESTS = \ account-storage/diverted-storage.py \ account-storage/5-12.py \ account-storage/5-14.py \ + account-storage/5-17.py \ + account-storage/5-99-5.py \ account-storage/create-new.py \ account-storage/load-keyfiles.py \ account-manager/server-drops-us.py \ diff --git a/tests/twisted/account-storage/5-12.py b/tests/twisted/account-storage/5-12.py index 17816616..9075d767 100644 --- a/tests/twisted/account-storage/5-12.py +++ b/tests/twisted/account-storage/5-12.py @@ -19,9 +19,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA # 02110-1301 USA -print "SKIP: MC 6 does not currently import MC 5 accounts" -raise SystemExit(77) - from storage_helper import test_keyfile from mctest import exec_test diff --git a/tests/twisted/account-storage/5-14.py b/tests/twisted/account-storage/5-14.py index d902d91b..42deb3ec 100644 --- a/tests/twisted/account-storage/5-14.py +++ b/tests/twisted/account-storage/5-14.py @@ -19,9 +19,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA # 02110-1301 USA -print "SKIP: MC 6 does not currently import MC 5 accounts" -raise SystemExit(77) - from storage_helper import test_keyfile from mctest import exec_test diff --git a/tests/twisted/account-storage/5-17.py b/tests/twisted/account-storage/5-17.py new file mode 100644 index 00000000..300c85c8 --- /dev/null +++ b/tests/twisted/account-storage/5-17.py @@ -0,0 +1,29 @@ +# Test for a former default account storage backend: +# XDG_DATA_HOME/telepathy/mission-control/, as used in MC 5.17 +# +# Copyright (C) 2009-2010 Nokia Corporation +# Copyright (C) 2009-2014 Collabora Ltd. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +from storage_helper import test_variant_file +from mctest import exec_test + +def test(q, bus, mc): + test_variant_file(q, bus, mc, '5.17') + +if __name__ == '__main__': + exec_test(test, {}, preload_mc=False, use_fake_accounts_service=False) diff --git a/tests/twisted/account-storage/5-99-5.py b/tests/twisted/account-storage/5-99-5.py new file mode 100644 index 00000000..0276238c --- /dev/null +++ b/tests/twisted/account-storage/5-99-5.py @@ -0,0 +1,29 @@ +# Test for a former default account storage backend: +# XDG_DATA_HOME/telepathy-1/mission-control/accounts.cfg, as used in MC 5.99.5 +# +# Copyright (C) 2009-2010 Nokia Corporation +# Copyright (C) 2009-2014 Collabora Ltd. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +from storage_helper import test_keyfile +from mctest import exec_test + +def test(q, bus, mc): + test_keyfile(q, bus, mc, '5.99.5') + +if __name__ == '__main__': + exec_test(test, {}, preload_mc=False, use_fake_accounts_service=False) diff --git a/tests/twisted/account-storage/storage_helper.py b/tests/twisted/account-storage/storage_helper.py index 6d78fa17..5f81548d 100644 --- a/tests/twisted/account-storage/storage_helper.py +++ b/tests/twisted/account-storage/storage_helper.py @@ -87,6 +87,18 @@ def test_keyfile(q, bus, mc, how_old='5.12'): 'w') avatar_bin.write('hello, world') avatar_bin.close() + elif how_old == '5.99.5': + old_key_file_name = os.path.join(os.environ['XDG_DATA_HOME'], + 'telepathy-1', 'mission-control', 'accounts.cfg') + + avatar_dir = (os.environ['XDG_DATA_DIRS'].split(':')[0] + + '/telepathy-1/mission-control') + os.makedirs(avatar_dir) + avatar_bin = open(avatar_dir + + '/fakecm-fakeprotocol-dontdivert1_40example_2ecom0.avatar', + 'w') + avatar_bin.write('hello, world') + avatar_bin.close() else: raise AssertionError('Unsupported value for how_old') @@ -130,11 +142,162 @@ AutomaticPresence=2;available;; mc = MC(q, bus) account_manager, properties, interfaces = connect_to_mc(q, bus, mc) - # During MC startup, it moved the old keyfile's contents into - # variant-based files, and deleted the old keyfile. - assert not os.path.exists(old_key_file_name) + if how_old < '5.99': + # MC did not delete the old files... + assert os.path.exists(old_key_file_name) + + # ... but it did import them + assert os.path.exists(os.path.join(os.environ['XDG_DATA_HOME'], + 'telepathy', 'mission-control', 'MIGRATED-TO-TELEPATHY-1.txt')) + else: + # if upgrading Tp 1 to Tp 1, the old file *is* deleted + assert not os.path.exists(old_key_file_name) + + assert os.path.exists(a1_new_variant_file_name) + assert os.path.exists(a2_new_variant_file_name) + assertEquals("'First among equals'", + account_store('get', 'variant-file', 'DisplayName', + account=a1_tail)) + assertEquals("'Second to none'", + account_store('get', 'variant-file', 'DisplayName', + account=a2_tail)) + # Because the CM is installed, we can work out the right types + # for the parameters, too. + assertEquals("'dontdivert1@example.com'", + account_store('get', 'variant-file', 'param-account', + account=a1_tail)) + assertEquals("'dontdivert2@example.com'", + account_store('get', 'variant-file', 'param-account', + account=a2_tail)) + + # Also, MC has both accounts in memory... + assertContains(cs.ACCOUNT_PATH_PREFIX + a1_tail, + properties['UsableAccounts']) + account = get_fakecm_account(bus, mc, cs.ACCOUNT_PATH_PREFIX + a1_tail) + assertEquals('dontdivert1@example.com', + account.Properties.Get(cs.ACCOUNT, 'Parameters')['account']) + assertEquals('First among equals', + account.Properties.Get(cs.ACCOUNT, 'DisplayName')) + assertEquals((dbus.ByteArray('hello, world'), 'text/plain'), + account.Properties.Get(cs.ACCOUNT_IFACE_AVATAR, 'Avatar', + byte_arrays=True)) + + assertContains(cs.ACCOUNT_PATH_PREFIX + a2_tail, + properties['UsableAccounts']) + account = get_fakecm_account(bus, mc, cs.ACCOUNT_PATH_PREFIX + a2_tail) + assertEquals('dontdivert2@example.com', + account.Properties.Get(cs.ACCOUNT, 'Parameters')['account']) + assertEquals('Second to none', + account.Properties.Get(cs.ACCOUNT, 'DisplayName')) + + # ... and no other accounts. + assertLength(2, properties['UsableAccounts']) + +def test_variant_file(q, bus, mc, how_old='5.17'): + simulated_cm = SimulatedConnectionManager(q, bus) + + if how_old == '5.17': + tp_dir = 'telepathy' + top_priority = os.path.join(os.environ['XDG_DATA_HOME'], + tp_dir, 'mission-control') + low_priority = os.path.join(os.environ['XDG_DATA_DIRS'].split(':')[0], + tp_dir, 'mission-control') + + os.makedirs(top_priority) + avatar_bin = open(top_priority + + '/fakecm-fakeprotocol-dontdivert1_40example_2ecom0.avatar', + 'w') + avatar_bin.write('hello, world') + avatar_bin.close() + + os.makedirs(low_priority) + avatar_bin = open(low_priority + + '/fakecm-fakeprotocol-dontdivert1_40example_2ecom0.avatar', + 'w') + avatar_bin.write('this version is not used') + avatar_bin.close() + + avatar_bin = open(low_priority + + '/fakecm-fakeprotocol-dontdivert2_40example_2ecom0.avatar', + 'w') + avatar_bin.write('second chance') + avatar_bin.close() + else: + raise AssertionError('Unsupported value for how_old') + + a1_old_variant_file_name = os.path.join(top_priority, + 'fakecm-fakeprotocol-dontdivert1_40example_2ecom0.account') + + a1_masked_variant_file_name = os.path.join(low_priority, + 'fakecm-fakeprotocol-dontdivert1_40example_2ecom0.account') + + a2_old_variant_file_name = os.path.join(low_priority, + 'fakecm-fakeprotocol-dontdivert2_40example_2ecom0.account') + + a1_new_variant_file_name = os.path.join(os.environ['XDG_DATA_HOME'], + 'telepathy-1', 'mission-control', + 'fakecm-fakeprotocol-dontdivert1_40example_2ecom0.account') + a1_tail = 'fakecm/fakeprotocol/dontdivert1_40example_2ecom0' + + a2_new_variant_file_name = os.path.join(os.environ['XDG_DATA_HOME'], + 'telepathy-1', 'mission-control', + 'fakecm-fakeprotocol-dontdivert2_40example_2ecom0.account') + a2_tail = 'fakecm/fakeprotocol/dontdivert2_40example_2ecom0' + + open(a1_old_variant_file_name, 'w').write(r"""{ +'manager': <'fakecm'>, +'protocol': <'fakeprotocol'>, +'Parameters': <{ + 'account': <'dontdivert1@example.com'>, + 'password': <'1'> + }>, +'DisplayName': <'First among equals'>, +'AutomaticPresence': <(uint32 2, 'available', '')>, +'AvatarMime': <'text/plain'>, +'avatar_token': <'hello, world'> +}""") + + open(a1_masked_variant_file_name, 'w').write(r"""{ +'manager': <'fakecm'>, +'protocol': <'fakeprotocol'>, +'Parameters': <{ + 'account': <'dontdivert1@example.com'>, + 'password': <'1'> + }>, +'DisplayName': <'this version is not used'>, +'AutomaticPresence': <(uint32 2, 'available', '')>, +'AvatarMime': <'text/plain'>, +'avatar_token': <'this version is not used'> +}""") + + open(a2_old_variant_file_name, 'w').write(r"""{ +'manager': <'fakecm'>, +'protocol': <'fakeprotocol'>, +'Parameters': <{ + 'account': <'dontdivert2@example.com'>, + 'password': <'2'> + }>, +'DisplayName': <'Second to none'>, +'AutomaticPresence': <(uint32 2, 'available', '')>, +'AvatarMime': <'text/plain'>, +'avatar_token': <'second chance'> +}""") + + mc = MC(q, bus) + account_manager, properties, interfaces = connect_to_mc(q, bus, mc) + + # MC did not delete the old files... + assert os.path.exists(a1_old_variant_file_name) + assert os.path.exists(a1_masked_variant_file_name) + assert os.path.exists(a2_old_variant_file_name) + + # ... but it did import them + assert os.path.exists(os.path.join(os.environ['XDG_DATA_HOME'], + 'telepathy', 'mission-control', 'MIGRATED-TO-TELEPATHY-1.txt')) + assert os.path.exists(a1_new_variant_file_name) assert os.path.exists(a2_new_variant_file_name) + assertEquals("'First among equals'", account_store('get', 'variant-file', 'DisplayName', account=a1_tail)) |