Skip to content

Commit e03f2be

Browse files
committed
Implement draft/sasl-ir
1 parent 477df0c commit e03f2be

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

lib/irc/handler.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ defmodule M51.IrcConn.Handler do
7575
# https://ircv3.net/specs/extensions/sasl-3.1
7676
"sasl" => {:sasl, "PLAIN"},
7777

78+
# https://github.com/ircv3/ircv3-specifications/pull/520
79+
"draft/sasl-ir" => {:sasl_ir, nil},
80+
7881
# https://ircv3.net/specs/extensions/server-time
7982
"server-time" => {:server_time, nil},
8083

@@ -400,10 +403,16 @@ defmodule M51.IrcConn.Handler do
400403

401404
nil
402405

403-
{"AUTHENTICATE", ["PLAIN" | _]} ->
406+
{"AUTHENTICATE", ["PLAIN"]} ->
404407
send.(%M51.Irc.Command{command: "AUTHENTICATE", params: ["+"]})
405408
nil
406409

410+
{"AUTHENTICATE", ["PLAIN" | params]} ->
411+
# SASL-IR: https://github.com/ircv3/ircv3-specifications/pull/520
412+
# Call this function recursively without the mechanism, to be handled
413+
# by the next case below
414+
handle_connreg(sup_pid, %{command | params: params}, nick)
415+
407416
{"AUTHENTICATE", [param | _]} ->
408417
# this catches both invalid mechs and actual PLAIN message.
409418
# FIXME: add some state to tell the two apart.

test/irc/handler_test.exs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ defmodule M51.IrcConn.HandlerTest do
1818
use ExUnit.Case, async: false
1919
doctest M51.IrcConn.Handler
2020

21-
@cap_ls_302 ":server. CAP * LS :account-tag batch draft/account-registration=before-connect draft/channel-rename draft/chathistory draft/multiline=max-bytes=8192 echo-message extended-join labeled-response message-tags sasl=PLAIN server-time soju.im/account-required standard-replies userhost-in-names\r\n"
22-
@cap_ls ":server. CAP * LS :account-tag batch draft/account-registration draft/channel-rename draft/chathistory draft/multiline echo-message extended-join labeled-response message-tags sasl server-time soju.im/account-required standard-replies userhost-in-names\r\n"
21+
@cap_ls_302 ":server. CAP * LS :account-tag batch draft/account-registration=before-connect draft/channel-rename draft/chathistory draft/multiline=max-bytes=8192 draft/sasl-ir echo-message extended-join labeled-response message-tags sasl=PLAIN server-time soju.im/account-required standard-replies userhost-in-names\r\n"
22+
@cap_ls ":server. CAP * LS :account-tag batch draft/account-registration draft/channel-rename draft/chathistory draft/multiline draft/sasl-ir echo-message extended-join labeled-response message-tags sasl server-time soju.im/account-required standard-replies userhost-in-names\r\n"
2323
@isupport "CASEMAPPING=rfc3454 CLIENTTAGDENY=*,-draft/react,-draft/reply CHANLIMIT= CHANTYPES=#! CHATHISTORY=1000 MAXTARGETS=1 MSGREFTYPES=msgid PREFIX= TARGMAX=JOIN:1,PART:1 UTF8ONLY :are supported by this server\r\n"
2424

2525
setup do
@@ -189,6 +189,33 @@ defmodule M51.IrcConn.HandlerTest do
189189
assert M51.IrcConn.State.gecos(state) == "My GECOS"
190190
end
191191

192+
test "Connection registration with SASL-IR", %{state: state, handler: handler} do
193+
send(handler, cmd("CAP LS 302"))
194+
assert_line(@cap_ls_302)
195+
196+
send(handler, cmd("CAP REQ sasl"))
197+
assert_line(":server. CAP * ACK :sasl\r\n")
198+
199+
send(handler, cmd("NICK foo:example.org"))
200+
send(handler, cmd("USER ident * * :My GECOS"))
201+
202+
# foo:example.org\x00foo:example.org\x00correct password
203+
send(handler, cmd("AUTHENTICATE PLAIN Zm9vOmV4YW1wbGUub3JnAGZvbzpleGFtcGxlLm9yZwBjb3JyZWN0IHBhc3N3b3Jk")
204+
)
205+
206+
assert_line(
207+
":server. 900 foo:example.org foo:[email protected] foo:example.org :You are now logged in as foo:example.org\r\n"
208+
)
209+
210+
assert_line(":server. 903 foo:example.org :Authentication successful\r\n")
211+
212+
send(handler, cmd("CAP END"))
213+
assert_welcome("foo:example.org")
214+
215+
assert M51.IrcConn.State.nick(state) == "foo:example.org"
216+
assert M51.IrcConn.State.gecos(state) == "My GECOS"
217+
end
218+
192219
test "Connection registration with AUTHENTICATE before NICK", %{state: state, handler: handler} do
193220
send(handler, cmd("CAP LS 302"))
194221
assert_line(@cap_ls_302)

0 commit comments

Comments
 (0)