Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Add config option for sasl_ir #294

Merged
merged 1 commit into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/net/imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ def starttls(**options)
end

# :call-seq:
# authenticate(mechanism, *, sasl_ir: true, registry: Net::IMAP::SASL.authenticators, **, &) -> ok_resp
# authenticate(mechanism, *, sasl_ir: config.sasl_ir, registry: Net::IMAP::SASL.authenticators, **, &) -> ok_resp
#
# Sends an {AUTHENTICATE command [IMAP4rev1 §6.2.2]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.2.2]
# to authenticate the client. If successful, the connection enters the
Expand Down Expand Up @@ -1317,7 +1317,9 @@ def starttls(**options)
# Previously cached #capabilities will be cleared when this method
# completes. If the TaggedResponse to #authenticate includes updated
# capabilities, they will be cached.
def authenticate(mechanism, *creds, sasl_ir: true, **props, &callback)
def authenticate(mechanism, *creds,
sasl_ir: config.sasl_ir,
**props, &callback)
mechanism = mechanism.to_s.tr("_", "-").upcase
authenticator = SASL.authenticator(mechanism, *creds, **props, &callback)
cmdargs = ["AUTHENTICATE", mechanism]
Expand Down
11 changes: 11 additions & 0 deletions lib/net/imap/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ def self.[](config) # :nodoc: unfinished API
# The default value is +5+ seconds.
attr_accessor :idle_response_timeout, type: Integer

# :markup: markdown
#
# Whether to use the +SASL-IR+ extension with IMAP#authenticate.
#
# | Starting with version | The default value is |
# |-----------------------|------------------------------------------|
# | _original_ | +false+ <em>(extension unsupported)</em> |
# | v0.4 | +true+ <em>(support added)</em> |
attr_accessor :sasl_ir, type: :boolean

# Creates a new config object and initialize its attribute with +attrs+.
#
# If +parent+ is not given, the global config is used by default.
Expand All @@ -119,6 +129,7 @@ def initialize(parent = Config.global, **attrs)
debug: false,
open_timeout: 30,
idle_response_timeout: 5,
sasl_ir: true,
).freeze

@global = default.new
Expand Down
17 changes: 17 additions & 0 deletions test/net/imap/test_imap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,23 @@ def test_id
end
end

test("#authenticate never sends an initial response " \
"when config.sasl_ir: false") do
[true, false].each do |server_support|
with_fake_server(
preauth: false, cleartext_auth: true, sasl_ir: server_support
) do |server, imap|
imap.config.sasl_ir = false
imap.authenticate("PLAIN", "test_user", "test-password")
cmd, cont = 2.times.map { server.commands.pop }
assert_equal %w[AUTHENTICATE PLAIN], [cmd.name, *cmd.args]
assert_equal(["\x00test_user\x00test-password"].pack("m0"),
cont[:continuation].strip)
assert_empty server.commands
end
end
end

test("#authenticate never sends an initial response " \
"when the mechanism does not support client-first") do
with_fake_server(
Expand Down