gitlab-mail_room 0.0.24 → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -2
- data/.gitlab-ci.yml +3 -4
- data/.rubocop_todo.yml +0 -5
- data/.ruby-version +1 -1
- data/.tool-versions +1 -0
- data/CHANGELOG.md +8 -0
- data/README.md +0 -10
- data/lib/mail_room/arbitration/redis.rb +6 -2
- data/lib/mail_room/delivery/postback.rb +15 -4
- data/lib/mail_room/delivery/sidekiq.rb +6 -2
- data/lib/mail_room/version.rb +1 -1
- data/mail_room.gemspec +3 -3
- data/spec/lib/arbitration/redis_spec.rb +31 -20
- data/spec/lib/delivery/postback_spec.rb +79 -109
- data/spec/lib/delivery/sidekiq_spec.rb +36 -26
- data/spec/lib/health_check_spec.rb +3 -1
- metadata +9 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1acb9f27f253f776bd924c9dfa75228f964a37ec3364fd6a557f916da85c3af1
|
4
|
+
data.tar.gz: 9397eee73f27be29ca26296b8525d5bb689856d70d46fedf0844cf08b0b575b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d45ef4ad64a91e09f146c44673612aa7211ceebd2f42907db1d525b18d9bf64749b18e2277f1df0e79aceea5108ca5526a673e9c1a6a9a262a902eeb4d64dfda
|
7
|
+
data.tar.gz: 3ba5a0a5dfbd62c1cb5ba5c81d340c08ee075ccd86cbbaa22c675b2dd681537714f79cb5b317e60365a39cdc2e8230fff2d384d481392d056dcca81d0b941c0c
|
data/.github/workflows/ci.yml
CHANGED
@@ -31,7 +31,7 @@ jobs:
|
|
31
31
|
- '3.0'
|
32
32
|
- '2.7'
|
33
33
|
steps:
|
34
|
-
- uses: actions/checkout@
|
34
|
+
- uses: actions/checkout@v4
|
35
35
|
- name: Set up Ruby ${{ matrix.ruby-version }}
|
36
36
|
uses: ruby/setup-ruby@v1
|
37
37
|
with:
|
@@ -43,7 +43,7 @@ jobs:
|
|
43
43
|
rubocop:
|
44
44
|
runs-on: ubuntu-latest
|
45
45
|
steps:
|
46
|
-
- uses: actions/checkout@
|
46
|
+
- uses: actions/checkout@v4
|
47
47
|
- name: Set up Ruby ${{ matrix.ruby-version }}
|
48
48
|
uses: ruby/setup-ruby@v1
|
49
49
|
with:
|
data/.gitlab-ci.yml
CHANGED
@@ -10,11 +10,10 @@ services:
|
|
10
10
|
paths:
|
11
11
|
- vendor/ruby
|
12
12
|
variables:
|
13
|
-
REDIS_URL: redis://redis:6379
|
13
|
+
REDIS_URL: redis://redis:6379
|
14
14
|
before_script:
|
15
15
|
- apt update && apt install -y libicu-dev
|
16
16
|
- ruby -v # Print out ruby version for debugging
|
17
|
-
- gem install bundler --no-document # Bundler is not installed with the image
|
18
17
|
- bundle config set --local path 'vendor'
|
19
18
|
- bundle install -j $(nproc)
|
20
19
|
script:
|
@@ -23,8 +22,8 @@ services:
|
|
23
22
|
rspec:
|
24
23
|
parallel:
|
25
24
|
matrix:
|
26
|
-
- RUBY_VERSION: [ "
|
25
|
+
- RUBY_VERSION: [ "3.0", "3.1", "3.2", "3.3", "3.4" ]
|
27
26
|
<<: *test
|
28
27
|
|
29
28
|
include:
|
30
|
-
- template: Security/Dependency-Scanning.gitlab-ci.yml
|
29
|
+
- template: Security/Dependency-Scanning.gitlab-ci.yml
|
data/.rubocop_todo.yml
CHANGED
@@ -25,7 +25,6 @@ Gemspec/RequiredRubyVersion:
|
|
25
25
|
# This cop supports safe autocorrection (--autocorrect).
|
26
26
|
Layout/BlockEndNewline:
|
27
27
|
Exclude:
|
28
|
-
- 'spec/lib/delivery/postback_spec.rb'
|
29
28
|
- 'spec/lib/delivery/que_spec.rb'
|
30
29
|
|
31
30
|
# Offense count: 5
|
@@ -75,7 +74,6 @@ Layout/EmptyLinesAroundClassBody:
|
|
75
74
|
# SupportedStyles: special_inside_parentheses, consistent, align_braces
|
76
75
|
Layout/FirstHashElementIndentation:
|
77
76
|
Exclude:
|
78
|
-
- 'spec/lib/delivery/postback_spec.rb'
|
79
77
|
- 'spec/lib/delivery/que_spec.rb'
|
80
78
|
- 'spec/lib/logger/structured_spec.rb'
|
81
79
|
|
@@ -101,7 +99,6 @@ Layout/LeadingCommentSpace:
|
|
101
99
|
# This cop supports safe autocorrection (--autocorrect).
|
102
100
|
Layout/MultilineBlockLayout:
|
103
101
|
Exclude:
|
104
|
-
- 'spec/lib/delivery/postback_spec.rb'
|
105
102
|
- 'spec/lib/delivery/que_spec.rb'
|
106
103
|
|
107
104
|
# Offense count: 3
|
@@ -153,7 +150,6 @@ Layout/SpaceInsideBlockBraces:
|
|
153
150
|
- 'spec/lib/configuration_spec.rb'
|
154
151
|
- 'spec/lib/delivery/letter_opener_spec.rb'
|
155
152
|
- 'spec/lib/delivery/logger_spec.rb'
|
156
|
-
- 'spec/lib/delivery/postback_spec.rb'
|
157
153
|
- 'spec/lib/delivery/que_spec.rb'
|
158
154
|
- 'spec/lib/imap/connection_spec.rb'
|
159
155
|
- 'spec/lib/mailbox_watcher_spec.rb'
|
@@ -273,7 +269,6 @@ Style/Alias:
|
|
273
269
|
Style/BlockDelimiters:
|
274
270
|
Exclude:
|
275
271
|
- 'spec/lib/arbitration/redis_spec.rb'
|
276
|
-
- 'spec/lib/delivery/postback_spec.rb'
|
277
272
|
- 'spec/lib/delivery/que_spec.rb'
|
278
273
|
- 'spec/lib/delivery/sidekiq_spec.rb'
|
279
274
|
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2
|
1
|
+
3.2
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.4.1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## mail_room 0.11.1 ##
|
2
|
+
|
3
|
+
https://github.com/tpitale/mail_room/compare/v0.11.0...v0.11.1
|
4
|
+
|
5
|
+
## mail_room 0.11.0 ##
|
6
|
+
|
7
|
+
https://github.com/tpitale/mail_room/compare/v0.10.1...v0.11.0
|
8
|
+
|
1
9
|
## mail_room 0.10.1 ##
|
2
10
|
|
3
11
|
* Fix db attribute on redis URL PR#130 - @jarkaK
|
data/README.md
CHANGED
@@ -489,13 +489,3 @@ respectively and MailRoom will log there.
|
|
489
489
|
4. Push to the branch (`git push origin my-new-feature`)
|
490
490
|
5. Create new Pull Request
|
491
491
|
6. If accepted, ask for commit rights
|
492
|
-
|
493
|
-
## TODO ##
|
494
|
-
|
495
|
-
1. specs, this is just a (working) proof of concept √
|
496
|
-
2. finish code for POSTing to callback with auth √
|
497
|
-
3. accept mailbox configuration for one account directly on the commandline; or ask for it
|
498
|
-
4. add example rails endpoint, with auth examples
|
499
|
-
5. add example configs for upstart/init.d √
|
500
|
-
6. log to stdout √
|
501
|
-
7. add a development mode that opens in letter_opener by ryanb √
|
@@ -3,11 +3,13 @@ require "redis"
|
|
3
3
|
module MailRoom
|
4
4
|
module Arbitration
|
5
5
|
class Redis
|
6
|
-
Options = Struct.new(:redis_url, :namespace, :sentinels) do
|
6
|
+
Options = Struct.new(:redis_url, :namespace, :sentinels, :sentinel_username, :sentinel_password) do
|
7
7
|
def initialize(mailbox)
|
8
8
|
redis_url = mailbox.arbitration_options[:redis_url] || "redis://localhost:6379"
|
9
9
|
namespace = mailbox.arbitration_options[:namespace]
|
10
10
|
sentinels = mailbox.arbitration_options[:sentinels]
|
11
|
+
sentinel_username = mailbox.arbitration_options[:sentinel_username]
|
12
|
+
sentinel_password = mailbox.arbitration_options[:sentinel_password]
|
11
13
|
|
12
14
|
if namespace
|
13
15
|
warn <<~MSG
|
@@ -16,7 +18,7 @@ module MailRoom
|
|
16
18
|
MSG
|
17
19
|
end
|
18
20
|
|
19
|
-
super(redis_url, namespace, sentinels)
|
21
|
+
super(redis_url, namespace, sentinels, sentinel_username, sentinel_password)
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
@@ -48,6 +50,8 @@ module MailRoom
|
|
48
50
|
sentinels = options.sentinels
|
49
51
|
redis_options = { url: options.redis_url }
|
50
52
|
redis_options[:sentinels] = sentinels if sentinels
|
53
|
+
redis_options[:sentinel_username] = options.sentinel_username if options.sentinel_username
|
54
|
+
redis_options[:sentinel_password] = options.sentinel_password if options.sentinel_password
|
51
55
|
|
52
56
|
redis = ::Redis.new(redis_options)
|
53
57
|
|
@@ -61,7 +61,6 @@ module MailRoom
|
|
61
61
|
# Build a new delivery, hold the delivery options
|
62
62
|
# @param [MailRoom::Delivery::Postback::Options]
|
63
63
|
def initialize(delivery_options)
|
64
|
-
puts delivery_options
|
65
64
|
@delivery_options = delivery_options
|
66
65
|
end
|
67
66
|
|
@@ -71,19 +70,19 @@ module MailRoom
|
|
71
70
|
connection = Faraday.new
|
72
71
|
|
73
72
|
if @delivery_options.token_auth?
|
74
|
-
connection
|
73
|
+
config_token_auth(connection)
|
75
74
|
elsif @delivery_options.basic_auth?
|
76
75
|
config_basic_auth(connection)
|
77
76
|
end
|
78
77
|
|
79
|
-
connection.post do |request|
|
78
|
+
result = connection.post do |request|
|
80
79
|
request.url @delivery_options.url
|
81
80
|
request.body = message
|
82
81
|
config_request_content_type(request)
|
83
82
|
config_request_jwt_auth(request)
|
84
83
|
end
|
85
84
|
|
86
|
-
@delivery_options.logger.info({ delivery_method: 'Postback', action: 'message pushed', url: @delivery_options.url })
|
85
|
+
@delivery_options.logger.info({ delivery_method: 'Postback', action: 'message pushed', url: @delivery_options.url, status_code: result.status })
|
87
86
|
true
|
88
87
|
end
|
89
88
|
|
@@ -101,6 +100,18 @@ module MailRoom
|
|
101
100
|
request.headers[@delivery_options.jwt.header] = @delivery_options.jwt.token
|
102
101
|
end
|
103
102
|
|
103
|
+
def config_token_auth(connection)
|
104
|
+
# connection.token_auth was removed in Faraday v2 in favor of connection.request(:authorization, 'Token', token)
|
105
|
+
if defined?(connection.token_auth)
|
106
|
+
connection.token_auth @delivery_options.token
|
107
|
+
else
|
108
|
+
connection.request(
|
109
|
+
:authorization, 'Token',
|
110
|
+
@delivery_options.token
|
111
|
+
)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
104
115
|
def config_basic_auth(connection)
|
105
116
|
if defined?(connection.basic_auth)
|
106
117
|
connection.basic_auth(
|
@@ -8,12 +8,14 @@ module MailRoom
|
|
8
8
|
# Sidekiq Delivery method
|
9
9
|
# @author Douwe Maan
|
10
10
|
class Sidekiq
|
11
|
-
Options = Struct.new(:redis_url, :namespace, :sentinels, :queue, :worker, :logger, :redis_db) do
|
11
|
+
Options = Struct.new(:redis_url, :namespace, :sentinels, :queue, :worker, :logger, :redis_db, :sentinel_username, :sentinel_password) do
|
12
12
|
def initialize(mailbox)
|
13
13
|
redis_url = mailbox.delivery_options[:redis_url] || "redis://localhost:6379"
|
14
14
|
redis_db = mailbox.delivery_options[:redis_db] || 0
|
15
15
|
namespace = mailbox.delivery_options[:namespace]
|
16
16
|
sentinels = mailbox.delivery_options[:sentinels]
|
17
|
+
sentinel_username = mailbox.delivery_options[:sentinel_username]
|
18
|
+
sentinel_password = mailbox.delivery_options[:sentinel_password]
|
17
19
|
queue = mailbox.delivery_options[:queue] || "default"
|
18
20
|
worker = mailbox.delivery_options[:worker]
|
19
21
|
logger = mailbox.logger
|
@@ -25,7 +27,7 @@ module MailRoom
|
|
25
27
|
MSG
|
26
28
|
end
|
27
29
|
|
28
|
-
super(redis_url, namespace, sentinels, queue, worker, logger, redis_db)
|
30
|
+
super(redis_url, namespace, sentinels, queue, worker, logger, redis_db, sentinel_username, sentinel_password)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -55,6 +57,8 @@ module MailRoom
|
|
55
57
|
sentinels = options.sentinels
|
56
58
|
redis_options = { url: options.redis_url, db: options.redis_db }
|
57
59
|
redis_options[:sentinels] = sentinels if sentinels
|
60
|
+
redis_options[:sentinel_username] = options.sentinel_username if options.sentinel_username
|
61
|
+
redis_options[:sentinel_password] = options.sentinel_password if options.sentinel_password
|
58
62
|
|
59
63
|
redis = ::Redis.new(redis_options)
|
60
64
|
|
data/lib/mail_room/version.rb
CHANGED
data/mail_room.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ["tpitale@gmail.com"]
|
11
11
|
gem.description = %q{mail_room will proxy email (gmail) from IMAP to a delivery method}
|
12
12
|
gem.summary = %q{mail_room will proxy email (gmail) from IMAP to a callback URL, logger, or letter_opener}
|
13
|
-
gem.homepage = "
|
13
|
+
gem.homepage = "https://gitlab.com/gitlab-org/ruby/gems/gitlab-mail_room"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -20,13 +20,13 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_dependency "net-imap", ">= 0.2.1"
|
21
21
|
gem.add_dependency "oauth2", [">= 1.4.4", "< 3"]
|
22
22
|
gem.add_dependency "jwt", ">= 2.0"
|
23
|
-
gem.add_dependency "redis", [">=
|
23
|
+
gem.add_dependency "redis", [">= 5", "< 6"]
|
24
24
|
gem.add_dependency "redis-namespace", '>= 1.8.2'
|
25
25
|
|
26
26
|
gem.add_development_dependency "rake"
|
27
27
|
gem.add_development_dependency "rspec", "~> 3.9"
|
28
28
|
gem.add_development_dependency "rubocop", "~> 1.11"
|
29
|
-
gem.add_development_dependency "mocha", "~>
|
29
|
+
gem.add_development_dependency "mocha", "~> 2.0"
|
30
30
|
gem.add_development_dependency "simplecov"
|
31
31
|
gem.add_development_dependency "webrick", "~> 1.6"
|
32
32
|
|
@@ -11,21 +11,12 @@ describe MailRoom::Arbitration::Redis do
|
|
11
11
|
)
|
12
12
|
}
|
13
13
|
let(:options) { described_class::Options.new(mailbox) }
|
14
|
-
let(:redis5) { Gem::Version.new(Redis::VERSION) >= Gem::Version.new('5.0') }
|
15
14
|
subject { described_class.new(options) }
|
16
15
|
|
17
16
|
# Private, but we don't care.
|
18
17
|
let(:redis) { subject.send(:client) }
|
19
18
|
let(:raw_client) { redis._client }
|
20
19
|
|
21
|
-
let(:server_url) do
|
22
|
-
if redis5
|
23
|
-
raw_client.config.server_url
|
24
|
-
else
|
25
|
-
raw_client.options[:url]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
20
|
describe '#deliver?' do
|
30
21
|
context "when called the first time" do
|
31
22
|
after do
|
@@ -89,7 +80,7 @@ describe MailRoom::Arbitration::Redis do
|
|
89
80
|
|
90
81
|
context 'redis client connection params' do
|
91
82
|
context 'when only url is present' do
|
92
|
-
let(:redis_url) { ENV.fetch('REDIS_URL', 'redis://localhost:6379
|
83
|
+
let(:redis_url) { ENV.fetch('REDIS_URL', 'redis://localhost:6379') }
|
93
84
|
let(:mailbox) {
|
94
85
|
build_mailbox(
|
95
86
|
arbitration_options: {
|
@@ -105,7 +96,7 @@ describe MailRoom::Arbitration::Redis do
|
|
105
96
|
it 'client has same specified url' do
|
106
97
|
subject.deliver?(123)
|
107
98
|
|
108
|
-
expect(server_url).to eq redis_url
|
99
|
+
expect(raw_client.config.server_url).to eq redis_url
|
109
100
|
end
|
110
101
|
|
111
102
|
it 'client is a instance of Redis class' do
|
@@ -144,17 +135,37 @@ describe MailRoom::Arbitration::Redis do
|
|
144
135
|
)
|
145
136
|
}
|
146
137
|
|
138
|
+
before { ::RedisClient::SentinelConfig.any_instance.stubs(:resolve_master).returns(RedisClient::Config.new(**sentinels.first)) }
|
139
|
+
|
147
140
|
it 'client has same specified sentinel params' do
|
148
|
-
|
141
|
+
expect(raw_client.config).to be_a RedisClient::SentinelConfig
|
142
|
+
expect(raw_client.config.name).to eq('sentinel-master')
|
143
|
+
expect(raw_client.config.host).to eq('10.0.0.1')
|
144
|
+
expect(raw_client.config.password).to eq('mypassword')
|
145
|
+
expect(raw_client.config.sentinels.map(&:server_url)).to eq(["redis://10.0.0.1:26379"])
|
146
|
+
end
|
147
|
+
|
148
|
+
context 'with separate Sentinel username and password' do
|
149
|
+
let(:sentinel_username) { 'my-sentinel-user' }
|
150
|
+
let(:sentinel_password) { 'my-sentinel-pass' }
|
151
|
+
let(:mailbox) {
|
152
|
+
build_mailbox(
|
153
|
+
arbitration_options: {
|
154
|
+
redis_url: redis_url,
|
155
|
+
sentinels: sentinels,
|
156
|
+
sentinel_username: sentinel_username,
|
157
|
+
sentinel_password: sentinel_password
|
158
|
+
}
|
159
|
+
)
|
160
|
+
}
|
161
|
+
|
162
|
+
it 'client uses Sentinel username and password' do
|
163
|
+
expect(raw_client.config).to be_a RedisClient::SentinelConfig
|
149
164
|
expect(raw_client.config.password).to eq('mypassword')
|
150
|
-
|
151
|
-
|
152
|
-
expect(
|
153
|
-
expect(
|
154
|
-
else
|
155
|
-
expect(raw_client.options[:host]).to eq('sentinel-master')
|
156
|
-
expect(raw_client.options[:password]).to eq('mypassword')
|
157
|
-
expect(raw_client.options[:sentinels]).to eq(sentinels)
|
165
|
+
|
166
|
+
sentinels = raw_client.config.sentinels
|
167
|
+
expect(sentinels.map(&:username).uniq).to eq([sentinel_username])
|
168
|
+
expect(sentinels.map(&:password).uniq).to eq([sentinel_password])
|
158
169
|
end
|
159
170
|
end
|
160
171
|
end
|
@@ -1,138 +1,108 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'mail_room/delivery/postback'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'webmock/rspec'
|
3
5
|
|
4
6
|
describe MailRoom::Delivery::Postback do
|
5
7
|
describe '#deliver' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
delivery_token: 'abcdefg'
|
10
|
-
})}
|
8
|
+
let(:delivery_options) do
|
9
|
+
MailRoom::Delivery::Postback::Options.new(mailbox)
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
before do
|
13
|
+
stub_request(:post, 'http://localhost/inbox')
|
14
|
+
.with(body: 'a message', headers: headers)
|
15
|
+
.to_return(status: 201)
|
16
|
+
end
|
15
17
|
|
18
|
+
shared_examples 'message poster' do
|
16
19
|
it 'posts the message with faraday' do
|
17
|
-
connection = stub
|
18
|
-
request = stub
|
19
|
-
Faraday.stubs(:new).returns(connection)
|
20
|
-
|
21
|
-
connection.expects(:token_auth).with('abcdefg')
|
22
|
-
connection.expects(:post).yields(request)
|
23
|
-
|
24
|
-
request.expects(:url).with('http://localhost/inbox')
|
25
|
-
request.expects(:body=).with('a message')
|
26
|
-
|
27
20
|
MailRoom::Delivery::Postback.new(delivery_options).deliver('a message')
|
28
21
|
end
|
29
22
|
end
|
30
23
|
|
31
|
-
context 'with
|
32
|
-
let(:mailbox)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
})}
|
39
|
-
|
40
|
-
let(:delivery_options) {
|
41
|
-
MailRoom::Delivery::Postback::Options.new(mailbox)
|
42
|
-
}
|
43
|
-
|
44
|
-
it 'posts the message with faraday' do
|
45
|
-
connection = stub
|
46
|
-
request = stub
|
47
|
-
Faraday.stubs(:new).returns(connection)
|
24
|
+
context 'with token auth delivery' do
|
25
|
+
let(:mailbox) do
|
26
|
+
build_mailbox({
|
27
|
+
delivery_url: 'http://localhost/inbox',
|
28
|
+
delivery_token: 'abcdefg'
|
29
|
+
})
|
30
|
+
end
|
48
31
|
|
49
|
-
|
50
|
-
connection.expects(:post).yields(request)
|
32
|
+
let(:headers) { { 'Authorization' => 'Token abcdefg' } }
|
51
33
|
|
52
|
-
|
53
|
-
|
34
|
+
it_behaves_like 'message poster'
|
35
|
+
end
|
54
36
|
|
55
|
-
|
37
|
+
context 'with basic auth delivery options' do
|
38
|
+
let(:mailbox) do
|
39
|
+
build_mailbox({
|
40
|
+
delivery_options: {
|
41
|
+
url: 'http://localhost/inbox',
|
42
|
+
username: 'user1',
|
43
|
+
password: 'password123abc'
|
44
|
+
}
|
45
|
+
})
|
56
46
|
end
|
57
47
|
|
58
|
-
|
59
|
-
let(:mailbox) {build_mailbox({
|
60
|
-
delivery_options: {
|
61
|
-
url: 'http://localhost/inbox',
|
62
|
-
username: 'user1',
|
63
|
-
password: 'password123abc',
|
64
|
-
content_type: 'text/plain'
|
65
|
-
}
|
66
|
-
})}
|
67
|
-
|
68
|
-
let(:delivery_options) {
|
69
|
-
MailRoom::Delivery::Postback::Options.new(mailbox)
|
70
|
-
}
|
48
|
+
let(:headers) { { 'Authorization' => 'Basic dXNlcjE6cGFzc3dvcmQxMjNhYmM=' } }
|
71
49
|
|
72
|
-
|
73
|
-
connection = stub
|
74
|
-
request = stub
|
75
|
-
Faraday.stubs(:new).returns(connection)
|
50
|
+
it_behaves_like 'message poster'
|
76
51
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
52
|
+
context 'with content type in the delivery options' do
|
53
|
+
let(:mailbox) do
|
54
|
+
build_mailbox({
|
55
|
+
delivery_options: {
|
56
|
+
url: 'http://localhost/inbox',
|
57
|
+
username: 'user1',
|
58
|
+
password: 'password123abc',
|
59
|
+
content_type: 'text/plain'
|
60
|
+
}
|
61
|
+
})
|
62
|
+
end
|
84
63
|
|
85
|
-
|
64
|
+
let(:headers) do
|
65
|
+
{
|
66
|
+
'Authorization' => 'Basic dXNlcjE6cGFzc3dvcmQxMjNhYmM=',
|
67
|
+
'Content-Type' => 'text/plain'
|
68
|
+
}
|
86
69
|
end
|
70
|
+
|
71
|
+
it_behaves_like 'message poster'
|
87
72
|
end
|
88
73
|
|
89
74
|
context 'with jwt token in the delivery options' do
|
90
|
-
let(:mailbox)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
75
|
+
let(:mailbox) do
|
76
|
+
build_mailbox({
|
77
|
+
delivery_options: {
|
78
|
+
url: 'http://localhost/inbox',
|
79
|
+
jwt_auth_header: "Mailroom-Api-Request",
|
80
|
+
jwt_issuer: "mailroom",
|
81
|
+
jwt_algorithm: "HS256",
|
82
|
+
jwt_secret_path: jwt_secret.path,
|
83
|
+
content_type: 'application/json'
|
84
|
+
}
|
85
|
+
})
|
86
|
+
end
|
87
|
+
|
88
|
+
let(:headers) do
|
89
|
+
{
|
90
|
+
'Content-Type' => 'application/json',
|
91
|
+
'Mailroom-Api-Request' => /.*/
|
97
92
|
}
|
98
|
-
})}
|
99
|
-
|
100
|
-
let(:delivery_options) {
|
101
|
-
MailRoom::Delivery::Postback::Options.new(mailbox)
|
102
|
-
}
|
103
|
-
|
104
|
-
it 'posts the message with faraday' do
|
105
|
-
connection = stub
|
106
|
-
request = stub
|
107
|
-
Faraday.stubs(:new).returns(connection)
|
108
|
-
|
109
|
-
connection.expects(:post).yields(request).twice
|
110
|
-
request.stubs(:url)
|
111
|
-
request.stubs(:body=)
|
112
|
-
request.stubs(:headers).returns({})
|
113
|
-
|
114
|
-
jwt = stub
|
115
|
-
MailRoom::JWT.expects(:new).with(
|
116
|
-
header: 'Mailroom-Api-Request',
|
117
|
-
issuer: 'mailroom',
|
118
|
-
algorithm: 'HS256',
|
119
|
-
secret_path: 'secret_path'
|
120
|
-
).returns(jwt)
|
121
|
-
jwt.stubs(:valid?).returns(true)
|
122
|
-
jwt.stubs(:header).returns('Mailroom-Api-Request')
|
123
|
-
jwt.stubs(:token).returns('a_jwt_token')
|
124
|
-
|
125
|
-
delivery = MailRoom::Delivery::Postback.new(delivery_options)
|
126
|
-
|
127
|
-
delivery.deliver('a message')
|
128
|
-
expect(request.headers['Mailroom-Api-Request']).to eql('a_jwt_token')
|
129
|
-
|
130
|
-
# A different jwt token for the second time
|
131
|
-
jwt.stubs(:token).returns('another_jwt_token')
|
132
|
-
|
133
|
-
delivery.deliver('another message')
|
134
|
-
expect(request.headers['Mailroom-Api-Request']).to eql('another_jwt_token')
|
135
93
|
end
|
94
|
+
|
95
|
+
let(:jwt_secret) do
|
96
|
+
file = Tempfile.new('secret')
|
97
|
+
file.write("test secret")
|
98
|
+
file
|
99
|
+
end
|
100
|
+
|
101
|
+
after do
|
102
|
+
jwt_secret.unlink
|
103
|
+
end
|
104
|
+
|
105
|
+
it_behaves_like 'message poster'
|
136
106
|
end
|
137
107
|
end
|
138
108
|
end
|
@@ -6,17 +6,9 @@ describe MailRoom::Delivery::Sidekiq do
|
|
6
6
|
let(:redis) { subject.send(:client) }
|
7
7
|
let(:raw_client) { redis._client }
|
8
8
|
let(:options) { MailRoom::Delivery::Sidekiq::Options.new(mailbox) }
|
9
|
-
let(:redis5) { Gem::Version.new(Redis::VERSION) >= Gem::Version.new('5.0') }
|
10
|
-
let(:server_url) do
|
11
|
-
if redis5
|
12
|
-
raw_client.config.server_url
|
13
|
-
else
|
14
|
-
raw_client.options[:url]
|
15
|
-
end
|
16
|
-
end
|
17
9
|
|
18
10
|
describe '#options' do
|
19
|
-
let(:redis_url) { 'redis://localhost' }
|
11
|
+
let(:redis_url) { 'redis://localhost:6379' }
|
20
12
|
let(:redis_options) { { redis_url: redis_url } }
|
21
13
|
|
22
14
|
context 'when only redis_url is specified' do
|
@@ -28,10 +20,8 @@ describe MailRoom::Delivery::Sidekiq do
|
|
28
20
|
}
|
29
21
|
|
30
22
|
context 'with simple redis url' do
|
31
|
-
let(:expected_url) { redis5 ? "#{redis_url}:6379/0" : redis_url }
|
32
|
-
|
33
23
|
it 'client has same specified redis_url' do
|
34
|
-
expect(raw_client.server_url).to eq(
|
24
|
+
expect(raw_client.config.server_url).to eq(redis_url)
|
35
25
|
end
|
36
26
|
|
37
27
|
it 'client is a instance of RedisNamespace class' do
|
@@ -45,19 +35,17 @@ describe MailRoom::Delivery::Sidekiq do
|
|
45
35
|
end
|
46
36
|
|
47
37
|
context 'with redis_db specified in options' do
|
48
|
-
let(:expected_url) { redis5 ? "#{redis_url}:6379/4" : redis_url }
|
49
|
-
|
50
38
|
before do
|
51
39
|
redis_options[:redis_db] = 4
|
52
40
|
end
|
53
41
|
|
54
42
|
it 'client has correct redis_url' do
|
55
|
-
expect(raw_client.server_url).to eq(
|
43
|
+
expect(raw_client.config.server_url).to eq("#{redis_url}/4")
|
56
44
|
end
|
57
45
|
|
58
46
|
it 'connection has correct values' do
|
59
|
-
expect(
|
60
|
-
expect(
|
47
|
+
expect(raw_client.config.host).to eq('localhost')
|
48
|
+
expect(raw_client.config.db).to eq(4)
|
61
49
|
end
|
62
50
|
end
|
63
51
|
end
|
@@ -96,17 +84,39 @@ describe MailRoom::Delivery::Sidekiq do
|
|
96
84
|
)
|
97
85
|
}
|
98
86
|
|
87
|
+
before { ::RedisClient::SentinelConfig.any_instance.stubs(:resolve_master).returns(RedisClient::Config.new(**sentinels.first)) }
|
88
|
+
|
99
89
|
it 'client has same specified sentinel params' do
|
100
|
-
|
90
|
+
expect(raw_client.config).to be_a RedisClient::SentinelConfig
|
91
|
+
expect(raw_client.config.host).to eq('10.0.0.1')
|
92
|
+
expect(raw_client.config.name).to eq('sentinel-master')
|
93
|
+
expect(raw_client.config.password).to eq('mypassword')
|
94
|
+
expect(raw_client.config.sentinels.map(&:server_url)).to eq(["redis://10.0.0.1:26379"])
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'with separate Sentinel username and password' do
|
98
|
+
let(:sentinel_username) { 'my-sentinel-user' }
|
99
|
+
let(:sentinel_password) { 'my-sentinel-pass' }
|
100
|
+
let(:mailbox) {
|
101
|
+
build_mailbox(
|
102
|
+
delivery_method: :sidekiq,
|
103
|
+
delivery_options: {
|
104
|
+
redis_url: redis_url,
|
105
|
+
sentinels: sentinels,
|
106
|
+
sentinel_username: sentinel_username,
|
107
|
+
sentinel_password: sentinel_password
|
108
|
+
}
|
109
|
+
)
|
110
|
+
}
|
111
|
+
|
112
|
+
it 'client uses Sentinel username and password' do
|
113
|
+
expect(raw_client.config).to be_a RedisClient::SentinelConfig
|
101
114
|
expect(raw_client.config.password).to eq('mypassword')
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
expect(
|
106
|
-
|
107
|
-
expect(raw_client.options[:host]).to eq('sentinel-master')
|
108
|
-
expect(raw_client.options[:password]).to eq('mypassword')
|
109
|
-
expect(raw_client.options[:sentinels]).to eq(sentinels)
|
115
|
+
|
116
|
+
sentinels = raw_client.config.sentinels
|
117
|
+
|
118
|
+
expect(sentinels.map(&:username).uniq).to eq([sentinel_username])
|
119
|
+
expect(sentinels.map(&:password).uniq).to eq([sentinel_password])
|
110
120
|
end
|
111
121
|
end
|
112
122
|
end
|
@@ -34,12 +34,14 @@ describe MailRoom::HealthCheck do
|
|
34
34
|
|
35
35
|
describe '#run' do
|
36
36
|
it 'sets running to true' do
|
37
|
-
server = stub(start: true)
|
37
|
+
server = stub(start: true, shutdown: true)
|
38
38
|
subject.stubs(:create_server).returns(server)
|
39
39
|
|
40
40
|
subject.run
|
41
41
|
|
42
42
|
expect(subject.running).to be true
|
43
|
+
|
44
|
+
subject.quit
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-mail_room
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Pitale
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-05 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: net-imap
|
@@ -64,7 +63,7 @@ dependencies:
|
|
64
63
|
requirements:
|
65
64
|
- - ">="
|
66
65
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
66
|
+
version: '5'
|
68
67
|
- - "<"
|
69
68
|
- !ruby/object:Gem::Version
|
70
69
|
version: '6'
|
@@ -74,7 +73,7 @@ dependencies:
|
|
74
73
|
requirements:
|
75
74
|
- - ">="
|
76
75
|
- !ruby/object:Gem::Version
|
77
|
-
version: '
|
76
|
+
version: '5'
|
78
77
|
- - "<"
|
79
78
|
- !ruby/object:Gem::Version
|
80
79
|
version: '6'
|
@@ -140,14 +139,14 @@ dependencies:
|
|
140
139
|
requirements:
|
141
140
|
- - "~>"
|
142
141
|
- !ruby/object:Gem::Version
|
143
|
-
version: '
|
142
|
+
version: '2.0'
|
144
143
|
type: :development
|
145
144
|
prerelease: false
|
146
145
|
version_requirements: !ruby/object:Gem::Requirement
|
147
146
|
requirements:
|
148
147
|
- - "~>"
|
149
148
|
- !ruby/object:Gem::Version
|
150
|
-
version: '
|
149
|
+
version: '2.0'
|
151
150
|
- !ruby/object:Gem::Dependency
|
152
151
|
name: simplecov
|
153
152
|
requirement: !ruby/object:Gem::Requirement
|
@@ -277,6 +276,7 @@ files:
|
|
277
276
|
- ".rubocop.yml"
|
278
277
|
- ".rubocop_todo.yml"
|
279
278
|
- ".ruby-version"
|
279
|
+
- ".tool-versions"
|
280
280
|
- CHANGELOG.md
|
281
281
|
- CODE_OF_CONDUCT.md
|
282
282
|
- CONTRIBUTING.md
|
@@ -337,10 +337,9 @@ files:
|
|
337
337
|
- spec/lib/message_spec.rb
|
338
338
|
- spec/lib/microsoft_graph/connection_spec.rb
|
339
339
|
- spec/spec_helper.rb
|
340
|
-
homepage:
|
340
|
+
homepage: https://gitlab.com/gitlab-org/ruby/gems/gitlab-mail_room
|
341
341
|
licenses: []
|
342
342
|
metadata: {}
|
343
|
-
post_install_message:
|
344
343
|
rdoc_options: []
|
345
344
|
require_paths:
|
346
345
|
- lib
|
@@ -355,8 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
355
354
|
- !ruby/object:Gem::Version
|
356
355
|
version: '0'
|
357
356
|
requirements: []
|
358
|
-
rubygems_version: 3.
|
359
|
-
signing_key:
|
357
|
+
rubygems_version: 3.6.2
|
360
358
|
specification_version: 4
|
361
359
|
summary: mail_room will proxy email (gmail) from IMAP to a callback URL, logger, or
|
362
360
|
letter_opener
|