[Pkg-telepathy-commits] [telepathy-mission-control-6] 228/280: Add dedicated tests for keyfile-based storage

Simon McVittie smcv at debian.org
Thu Mar 27 20:07:27 UTC 2014


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian
in repository telepathy-mission-control-6.

commit 1beafc65f2125df00f89a8e47c7ac67a7be9fb9b
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Mon Jan 27 20:16:21 2014 +0000

    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.
---
 tests/twisted/Makefile.am                          |   6 +-
 tests/twisted/account-storage/5-12.py              |  29 ++++
 tests/twisted/account-storage/5-14.py              |  29 ++++
 .../account-storage/default-keyring-storage.py     |  54 +-------
 tests/twisted/account-storage/storage_helper.py    | 149 +++++++++++++++++++++
 5 files changed, 213 insertions(+), 54 deletions(-)

diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index 587d6b0..1f7dd21 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 0000000..9075d76
--- /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 0000000..42deb3e
--- /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 27b45e5..2281387 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 at 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 0000000..42bfcf1
--- /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 at example.com
+param-password=1
+DisplayName=First among equals
+AutomaticPresence=2;available;;
+
+[%s]
+manager=fakecm
+protocol=fakeprotocol
+param-account=dontdivert2 at 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 at example.com'",
+            account_store('get', 'variant-file', 'param-account',
+                account=a1_tail))
+    assertEquals("keyfile-escaped 'dontdivert2 at 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 at 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 at 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'])

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/telepathy-mission-control-6.git



More information about the Pkg-telepathy-commits mailing list