summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2014-01-27 20:16:21 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2014-01-29 19:28:34 +0000
commit1beafc65f2125df00f89a8e47c7ac67a7be9fb9b (patch)
tree1943e8e98bbcfce45e0a8ff6632eb9d698707c44
parentc00effb16665ac09f3fa5bb781f2e65b0899f66b (diff)
Add dedicated tests for keyfile-based storage
These are impossible to test without restarting Mission Control, because we only read from one such location at a time; so there's no point in trying to bundle them into one test.
-rw-r--r--tests/twisted/Makefile.am6
-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/default-keyring-storage.py54
-rw-r--r--tests/twisted/account-storage/storage_helper.py149
5 files changed, 213 insertions, 54 deletions
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 587d6b0c..1f7dd21c 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -75,7 +75,10 @@ TWISTED_BASIC_TESTS = \
TWISTED_SPECIAL_BUILD_TESTS = \
account-manager/connectivity.py \
account-storage/default-keyring-storage.py \
- account-storage/diverted-storage.py
+ account-storage/diverted-storage.py \
+ account-storage/5-12.py \
+ account-storage/5-14.py \
+ $(NULL)
# Tests that are usually too slow to run.
TWISTED_SLOW_TESTS = \
@@ -105,6 +108,7 @@ TWISTED_OTHER_FILES = \
fakeconnectivity.py \
mctest.py \
servicetest.py \
+ account-storage/storage_helper.py \
telepathy/clients/README \
telepathy/clients/AbiWord.client \
telepathy/clients/Logger.client \
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/default-keyring-storage.py b/tests/twisted/account-storage/default-keyring-storage.py
index 27b45e51..2281387f 100644
--- a/tests/twisted/account-storage/default-keyring-storage.py
+++ b/tests/twisted/account-storage/default-keyring-storage.py
@@ -32,32 +32,9 @@ from mctest import (
exec_test, create_fakecm_account, get_fakecm_account, connect_to_mc,
keyfile_read, tell_mc_to_die, resuscitate_mc
)
+from storage_helper import (account_store)
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')
@@ -279,35 +256,6 @@ def test(q, bus, mc):
pwd = account_store('get', 'variant-file', 'param-password')
assertEquals(None, pwd)
- # Write out an account configuration in the old keyfile, to test
- # migration from there
- os.remove(new_variant_file_name)
- os.remove(new_variant_file_name.replace('.account', 'masked.account'))
- os.remove(new_variant_file_name.replace('.account', 'priority.account'))
- os.remove(low_prio_variant_file_name)
- os.remove(low_prio_variant_file_name.replace('.account', 'masked.account'))
- os.remove(low_prio_variant_file_name.replace('.account', 'priority.account'))
- 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 deleted automatically during MC startup,
- # after copying its contents to the new name/format
- assert not os.path.exists(old_key_file_name)
- assert not os.path.exists(low_prio_variant_file_name)
- assertEquals("'Ye olde account'",
- account_store('get', 'variant-file', 'DisplayName'))
-
if __name__ == '__main__':
ctl_dir = os.environ['MC_ACCOUNT_DIR']
try:
diff --git a/tests/twisted/account-storage/storage_helper.py b/tests/twisted/account-storage/storage_helper.py
new file mode 100644
index 00000000..42bfcf1e
--- /dev/null
+++ b/tests/twisted/account-storage/storage_helper.py
@@ -0,0 +1,149 @@
+# 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
+
+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')
+ 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')
+ 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;;
+
+[%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))
+ # MC doesn't currently ensure that parameters are stored with their
+ # proper types.
+ assertEquals("keyfile-escaped 'dontdivert1@example.com'",
+ account_store('get', 'variant-file', 'param-account',
+ account=a1_tail))
+ assertEquals("keyfile-escaped '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'))
+
+ 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'])