summaryrefslogtreecommitdiff
path: root/tests/twisted/account-storage
diff options
context:
space:
mode:
Diffstat (limited to 'tests/twisted/account-storage')
-rw-r--r--tests/twisted/account-storage/5-12.py29
-rw-r--r--tests/twisted/account-storage/5-14.py29
-rw-r--r--tests/twisted/account-storage/create-new.py136
-rw-r--r--tests/twisted/account-storage/default-keyring-storage.py230
-rw-r--r--tests/twisted/account-storage/diverted-storage.py6
-rw-r--r--tests/twisted/account-storage/libaccounts-sso-storage.py89
-rw-r--r--tests/twisted/account-storage/load-keyfiles.py283
-rw-r--r--tests/twisted/account-storage/storage_helper.py174
8 files changed, 652 insertions, 324 deletions
diff --git a/tests/twisted/account-storage/5-12.py b/tests/twisted/account-storage/5-12.py
new file mode 100644
index 00000000..9075d767
--- /dev/null
+++ b/tests/twisted/account-storage/5-12.py
@@ -0,0 +1,29 @@
+# Test for a former default account storage backend:
+# ~/.mission-control/accounts.cfg, as used in MC 5.0 to 5.13.1
+#
+# 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_5_12(q, bus, mc):
+ test_keyfile(q, bus, mc, '5.12')
+
+if __name__ == '__main__':
+ exec_test(test_5_12, {}, preload_mc=False, use_fake_accounts_service=False)
diff --git a/tests/twisted/account-storage/5-14.py b/tests/twisted/account-storage/5-14.py
new file mode 100644
index 00000000..42deb3ec
--- /dev/null
+++ b/tests/twisted/account-storage/5-14.py
@@ -0,0 +1,29 @@
+# Test for a former default account storage backend:
+# XDG_DATA_HOME/telepathy/mission-control/accounts.cfg, as used in MC 5.14
+#
+# 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_5_14(q, bus, mc):
+ test_keyfile(q, bus, mc, '5.14')
+
+if __name__ == '__main__':
+ exec_test(test_5_14, {}, preload_mc=False, use_fake_accounts_service=False)
diff --git a/tests/twisted/account-storage/create-new.py b/tests/twisted/account-storage/create-new.py
new file mode 100644
index 00000000..f77624a9
--- /dev/null
+++ b/tests/twisted/account-storage/create-new.py
@@ -0,0 +1,136 @@
+# Test for "stringified GVariant per account" storage backend introduced in
+# Mission Control 5.16, when creating a new account stored in this default
+# backend
+#
+# 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
+
+import time
+import os
+import os.path
+import signal
+
+import dbus
+import dbus.service
+
+from servicetest import (
+ EventPattern, assertEquals,
+ )
+from mctest import (
+ exec_test, create_fakecm_account, connect_to_mc,
+ )
+from storage_helper import (account_store)
+import constants as cs
+
+def test(q, bus, mc):
+ ctl_dir = os.environ['MC_ACCOUNT_DIR']
+ old_key_file_name = os.path.join(ctl_dir, 'accounts.cfg')
+ newer_key_file_name = os.path.join(os.environ['XDG_DATA_HOME'],
+ 'telepathy', 'mission-control', 'accounts.cfg')
+ new_variant_file_name = os.path.join(os.environ['XDG_DATA_HOME'],
+ 'telepathy', 'mission-control',
+ 'fakecm-fakeprotocol-dontdivert_40example_2ecom0.account')
+
+ account_manager, properties, interfaces = connect_to_mc(q, bus, mc)
+
+ assert properties.get('ValidAccounts') == [], \
+ properties.get('ValidAccounts')
+ assert properties.get('InvalidAccounts') == [], \
+ properties.get('InvalidAccounts')
+
+ params = dbus.Dictionary({"account": "dontdivert@example.com",
+ "password": "secrecy",
+ "snakes": dbus.UInt32(23)}, signature='sv')
+ (simulated_cm, account) = create_fakecm_account(q, bus, mc, params)
+
+ account_path = account.__dbus_object_path__
+
+ # Check the account is correctly created
+ properties = account_manager.GetAll(cs.AM,
+ dbus_interface=cs.PROPERTIES_IFACE)
+ assert properties is not None
+ assert properties.get('ValidAccounts') == [account_path], properties
+ account_path = properties['ValidAccounts'][0]
+ assert isinstance(account_path, dbus.ObjectPath), repr(account_path)
+ assert properties.get('InvalidAccounts') == [], properties
+
+ account_iface = dbus.Interface(account, cs.ACCOUNT)
+ account_props = dbus.Interface(account, cs.PROPERTIES_IFACE)
+
+ # Alter some miscellaneous r/w properties
+
+ account_props.Set(cs.ACCOUNT, 'DisplayName', 'Work account')
+ account_props.Set(cs.ACCOUNT, 'Icon', 'im-jabber')
+ account_props.Set(cs.ACCOUNT, 'Nickname', 'Joe Bloggs')
+ account_props.Set(cs.ACCOUNT, 'ConnectAutomatically', True)
+ account_props.Set(cs.ACCOUNT, 'AutomaticPresence',
+ (dbus.UInt32(cs.PRESENCE_EXTENDED_AWAY), 'xa',
+ 'never online'))
+
+ # .. let's check the keyfile
+ assert not os.path.exists(old_key_file_name)
+ assert not os.path.exists(newer_key_file_name)
+ assert os.path.exists(new_variant_file_name)
+ assert 'Joe Bloggs' in open(new_variant_file_name).read()
+ assertEquals("'fakecm'", account_store('get', 'variant-file', 'manager'))
+ assertEquals("'fakeprotocol'", account_store('get', 'variant-file',
+ 'protocol'))
+ assertEquals("'Work account'", account_store('get', 'variant-file',
+ 'DisplayName'))
+ assertEquals("'im-jabber'", account_store('get', 'variant-file',
+ 'Icon'))
+ assertEquals("'Joe Bloggs'", account_store('get', 'variant-file',
+ 'Nickname'))
+ assertEquals('true', account_store('get', 'variant-file',
+ 'ConnectAutomatically'))
+ assertEquals("(uint32 4, 'xa', 'never online')",
+ account_store('get', 'variant-file', 'AutomaticPresence'))
+ assertEquals("'dontdivert@example.com'",
+ account_store('get', 'variant-file', 'param-account'))
+ assertEquals("uint32 23",
+ account_store('get', 'variant-file', 'param-snakes'))
+ assertEquals("'secrecy'",
+ account_store('get', 'variant-file', 'param-password'))
+
+ assertEquals({'password': 'secrecy', 'account': 'dontdivert@example.com',
+ 'snakes': 23}, account.Properties.Get(cs.ACCOUNT, 'Parameters'))
+
+ # Delete the account
+ assert account_iface.Remove() is None
+ account_event, account_manager_event = q.expect_many(
+ EventPattern('dbus-signal',
+ path=account_path,
+ signal='Removed',
+ interface=cs.ACCOUNT,
+ args=[]
+ ),
+ EventPattern('dbus-signal',
+ path=cs.AM_PATH,
+ signal='AccountRemoved',
+ interface=cs.AM,
+ args=[account_path]
+ ),
+ )
+
+ # Check the account is correctly deleted
+ assert not os.path.exists(old_key_file_name)
+ assert not os.path.exists(newer_key_file_name)
+ assert not os.path.exists(new_variant_file_name)
+
+if __name__ == '__main__':
+ exec_test(test, {}, timeout=10, use_fake_accounts_service=False)
diff --git a/tests/twisted/account-storage/default-keyring-storage.py b/tests/twisted/account-storage/default-keyring-storage.py
deleted file mode 100644
index 2d3b2fcf..00000000
--- a/tests/twisted/account-storage/default-keyring-storage.py
+++ /dev/null
@@ -1,230 +0,0 @@
-# Test for default account storage backend.
-#
-# Copyright (C) 2009-2010 Nokia Corporation
-# Copyright (C) 2009-2010 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
-
-import time
-import os
-import os.path
-import signal
-
-import dbus
-import dbus.service
-
-from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
- call_async, assertEquals
-from mctest import (
- exec_test, create_fakecm_account, get_fakecm_account, connect_to_mc,
- keyfile_read, tell_mc_to_die, resuscitate_mc
- )
-import constants as cs
-
-# This doesn't escape its parameters before passing them to the shell,
-# so be careful.
-def account_store(op, backend, key=None, value=None,
- account='fakecm/fakeprotocol/dontdivert_40example_2ecom0'):
- cmd = [ '../account-store', op, backend, account ]
- if key:
- cmd.append(key)
- if value:
- cmd.append(value)
-
- lines = os.popen(' '.join(cmd)).read()
- ret = []
- for line in lines.split('\n'):
- if line.startswith('** '):
- continue
-
- if line:
- ret.append(line)
-
- if len(ret) > 0:
- return ret[0]
- else:
- return None
-
-def test(q, bus, mc):
- ctl_dir = os.environ['MC_ACCOUNT_DIR']
- old_key_file_name = os.path.join(ctl_dir, 'accounts.cfg')
- new_key_file_name = os.path.join(os.environ['XDG_DATA_HOME'],
- 'telepathy', 'mission-control', 'accounts.cfg')
- group = 'fakecm/fakeprotocol/dontdivert_40example_2ecom0'
-
- account_manager, properties, interfaces = connect_to_mc(q, bus, mc)
-
- assert properties.get('ValidAccounts') == [], \
- properties.get('ValidAccounts')
- assert properties.get('InvalidAccounts') == [], \
- properties.get('InvalidAccounts')
-
- params = dbus.Dictionary({"account": "dontdivert@example.com",
- "password": "secrecy"}, signature='sv')
- (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params)
-
- account_path = account.__dbus_object_path__
-
- # Check the account is correctly created
- properties = account_manager.GetAll(cs.AM,
- dbus_interface=cs.PROPERTIES_IFACE)
- assert properties is not None
- assert properties.get('ValidAccounts') == [account_path], properties
- account_path = properties['ValidAccounts'][0]
- assert isinstance(account_path, dbus.ObjectPath), repr(account_path)
- assert properties.get('InvalidAccounts') == [], properties
-
- account_iface = dbus.Interface(account, cs.ACCOUNT)
- account_props = dbus.Interface(account, cs.PROPERTIES_IFACE)
-
- # Alter some miscellaneous r/w properties
-
- account_props.Set(cs.ACCOUNT, 'DisplayName', 'Work account')
- account_props.Set(cs.ACCOUNT, 'Icon', 'im-jabber')
- account_props.Set(cs.ACCOUNT, 'Nickname', 'Joe Bloggs')
-
- tell_mc_to_die(q, bus)
-
- # .. let's check the keyfile
- assert not os.path.exists(old_key_file_name)
- kf = keyfile_read(new_key_file_name)
- assert group in kf, kf
- assert kf[group]['manager'] == 'fakecm'
- assert kf[group]['protocol'] == 'fakeprotocol'
- assert kf[group]['param-account'] == params['account'], kf
- assert kf[group]['DisplayName'] == 'Work account', kf
- assert kf[group]['Icon'] == 'im-jabber', kf
- assert kf[group]['Nickname'] == 'Joe Bloggs', kf
-
- # This works wherever the password is stored
- pwd = account_store('get', 'default', 'param-password')
- assert pwd == params['password'], pwd
-
- # We no longer use gnome-keyring, so the password is stored as clear-text.
- assert kf[group]['param-password'] == params['password'], kf
-
- # Reactivate MC
- account_manager, properties, interfaces = resuscitate_mc(q, bus, mc)
- account = get_fakecm_account(bus, mc, account_path)
- account_iface = dbus.Interface(account, cs.ACCOUNT)
-
- # Delete the account
- assert account_iface.Remove() is None
- account_event, account_manager_event = q.expect_many(
- EventPattern('dbus-signal',
- path=account_path,
- signal='Removed',
- interface=cs.ACCOUNT,
- args=[]
- ),
- EventPattern('dbus-signal',
- path=cs.AM_PATH,
- signal='AccountRemoved',
- interface=cs.AM,
- args=[account_path]
- ),
- )
-
- # Check the account is correctly deleted
- assert not os.path.exists(old_key_file_name)
- kf = keyfile_read(new_key_file_name)
- assert group not in kf, kf
-
- # Tell MC to die, again
- tell_mc_to_die(q, bus)
-
- low_prio_key_file_name = os.path.join(
- os.environ['XDG_DATA_DIRS'].split(':')[0],
- 'telepathy', 'mission-control', 'accounts.cfg')
- os.makedirs(os.path.dirname(low_prio_key_file_name), 0700)
-
- # This is deliberately a lower-priority location
- os.remove(new_key_file_name)
- open(low_prio_key_file_name, 'w').write(
-r"""# Telepathy accounts
-[%s]
-manager=fakecm
-protocol=fakeprotocol
-param-account=dontdivert@example.com
-param-password=password_in_keyfile
-DisplayName=New and improved account
-AutomaticPresence=2;available;;
-""" % group)
-
- account_manager, properties, interfaces = resuscitate_mc(q, bus, mc)
- account = get_fakecm_account(bus, mc, account_path)
- account_iface = dbus.Interface(account, cs.ACCOUNT)
-
- # Files in lower-priority XDG locations aren't copied until something
- # actually changes, and they aren't deleted.
- assert not os.path.exists(new_key_file_name)
- assert os.path.exists(low_prio_key_file_name)
-
- # Delete the password (only), like Empathy 3.0-3.4 do when migrating
- account_iface.UpdateParameters({}, ['password'])
- q.expect('dbus-signal',
- path=account_path,
- signal='AccountPropertyChanged',
- interface=cs.ACCOUNT,
- predicate=(lambda e:
- 'Parameters' in e.args[0]),
- )
-
- # Tell MC to die yet again
- tell_mc_to_die(q, bus)
-
- # Check the account has copied (not moved! XDG_DATA_DIRS are,
- # conceptually, read-only) from the old to the new name
- assert not os.path.exists(old_key_file_name)
- assert os.path.exists(low_prio_key_file_name)
- kf = keyfile_read(new_key_file_name)
- assert 'param-password' not in kf[group]
- pwd = account_store('get', 'default', 'param-password')
- assertEquals(None, pwd)
-
- # Write out an account configuration in the old keyfile, to test
- # migration
- os.remove(new_key_file_name)
- os.remove(low_prio_key_file_name)
- open(old_key_file_name, 'w').write(
-r"""# Telepathy accounts
-[%s]
-manager=fakecm
-protocol=fakeprotocol
-param-account=dontdivert@example.com
-DisplayName=Ye olde account
-AutomaticPresence=2;available;;
-""" % group)
-
- account_manager, properties, interfaces = resuscitate_mc(q, bus, mc)
- account = get_fakecm_account(bus, mc, account_path)
- account_iface = dbus.Interface(account, cs.ACCOUNT)
-
- # This time it *does* get moved (really copied+deleted) automatically
- # during MC startup
- assert not os.path.exists(old_key_file_name)
- assert not os.path.exists(low_prio_key_file_name)
- kf = keyfile_read(new_key_file_name)
- assert 'param-password' not in kf[group]
- assertEquals('Ye olde account', kf[group]['DisplayName'])
-
-if __name__ == '__main__':
- ctl_dir = os.environ['MC_ACCOUNT_DIR']
- try:
- os.mkdir(ctl_dir, 0700)
- except OSError:
- pass
- exec_test(test, {}, timeout=10, use_fake_accounts_service=False)
diff --git a/tests/twisted/account-storage/diverted-storage.py b/tests/twisted/account-storage/diverted-storage.py
index 8692b09b..7aa011e8 100644
--- a/tests/twisted/account-storage/diverted-storage.py
+++ b/tests/twisted/account-storage/diverted-storage.py
@@ -53,7 +53,7 @@ def test(q, bus, mc):
params = dbus.Dictionary({"account": "someguy@example.com",
"password": "secrecy"}, signature='sv')
- (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params)
+ (simulated_cm, account) = create_fakecm_account(q, bus, mc, params)
account_path = account.__dbus_object_path__
@@ -88,10 +88,6 @@ def test(q, bus, mc):
assert kf[group]['Icon'] == 'im-jabber', kf
assert kf[group]['Nickname'] == 'Joe Bloggs', kf
- # default keyfile should be empty
- ekf = keyfile_read(empty_key_file_name)
- assert ekf == { None: {} }, ekf
-
# Reactivate MC
account_manager, properties, interfaces = resuscitate_mc(q, bus, mc)
account = get_fakecm_account(bus, mc, account_path)
diff --git a/tests/twisted/account-storage/libaccounts-sso-storage.py b/tests/twisted/account-storage/libaccounts-sso-storage.py
deleted file mode 100644
index a2e7b512..00000000
--- a/tests/twisted/account-storage/libaccounts-sso-storage.py
+++ /dev/null
@@ -1,89 +0,0 @@
-# Copyright (C) 2009-2010 Nokia Corporation
-# Copyright (C) 2009-2010 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
-
-raise AssertionError('Disabled for 5.6 branch')
-
-import time
-import os
-import os.path
-import signal
-import sys
-
-import dbus
-import dbus.service
-
-from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \
- call_async
-from mctest import exec_test, create_fakecm_account, get_account_manager, \
- get_fakecm_account
-import constants as cs
-
-if ('ACCOUNTS' not in os.environ or not os.environ['ACCOUNTS']):
- print "Not testing accounts-sso storage"
- sys.exit(0)
-
-def account_store(op, backend, key=None, value=None):
- cmd = [ '../account-store', op, backend,
- 'colltest42@googlemail.com' ]
- if key:
- cmd.append(key)
- if value:
- cmd.append(value)
-
- lines = os.popen(' '.join(cmd)).read()
- ret = []
- for line in lines.split('\n'):
- if line.startswith('** '):
- continue
-
- if line:
- ret.append(line)
-
- if len(ret) > 0:
- return ret[0]
- else:
- return None
-
-def prepare_accounts_db(ctl_dir):
- os.system('cp %s/../tools/example-accounts.db %s/accounts.db' % (ctl_dir, ctl_dir))
- os.system('cp %s/../tools/accounts-sso-example.service %s/google-talk.service' % (ctl_dir, ctl_dir))
-
-def test(q, bus, mc):
- account_manager, properties, interfaces = connect_to_mc(q, bus, mc)
-
- va = properties.get('ValidAccounts')
- assert va == [], va
-
- ia = properties.get('InvalidAccounts')
- assert len(ia) == 1
-
- account_path = ia[0]
- print repr(account_path)
-
- account = get_fakecm_account(bus, mc, account_path)
- account_iface = dbus.Interface(account, cs.ACCOUNT)
- account_props = dbus.Interface(account, cs.PROPERTIES_IFACE)
-
- # FIXME at this point MC crashes
- properties = account_props.GetAll(cs.ACCOUNT)
-
-
-if __name__ == '__main__':
- ctl_dir = os.environ['ACCOUNTS']
- prepare_accounts_db(ctl_dir)
- exec_test(test, {}, timeout=10, use_fake_accounts_service=False)
diff --git a/tests/twisted/account-storage/load-keyfiles.py b/tests/twisted/account-storage/load-keyfiles.py
new file mode 100644
index 00000000..b6c9d2ef
--- /dev/null
+++ b/tests/twisted/account-storage/load-keyfiles.py
@@ -0,0 +1,283 @@
+# Test for "stringified GVariant per account" storage backend introduced in
+# Mission Control 5.16, when loading pre-prepared files
+#
+# 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
+
+import errno
+import os
+import os.path
+
+import dbus
+
+from servicetest import (
+ assertEquals, assertContains, assertDoesNotContain,
+ )
+from mctest import (
+ MC, exec_test, get_fakecm_account, connect_to_mc,
+ SimulatedConnectionManager,
+ )
+from storage_helper import (
+ account_store,
+ )
+import constants as cs
+
+def test(q, bus, mc):
+ simulated_cm = SimulatedConnectionManager(q, bus)
+
+ ctl_dir = os.environ['MC_ACCOUNT_DIR']
+ old_key_file_name = os.path.join(ctl_dir, 'accounts.cfg')
+ newer_key_file_name = os.path.join(os.environ['XDG_DATA_HOME'],
+ 'telepathy', 'mission-control', 'accounts.cfg')
+
+ # We do several scenarios in one MC run, to speed up testing a bit.
+ scenarios = ('low', 'priority', 'masked', 'migration', 'absentcm')
+
+ variant_file_names = {}
+ low_prio_variant_file_names = {}
+ account_paths = {}
+ tails = {}
+
+ for s in scenarios:
+ variant_file_names[s] = os.path.join(os.environ['XDG_DATA_HOME'],
+ 'telepathy', 'mission-control',
+ 'fakecm-fakeprotocol-dontdivert%s_40example_2ecom0.account'
+ % s)
+ tails[s] = ('fakecm/fakeprotocol/dontdivert%s_40example_2ecom0' % s)
+ account_paths[s] = cs.ACCOUNT_PATH_PREFIX + tails[s]
+ low_prio_variant_file_names[s] = os.path.join(
+ os.environ['XDG_DATA_DIRS'].split(':')[0],
+ 'telepathy', 'mission-control',
+ 'fakecm-fakeprotocol-dontdivert%s_40example_2ecom0.account' %
+ s)
+
+ try:
+ os.makedirs(os.path.dirname(variant_file_names[s]), 0700)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+
+ try:
+ os.makedirs(os.path.dirname(low_prio_variant_file_names[s]), 0700)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+
+ # This is deliberately a lower-priority location
+ open(low_prio_variant_file_names['low'], 'w').write(
+"""{
+'manager': <'fakecm'>,
+'protocol': <'fakeprotocol'>,
+'DisplayName': <'Account in a low-priority location'>,
+'AutomaticPresence': <(uint32 2, 'available', '')>,
+'Parameters': <{
+ 'account': <'dontdivertlow@example.com'>,
+ 'password': <'password_in_variant_file'>,
+ 'snakes': <uint32 42>
+ }>
+}
+""")
+
+ # This is in a lower-priority location and we don't know the
+ # parameters' types yet
+ open(low_prio_variant_file_names['migration'], 'w').write(
+"""{
+'manager': <'fakecm'>,
+'protocol': <'fakeprotocol'>,
+'DisplayName': <'Account in a low-priority location with KeyFileParameters'>,
+'AutomaticPresence': <(uint32 2, 'available', '')>,
+'KeyFileParameters': <{
+ 'account': 'dontdivertmigration@example.com',
+ 'password': 'password_in_variant_file',
+ 'snakes': '42'
+ }>
+}
+""")
+
+ # This is in a lower-priority location, and we don't know the
+ # parameters' types, and we can't learn them by asking the CM
+ # because it isn't installed
+ open(low_prio_variant_file_names['absentcm'], 'w').write(
+"""{
+'manager': <'absentcm'>,
+'protocol': <'absentprotocol'>,
+'DisplayName': <'Account in a low-priority location with absent CM'>,
+'AutomaticPresence': <(uint32 2, 'available', '')>,
+'KeyFileParameters': <{
+ 'account': 'dontdivertabsentcm@example.com',
+ 'password': 'hello',
+ 'snakes': '42'
+ }>
+}
+""")
+
+ # This version of this account will be used
+ open(variant_file_names['priority'], 'w').write("""{
+'manager': <'fakecm'>,
+'protocol': <'fakeprotocol'>,
+'DisplayName': <'Visible'>,
+'AutomaticPresence': <(uint32 2, 'available', '')>,
+'KeyFileParameters': <{'account': 'dontdivertpriority@example.com',
+ 'password': 'password_in_variant_file',
+ 'snakes': '42'
+ }>
+}
+""")
+ # This one won't, because it's "masked" by the higher-priority one
+ open(low_prio_variant_file_names['priority'], 'w').write("""{
+'manager': <'fakecm'>,
+'protocol': <'fakeprotocol'>,
+'DisplayName': <'Hidden'>,
+'Nickname': <'Hidden'>,
+'AutomaticPresence': <(uint32 2, 'available', '')>,
+'KeyFileParameters': <{'account': 'dontdivertpriority@example.com',
+ 'password': 'password_in_variant_file',
+ 'snakes': '42'
+ }>
+}
+""")
+
+ # This empty file is considered to "mask" the lower-priority one
+ open(variant_file_names['masked'], 'w').write('')
+ open(low_prio_variant_file_names['masked'], 'w').write("""{
+'manager': <'fakecm'>,
+'protocol': <'fakeprotocol'>,
+'AutomaticPresence': <(uint32 2, 'available', '')>,
+'KeyFileParameters': <{'account': 'dontdivert@example.com',
+ 'password': 'password_in_variant_file',
+ 'snakes': '42'
+ }>
+}
+""")
+
+ mc = MC(q, bus)
+ account_manager, properties, interfaces = connect_to_mc(q, bus, mc)
+
+ for s in scenarios:
+ if s == 'masked':
+ assertDoesNotContain(account_paths[s], properties['ValidAccounts'])
+ assertDoesNotContain(account_paths[s], properties['InvalidAccounts'])
+ elif s == 'absentcm':
+ assertContains(account_paths[s], properties['InvalidAccounts'])
+ assertDoesNotContain(account_paths[s], properties['ValidAccounts'])
+ else:
+ assertContains(account_paths[s], properties['ValidAccounts'])
+ assertDoesNotContain(account_paths[s], properties['InvalidAccounts'])
+
+ accounts = {}
+ account_ifaces = {}
+
+ for s in scenarios:
+ if s != 'masked':
+ accounts[s] = get_fakecm_account(bus, mc, account_paths[s])
+ account_ifaces[s] = dbus.Interface(accounts[s], cs.ACCOUNT)
+
+ if s not in ('masked', 'absentcm'):
+ # We can't get untyped parameters if we don't know what types
+ # the CM gives them.
+ assertEquals(42, accounts[s].Properties.Get(cs.ACCOUNT,
+ 'Parameters')['snakes'])
+ assertEquals(dbus.UInt32,
+ type(accounts[s].Properties.Get(cs.ACCOUNT,
+ 'Parameters')['snakes']))
+
+ # Files in lower-priority XDG locations aren't copied until something
+ # actually changes, and they aren't deleted.
+
+ if s == 'low':
+ assert os.path.exists(low_prio_variant_file_names[s])
+
+ # Delete the password (only), like Empathy 3.0-3.4 do when migrating.
+ # This results in the higher-priority file being written out.
+ account_ifaces['low'].UpdateParameters({}, ['password'])
+ q.expect('dbus-signal',
+ path=account_paths['low'],
+ signal='AccountPropertyChanged',
+ interface=cs.ACCOUNT,
+ predicate=(lambda e:
+ 'Parameters' in e.args[0]),
+ )
+ # Check the account has copied (not moved! XDG_DATA_DIRS are,
+ # conceptually, read-only) 'low' from the old to the new name
+ assert not os.path.exists(old_key_file_name)
+ assert not os.path.exists(newer_key_file_name)
+ assert os.path.exists(low_prio_variant_file_names['low'])
+ assert os.path.exists(variant_file_names['low'])
+
+ # test that priority works
+ assertContains(account_paths["priority"], properties['ValidAccounts'])
+ assertEquals('',
+ accounts['priority'].Properties.Get(cs.ACCOUNT, 'Nickname'))
+ assertEquals('Visible',
+ accounts['priority'].Properties.Get(cs.ACCOUNT, 'DisplayName'))
+
+ # test what happens when we delete an account that has a lower-priority
+ # "other self": it becomes masked
+ assert accounts['priority'].Remove() is None
+ assert not os.path.exists(old_key_file_name)
+ assert not os.path.exists(newer_key_file_name)
+ assert os.path.exists(low_prio_variant_file_names['priority'])
+ assert os.path.exists(variant_file_names['priority'])
+ assert open(variant_file_names['priority'], 'r').read() == ''
+ assertContains('password_in_variant_file',
+ open(low_prio_variant_file_names['priority'], 'r').read())
+
+ # The masked account is still masked
+ assert open(variant_file_names['masked'], 'r').read() == ''
+
+ # Because the CM exists, we can work out the correct types
+ # for the 'migration' account's parameters. This triggers a commit
+ # even though nothing has conceptually changed, so we have the type
+ # for later. The file is copied, not moved, because XDG_DATA_DIRS are,
+ # conceptually, read-only.
+ assert not os.path.exists(old_key_file_name)
+ assert not os.path.exists(newer_key_file_name)
+ assert os.path.exists(low_prio_variant_file_names['migration'])
+ assert os.path.exists(variant_file_names['migration'])
+ assertEquals("'password_in_variant_file'",
+ account_store('get', 'variant-file', 'param-password',
+ account=tails['migration']))
+ assertEquals("uint32 42", account_store('get', 'variant-file',
+ 'param-snakes', account=tails['migration']))
+
+ # Setting the password still does the right thing.
+ account_ifaces['migration'].UpdateParameters({'password': 'hello'}, [])
+ q.expect('dbus-signal',
+ path=account_paths['migration'],
+ signal='AccountPropertyChanged',
+ interface=cs.ACCOUNT,
+ predicate=(lambda e:
+ 'Parameters' in e.args[0]),
+ )
+ assert not os.path.exists(old_key_file_name)
+ assert not os.path.exists(newer_key_file_name)
+ assert os.path.exists(low_prio_variant_file_names['migration'])
+ assert os.path.exists(variant_file_names['migration'])
+ assertEquals("'hello'",
+ account_store('get', 'variant-file', 'param-password',
+ account=tails['migration']))
+
+ # 'absentcm' is still only in the low-priority location: we can't
+ # known the types of its parameters, so it doesn't get migrated.
+ assert not os.path.exists(old_key_file_name)
+ assert not os.path.exists(newer_key_file_name)
+ assert os.path.exists(low_prio_variant_file_names['absentcm'])
+ assert not os.path.exists(variant_file_names['absentcm'])
+
+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
new file mode 100644
index 00000000..0f67df92
--- /dev/null
+++ b/tests/twisted/account-storage/storage_helper.py
@@ -0,0 +1,174 @@
+# Helper code for former default account storage backends
+#
+# 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
+
+import errno
+import os
+import os.path
+
+import dbus
+
+from servicetest import (
+ assertEquals, assertContains, assertLength,
+ )
+from mctest import (
+ exec_test, get_fakecm_account, connect_to_mc,
+ MC, SimulatedConnectionManager,
+ )
+import constants as cs
+
+# This doesn't escape its parameters before passing them to the shell,
+# so be careful.
+def account_store(op, backend, key=None, value=None,
+ account='fakecm/fakeprotocol/dontdivert_40example_2ecom0'):
+ cmd = [ '../account-store', op, backend, account ]
+ if key:
+ cmd.append(key)
+ if value:
+ cmd.append(value)
+
+ lines = os.popen(' '.join(cmd)).read()
+ ret = []
+ for line in lines.split('\n'):
+ if line.startswith('** '):
+ continue
+
+ if line:
+ ret.append(line)
+
+ if len(ret) > 0:
+ return ret[0]
+ else:
+ return None
+
+def test_keyfile(q, bus, mc, how_old='5.12'):
+ simulated_cm = SimulatedConnectionManager(q, bus)
+
+ if how_old == '5.12':
+ # This is not actually ~/.mission-control, but it uses the same
+ # code paths.
+ dot_mission_control = os.environ['MC_ACCOUNT_DIR']
+ old_key_file_name = os.path.join(dot_mission_control, 'accounts.cfg')
+
+ os.makedirs(dot_mission_control +
+ '/fakecm/fakeprotocol/dontdivert1_40example_2ecom0')
+ avatar_bin = open(dot_mission_control +
+ '/fakecm/fakeprotocol/dontdivert1_40example_2ecom0/avatar.bin',
+ 'w')
+ avatar_bin.write('hello, world')
+ avatar_bin.close()
+ elif how_old == '5.14':
+ # Same format, different location.
+ old_key_file_name = os.path.join(os.environ['XDG_DATA_HOME'],
+ 'telepathy', 'mission-control', 'accounts.cfg')
+
+ # exercise override of an avatar in XDG_DATA_DIRS
+ avatar_dir = (os.environ['XDG_DATA_DIRS'].split(':')[0] +
+ '/telepathy/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')
+
+ a1_new_variant_file_name = os.path.join(os.environ['XDG_DATA_HOME'],
+ 'telepathy', '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', 'mission-control',
+ 'fakecm-fakeprotocol-dontdivert2_40example_2ecom0.account')
+ a2_tail = 'fakecm/fakeprotocol/dontdivert2_40example_2ecom0'
+
+ try:
+ os.makedirs(os.path.dirname(old_key_file_name), 0700)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+
+ open(old_key_file_name, 'w').write(
+r"""# Telepathy accounts
+[%s]
+manager=fakecm
+protocol=fakeprotocol
+param-account=dontdivert1@example.com
+param-password=1
+DisplayName=First among equals
+AutomaticPresence=2;available;;
+AvatarMime=text/plain
+avatar_token=hello, world
+
+[%s]
+manager=fakecm
+protocol=fakeprotocol
+param-account=dontdivert2@example.com
+param-password=2
+DisplayName=Second to none
+AutomaticPresence=2;available;;
+""" % (a1_tail, a2_tail))
+
+ 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)
+ 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['ValidAccounts'])
+ 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['ValidAccounts'])
+ 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['ValidAccounts'])