Skip to content

Commit 9c8fbdb

Browse files
committed
🔥 Remove SASL.initial_response?, SASL.done?
Since they haven't been in any release yet, `SASL.initial_response?` and `SASL.done?` have been removed without deprecation. The logic has been moved directly into `Net::IMAP#authenticate` (for now). Implementing `#initial_response?` is still optional. But, to simplify the tests, `#initial_response? => false` was added to all of the deprecated SASL mechanisms.
1 parent 146ad37 commit 9c8fbdb

File tree

6 files changed

+12
-25
lines changed

6 files changed

+12
-25
lines changed

lib/net/imap.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,8 @@ def authenticate(mechanism, *creds, sasl_ir: true, **props, &callback)
12511251
authenticator = SASL.authenticator(mechanism, *creds, **props, &callback)
12521252
cmdargs = ["AUTHENTICATE", mechanism]
12531253
if sasl_ir && capable?("SASL-IR") && auth_capable?(mechanism) &&
1254-
SASL.initial_response?(authenticator)
1254+
authenticator.respond_to?(:initial_response?) &&
1255+
authenticator.initial_response?
12551256
response = authenticator.process(nil)
12561257
cmdargs << (response.empty? ? "=" : [response].pack("m0"))
12571258
end
@@ -1263,7 +1264,7 @@ def authenticate(mechanism, *creds, sasl_ir: true, **props, &callback)
12631264
put_string(response + CRLF)
12641265
end
12651266
end
1266-
unless SASL.done?(authenticator)
1267+
if authenticator.respond_to?(:done?) && !authenticator.done?
12671268
logout!
12681269
raise SASL::AuthenticationFailed, "authentication ended prematurely"
12691270
end

lib/net/imap/sasl.rb

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,6 @@ def saslprep(string, **opts)
158158
Net::IMAP::StringPrep::SASLprep.saslprep(string, **opts)
159159
end
160160

161-
# Returns whether +authenticator+ is client-first and supports sending an
162-
# "initial response".
163-
def initial_response?(authenticator)
164-
authenticator.respond_to?(:initial_response?) &&
165-
authenticator.initial_response?
166-
end
167-
168-
# Returns whether +authenticator+ considers the authentication exchange to
169-
# be complete.
170-
#
171-
# The authentication should not succeed if this returns false, but
172-
# returning true does *not* indicate success. Authentication succeeds
173-
# when this method returns true and the server responds with a
174-
# protocol-specific success.
175-
def done?(authenticator)
176-
!authenticator.respond_to?(:done?) || authenticator.done?
177-
end
178-
179161
end
180162
end
181163
end

lib/net/imap/sasl/cram_md5_authenticator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def initialize(user, password, warn_deprecation: true, **_ignored)
2424
@done = false
2525
end
2626

27+
def initial_response?; false end
28+
2729
def process(challenge)
2830
digest = hmac_md5(challenge, @password)
2931
return @user + " " + digest

lib/net/imap/sasl/digest_md5_authenticator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def initialize(user = nil, pass = nil, authz = nil,
7373
@nc, @stage = {}, STAGE_ONE
7474
end
7575

76+
def initial_response?; false end
77+
7678
# Responds to server challenge in two stages.
7779
def process(challenge)
7880
case @stage

lib/net/imap/sasl/login_authenticator.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def initialize(user, password, warn_deprecation: true, **_ignored)
3232
@state = STATE_USER
3333
end
3434

35+
def initial_response?; false end
36+
3537
def process(data)
3638
case @state
3739
when STATE_USER

test/net/imap/test_imap_authenticators.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def test_plain_authenticator_matches_mechanism
4141

4242
def test_plain_supports_initial_response
4343
assert plain("foo", "bar").initial_response?
44-
assert Net::IMAP::SASL.initial_response?(plain("foo", "bar"))
4544
end
4645

4746
def test_plain_response
@@ -194,7 +193,6 @@ def test_xoauth2_kwargs
194193

195194
def test_xoauth2_supports_initial_response
196195
assert xoauth2("foo", "bar").initial_response?
197-
assert Net::IMAP::SASL.initial_response?(xoauth2("foo", "bar"))
198196
end
199197

200198
# ----------------------
@@ -276,7 +274,7 @@ def test_login_authenticator_matches_mechanism
276274
end
277275

278276
def test_login_does_not_support_initial_response
279-
refute Net::IMAP::SASL.initial_response?(login("foo", "bar"))
277+
refute login("foo", "bar").initial_response?
280278
end
281279

282280
def test_login_authenticator_deprecated
@@ -306,7 +304,7 @@ def test_cram_md5_authenticator_matches_mechanism
306304
end
307305

308306
def test_cram_md5_does_not_support_initial_response
309-
refute Net::IMAP::SASL.initial_response?(cram_md5("foo", "bar"))
307+
refute cram_md5("foo", "bar").initial_response?
310308
end
311309

312310
def test_cram_md5_authenticator_deprecated
@@ -343,7 +341,7 @@ def test_digest_md5_authenticator_deprecated
343341
end
344342

345343
def test_digest_md5_does_not_support_initial_response
346-
refute Net::IMAP::SASL.initial_response?(digest_md5("foo", "bar"))
344+
refute digest_md5("foo", "bar").initial_response?
347345
end
348346

349347
def test_digest_md5_authenticator

0 commit comments

Comments
 (0)