diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-09-13 13:21:45 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-10-31 14:45:45 +0000 |
commit | f57ad64d19ff9002e0820678b3aca472a02c2270 (patch) | |
tree | db2365fef0f902c9fecd2b64147a54188ccda066 /tests | |
parent | f9722e84786bf00137b980948eb83539e94f3945 (diff) |
Test some new corner cases in the default account storage backend
Now that we can load individual accounts from any of several directories,
we should test that precedence and deletion behave correctly.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54875
Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/twisted/account-storage/default-keyring-storage.py | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/tests/twisted/account-storage/default-keyring-storage.py b/tests/twisted/account-storage/default-keyring-storage.py index c67399ed..58ef1089 100644 --- a/tests/twisted/account-storage/default-keyring-storage.py +++ b/tests/twisted/account-storage/default-keyring-storage.py @@ -27,7 +27,7 @@ import dbus import dbus.service from servicetest import EventPattern, tp_name_prefix, tp_path_prefix, \ - call_async, assertEquals + call_async, assertEquals, assertContains, assertDoesNotContain from mctest import ( exec_test, create_fakecm_account, get_fakecm_account, connect_to_mc, keyfile_read, tell_mc_to_die, resuscitate_mc @@ -180,7 +180,45 @@ def test(q, bus, mc): } """) + # This version of this account will be used + open(new_variant_file_name.replace('.account', 'priority.account'), + 'w').write("""{ +'manager': <'fakecm'>, +'protocol': <'fakeprotocol'>, +'DisplayName': <'Visible'>, +'AutomaticPresence': <'2;available;;'>, +'KeyFileParameters': <{'account': 'dontdivert@example.com', + 'password': 'password_in_variant_file'}> +} +""") + # This one won't, because it's "masked" by the higher-priority one + open(low_prio_variant_file_name.replace('.account', 'priority.account'), + 'w').write("""{ +'manager': <'fakecm'>, +'protocol': <'fakeprotocol'>, +'DisplayName': <'Hidden'>, +'Nickname': <'Hidden'>, +'AutomaticPresence': <'2;available;;'>, +'KeyFileParameters': <{'account': 'dontdivert@example.com', + 'password': 'password_in_variant_file'}> +} +""") + + # This empty file is considered to "mask" the lower-priority one + open(new_variant_file_name.replace('.account', 'masked.account'), + 'w').write('') + open(low_prio_variant_file_name.replace('.account', 'masked.account'), + 'w').write("""{ +'manager': <'fakecm'>, +'protocol': <'fakeprotocol'>, +'AutomaticPresence': <'2;available;;'>, +'KeyFileParameters': <{'account': 'dontdivert@example.com', + 'password': 'password_in_variant_file'}> +} +""") + account_manager, properties, interfaces = resuscitate_mc(q, bus, mc) + assertContains(account_path, properties['ValidAccounts']) account = get_fakecm_account(bus, mc, account_path) account_iface = dbus.Interface(account, cs.ACCOUNT) @@ -199,6 +237,22 @@ def test(q, bus, mc): 'Parameters' in e.args[0]), ) + # test that "masking" works + assertDoesNotContain(account_path + "masked", properties['ValidAccounts']) + assertDoesNotContain(account_path + "masked", + properties['InvalidAccounts']) + + # test that priority works + assertContains(account_path + "priority", properties['ValidAccounts']) + priority_account = get_fakecm_account(bus, mc, account_path + "priority") + assertEquals('', priority_account.Properties.Get(cs.ACCOUNT, 'Nickname')) + assertEquals('Visible', + priority_account.Properties.Get(cs.ACCOUNT, 'DisplayName')) + + # test what happens when we delete an account that has a lower-priority + # "other self" + assert priority_account.Remove() is None + # Tell MC to die yet again tell_mc_to_die(q, bus) @@ -208,13 +262,22 @@ def test(q, bus, mc): assert not os.path.exists(newer_key_file_name) assert os.path.exists(low_prio_variant_file_name) assert os.path.exists(new_variant_file_name) + assert open(new_variant_file_name.replace('.account', 'masked.account'), + 'r').read() == '' + assert open(new_variant_file_name.replace('.account', 'priority.account'), + 'r').read() == '' + 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] |