D-Bus test: interactive password request in local sync

The child in a local sync asks its parent for a password,
which in turn has to use the normal password request mechanism
on that side. Added this test because the code refactoring
of ConfigUserInterface->UserInterface broke that without
causing test failures... this test caught that problem.
This commit is contained in:
Patrick Ohly 2012-03-08 15:06:09 +00:00
parent bd2eb7387f
commit 7d7f5a81e4
2 changed files with 55 additions and 4 deletions

View File

@ -2971,11 +2971,15 @@ SyncMLStatus SyncContext::sync(SyncReport *report)
*/
ConfigPropertyRegistry& registry = SyncConfig::getRegistry();
BOOST_FOREACH(const ConfigProperty *prop, registry) {
SE_LOG_DEBUG(NULL, NULL, "checking sync password %s", prop->getMainName().c_str());
prop->checkPassword(getUserInterfaceNonNull(), m_server, *getProperties());
}
BOOST_FOREACH(SyncSource *source, sourceList) {
ConfigPropertyRegistry& registry = SyncSourceConfig::getRegistry();
BOOST_FOREACH(const ConfigProperty *prop, registry) {
SE_LOG_DEBUG(NULL, NULL, "checking source %s password %s",
source->getName().c_str(),
prop->getMainName().c_str());
prop->checkPassword(getUserInterfaceNonNull(), m_server, *getProperties(),
source->getName(), source->getProperties());
}

View File

@ -3080,14 +3080,20 @@ class TestLocalSync(unittest.TestCase, DBusUtil):
def setUp(self):
self.setUpServer()
def setUpConfigs(self, childPassword=None):
# create file<->file configs
self.setUpSession("target-config@client")
addressbook = { "sync": "two-way",
"backend": "file",
"databaseFormat": "text/vcard",
"database": "file://" + xdg_root + "/client" }
if childPassword:
addressbook["databaseUser"] = "foo-user"
addressbook["databasePassword"] = childPassword
self.session.SetConfig(False, False,
{"" : { "loglevel": "4" },
"source/addressbook": { "sync": "two-way",
"backend": "file",
"databaseFormat": "text/vcard",
"database": "file://" + xdg_root + "/client" } })
"source/addressbook": addressbook })
self.session.Detach()
self.setUpSession("server")
self.session.SetConfig(False, False,
@ -3104,6 +3110,7 @@ class TestLocalSync(unittest.TestCase, DBusUtil):
@timeout(100)
def testSync(self):
"""TestLocalSync.testSync - run a simple slow sync between local dirs"""
self.setUpConfigs()
os.makedirs(xdg_root + "/server")
output = open(xdg_root + "/server/0", "w")
output.write('''BEGIN:VCARD
@ -3120,10 +3127,50 @@ END:VCARD''')
input = open(xdg_root + "/server/0", "r")
self.assertTrue("FN:John Doe" in input.read())
@timeout(100)
def testPasswordRequest(self):
"""TestLocalSync.testPassswordRequest - check that password request child->parent->us works"""
self.setUpConfigs(childPassword="-")
self.setUpListeners(self.sessionpath)
self.lastState = "unknown"
def infoRequest(id, session, state, handler, type, params):
if state == "request":
self.assertEqual(self.lastState, "unknown")
self.lastState = "request"
self.server.InfoResponse(id, "working", {}, utf8_strings=True)
elif state == "waiting":
self.assertEqual(self.lastState, "request")
self.lastState = "waiting"
self.server.InfoResponse(id, "response", {"password" : "123456"}, utf8_strings=True)
elif state == "done":
self.assertEqual(self.lastState, "waiting")
self.lastState = "done"
else:
self.fail("state should not be '" + state + "'")
signal = bus.add_signal_receiver(infoRequest,
'InfoRequest',
'org.syncevolution.Server',
self.server.bus_name,
None,
byte_arrays=True,
utf8_strings=True)
try:
self.session.Sync("slow", {})
loop.run()
finally:
signal.remove()
self.assertEqual(DBusUtil.quit_events, ["session " + self.sessionpath + " done"])
self.assertEqual(self.lastState, "done")
self.checkSync()
@property("ENV", "SYNCEVOLUTION_LOCAL_CHILD_DELAY=5")
@timeout(100)
def testConcurrency(self):
"""TestLocalSync.testConcurrency - D-Bus server must remain responsive while sync runs"""
self.setUpConfigs()
self.setUpListeners(self.sessionpath)
self.session.Sync("slow", {})
time.sleep(2)