Skip to content

Commit

Permalink
Maintenance: Use Net::SMTP authenticator API for XOauth2 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
renovatebot authored and mantas committed Jan 19, 2024
1 parent c25c250 commit 5f8cb09
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -113,7 +113,6 @@ gem 'omniauth-weibo-oauth2', git: 'https://github.com/zammad-deps/omniauth-weibo
gem 'rack-attack'

# channels
gem 'gmail_xoauth'
gem 'koala'
gem 'telegram-bot-ruby'
gem 'twitter'
Expand Down
5 changes: 1 addition & 4 deletions Gemfile.lock
Expand Up @@ -261,8 +261,6 @@ GEM
gli (2.21.1)
globalid (1.2.1)
activesupport (>= 6.1)
gmail_xoauth (0.4.3)
oauth (>= 0.3.6)
graphql (2.2.5)
racc (~> 1.4)
graphql-batch (0.5.3)
Expand Down Expand Up @@ -360,7 +358,7 @@ GEM
net-protocol
net-protocol (0.2.2)
timeout
net-smtp (0.3.3)
net-smtp (0.4.0.1)
net-protocol
nio4r (2.5.9)
nkf (0.1.3)
Expand Down Expand Up @@ -749,7 +747,6 @@ DEPENDENCIES
execjs
factory_bot_rails
faker
gmail_xoauth
graphql
graphql-batch
hiredis
Expand Down
21 changes: 21 additions & 0 deletions lib/core_ext/net/smtp/auth_xoauth2.rb
@@ -0,0 +1,21 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require 'net/smtp'

class Net::SMTP
class AuthXoauth2 < Net::SMTP::Authenticator
auth_type :xoauth2

def auth(user, secret)
token = xoauth2_string(user, secret)

finish("AUTH XOAUTH2 #{base64_encode(token)}")
end

private

def xoauth2_string(user, secret)
"user=#{user}\1auth=Bearer #{secret}\1\1"
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/email_helper/probe_spec.rb
Expand Up @@ -146,7 +146,7 @@
let(:message_human) { [ 'This host cannot be reached.', 'There is no route to this host.' ] }

before do
allow(Socket).to receive(:tcp).and_raise(Errno::EHOSTUNREACH)
allow(TCPSocket).to receive(:open).and_raise(Errno::EHOSTUNREACH)
end

include_examples 'probe tests with invalid result'
Expand Down
2 changes: 2 additions & 0 deletions spec/support/imap.rb
@@ -1,5 +1,7 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

require 'net/imap'

module ImapHelper
def imap_delete_old_mails(options)
imap = ::Net::IMAP.new(options[:host], port: options[:port], ssl: (options[:ssl] ? { verify_mode: OpenSSL::SSL::VERIFY_NONE } : false))
Expand Down

0 comments on commit 5f8cb09

Please sign in to comment.