Skip to content

Commit 0e38a11

Browse files
committed
♻️ SASL LOGIN: Add "#done?" [🚧 WIP]
The client should raise an error if the command completes successfully but "done?" returns false. also moved to sasl dir and SASL module. move login login
1 parent 5119bb4 commit 0e38a11

File tree

4 files changed

+65
-48
lines changed

4 files changed

+65
-48
lines changed

lib/net/imap/authenticators.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,6 @@ def authenticators
103103
require_relative "sasl/external_authenticator"
104104

105105
# deprecated
106-
require_relative "authenticators/login"
106+
require_relative "sasl/login_authenticator"
107107
require_relative "sasl/cram_md5_authenticator"
108108
require_relative "sasl/digest_md5_authenticator"

lib/net/imap/authenticators/login.rb

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# frozen_string_literal: true
2+
3+
module Net
4+
class IMAP < Protocol
5+
module SASL
6+
7+
# Authenticator for the "+LOGIN+" SASL mechanism. See Net::IMAP#authenticate.
8+
#
9+
# +LOGIN+ authentication sends the password in cleartext.
10+
# RFC3501[https://tools.ietf.org/html/rfc3501] encourages servers to disable
11+
# cleartext authentication until after TLS has been negotiated.
12+
# RFC8314[https://tools.ietf.org/html/rfc8314] recommends TLS version 1.2 or
13+
# greater be used for all traffic, and deprecate cleartext access ASAP. +LOGIN+
14+
# can be secured by TLS encryption.
15+
#
16+
# == Deprecated
17+
#
18+
# The {SASL mechanisms
19+
# registry}[https://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml]
20+
# marks "LOGIN" as obsoleted in favor of "PLAIN". It is included here for
21+
# compatibility with existing servers. See
22+
# {draft-murchison-sasl-login}[https://www.iana.org/go/draft-murchison-sasl-login]
23+
# for both specification and deprecation.
24+
class LoginAuthenticator
25+
def process(data)
26+
case @state
27+
when STATE_USER
28+
@state = STATE_PASSWORD
29+
@user
30+
when STATE_PASSWORD
31+
@state = STATE_DONE
32+
@password
33+
when STATE_DONE
34+
raise ResponseParseError, data
35+
end
36+
end
37+
38+
def done?; @state == STATE_DONE end
39+
40+
private
41+
42+
STATE_USER = :USER
43+
STATE_PASSWORD = :PASSWORD
44+
STATE_DONE = :DONE
45+
46+
def initialize(user, password, warn_deprecation: true, **_ignored)
47+
if warn_deprecation
48+
warn "WARNING: LOGIN SASL mechanism is deprecated. Use PLAIN instead."
49+
end
50+
@user = user
51+
@password = password
52+
@state = STATE_USER
53+
end
54+
55+
Net::IMAP.add_authenticator "LOGIN", self
56+
end
57+
end
58+
59+
LoginAuthenticator = SASL::LoginAuthenticator
60+
deprecate_constant :LoginAuthenticator
61+
62+
end
63+
end

test/net/imap/sasl/test_authenticators.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def login(*args, warn_deprecation: false, **kwargs, &block)
159159
end
160160

161161
def test_login_authenticator_matches_mechanism
162-
assert_kind_of(Net::IMAP::LoginAuthenticator, login("n", "p"))
162+
assert_kind_of(Net::IMAP::SASL::LoginAuthenticator, login("n", "p"))
163163
end
164164

165165
def test_login_authenticator_deprecated

0 commit comments

Comments
 (0)