diff --git a/plugins/Services/plugin.py b/plugins/Services/plugin.py index b96fcde2a..6926cd118 100644 --- a/plugins/Services/plugin.py +++ b/plugins/Services/plugin.py @@ -668,7 +668,12 @@ class Services(callbacks.Plugin): ) return - label = msg.server_tags["label"] + if "batch" in msg.server_tags: + # TODO: handle recursive batches + batch = irc.state.batches[msg.server_tags["batch"]] + label = batch.messages[0].server_tags["label"] + else: + label = msg.server_tags["label"] if label not in self._register: self.log.warning( "Got '%s' on %s, but I don't remember using " diff --git a/plugins/Services/test.py b/plugins/Services/test.py index d629395ad..a412f7516 100644 --- a/plugins/Services/test.py +++ b/plugins/Services/test.py @@ -149,6 +149,37 @@ class ExperimentalServicesTestCase(PluginTestCase): "", "Registration of account accountname on test succeeded: welcome!") + def testRegisterSuccessBatch(self): + # oragono replies with a batch + m = self.getMsg("register p4ssw0rd") + label = m.server_tags.pop("label") + self.assertEqual(m, IrcMsg(command="REGISTER", args=["*", "p4ssw0rd"])) + + batch_name = "Services_testRegisterSuccessBatch" + self.irc.feedMsg(IrcMsg( + server_tags={"label": label}, + command="BATCH", + args=["+" + batch_name, "labeled-response"] + )) + self.irc.feedMsg(IrcMsg( + server_tags={"batch": batch_name}, + command="REGISTER", + args=["SUCCESS", "accountname", "welcome!"] + )) + self.irc.feedMsg(IrcMsg( + server_tags={"batch": batch_name}, + command="NOTICE", + args=[self.irc.nick, "Registration succeeded blah blah blah"] + )) + self.irc.feedMsg(IrcMsg( + command="BATCH", + args=["-" + batch_name], + )) + + self.assertResponse( + "", + "Registration of account accountname on test succeeded: welcome!") + def testRegisterSuccessEmail(self): m = self.getMsg("register p4ssw0rd foo@example.org") label = m.server_tags.pop("label") @@ -190,6 +221,50 @@ class ExperimentalServicesTestCase(PluginTestCase): "", "Verification of account accountname on test succeeded: welcome!") + def testRegisterVerifyBatch(self): + m = self.getMsg("register p4ssw0rd") + label = m.server_tags.pop("label") + self.assertEqual(m, IrcMsg(command="REGISTER", args=["*", "p4ssw0rd"])) + self.irc.feedMsg(IrcMsg( + server_tags={"label": label}, + command="REGISTER", + args=["VERIFICATION_REQUIRED", "accountname", "check your emails"] + )) + self.assertResponse( + "", + "Registration of accountname on test requires verification " + "to complete: check your emails") + + m = self.getMsg("verify accountname c0de") + label = m.server_tags.pop("label") + self.assertEqual(m, IrcMsg( + command="VERIFY", args=["accountname", "c0de"])) + + batch_name = "Services_testVerifySuccessBatch" + self.irc.feedMsg(IrcMsg( + server_tags={"label": label}, + command="BATCH", + args=["+" + batch_name, "labeled-response"] + )) + self.irc.feedMsg(IrcMsg( + server_tags={"batch": batch_name}, + command="VERIFY", + args=["SUCCESS", "accountname", "welcome!"] + )) + self.irc.feedMsg(IrcMsg( + server_tags={"batch": batch_name}, + command="NOTICE", + args=[self.irc.nick, "Verification succeeded blah blah blah"] + )) + self.irc.feedMsg(IrcMsg( + command="BATCH", + args=["-" + batch_name], + )) + + self.assertResponse( + "", + "Verification of account accountname on test succeeded: welcome!") + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: