Services: Add support for batches as reply to REGISTER/VERIFY.

Oragono uses them.
This commit is contained in:
Valentin Lorentz 2021-01-25 22:00:51 +01:00
parent 1c6c1cb16a
commit c016ed5bfd
2 changed files with 81 additions and 1 deletions

View File

@ -668,6 +668,11 @@ class Services(callbacks.Plugin):
)
return
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(

View File

@ -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: