summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2014-01-28 16:34:18 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2014-01-29 19:28:34 +0000
commit775c27341c109cc4067df733ceec6c7728e9c6dd (patch)
tree440aef6a3277a83cea3bdbdc75dbc11f4b05cc6b
parent08ade738693e685d7de271792f605ebbc8af03df (diff)
Test that we add types to accounts' parameters when set
-rw-r--r--tests/twisted/account-storage/load-keyfiles.py78
1 files changed, 75 insertions, 3 deletions
diff --git a/tests/twisted/account-storage/load-keyfiles.py b/tests/twisted/account-storage/load-keyfiles.py
index 1f4cd986..dfba53b4 100644
--- a/tests/twisted/account-storage/load-keyfiles.py
+++ b/tests/twisted/account-storage/load-keyfiles.py
@@ -32,6 +32,9 @@ 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):
@@ -43,7 +46,7 @@ def test(q, bus, mc):
'telepathy', 'mission-control', 'accounts.cfg')
# We do several scenarios in one MC run, to speed up testing a bit.
- scenarios = ('low', 'priority', 'masked')
+ scenarios = ('low', 'priority', 'masked', 'migration', 'absentcm')
variant_file_names = {}
low_prio_variant_file_names = {}
@@ -90,6 +93,39 @@ def test(q, bus, mc):
}
""")
+ # 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'>,
@@ -135,10 +171,13 @@ def test(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'])
+ assertDoesNotContain(account_paths[s], properties['InvalidAccounts'])
accounts = {}
account_ifaces = {}
@@ -148,6 +187,9 @@ def test(q, bus, mc):
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,
@@ -198,5 +240,35 @@ def test(q, bus, mc):
# The masked account is still masked
assert open(variant_file_names['masked'], 'r').read() == ''
+ # Teach the one that knows its CM that the 'password' is a string.
+ # This results in the higher-priority file being written out.
+ 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]),
+ )
+ # Check the account has copied (not moved! XDG_DATA_DIRS are,
+ # conceptually, read-only) 'migration' 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['migration'])
+ assert os.path.exists(variant_file_names['migration'])
+ assertEquals("'hello'", account_store('get', 'variant-file',
+ 'param-password', account=tails['migration']))
+ # Parameters whose types are still unknown are copied too, but their
+ # types are still unknown
+ assertEquals("keyfile-escaped '42'", account_store('get', 'variant-file',
+ 'param-snakes', account=tails['migration']))
+
+ # 'absentcm' is still only in the low-priority location: we can't
+ # known the types of its parameters
+ 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)