gitlab-mail_room 0.0.25 → 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/.gitlab-ci.yml +1 -1
- data/.rubocop_todo.yml +0 -5
- data/.tool-versions +1 -1
- data/lib/mail_room/delivery/postback.rb +2 -3
- data/lib/mail_room/version.rb +1 -1
- data/spec/lib/delivery/postback_spec.rb +79 -109
- metadata +3 -6
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/.gitlab-ci.yml
CHANGED
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/.tool-versions
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby 3.
|
1
|
+
ruby 3.4.1
|
@@ -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
|
|
@@ -76,14 +75,14 @@ module MailRoom
|
|
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
|
|
data/lib/mail_room/version.rb
CHANGED
@@ -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
|
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
|
@@ -341,7 +340,6 @@ files:
|
|
341
340
|
homepage: https://gitlab.com/gitlab-org/ruby/gems/gitlab-mail_room
|
342
341
|
licenses: []
|
343
342
|
metadata: {}
|
344
|
-
post_install_message:
|
345
343
|
rdoc_options: []
|
346
344
|
require_paths:
|
347
345
|
- lib
|
@@ -356,8 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
356
354
|
- !ruby/object:Gem::Version
|
357
355
|
version: '0'
|
358
356
|
requirements: []
|
359
|
-
rubygems_version: 3.
|
360
|
-
signing_key:
|
357
|
+
rubygems_version: 3.6.2
|
361
358
|
specification_version: 4
|
362
359
|
summary: mail_room will proxy email (gmail) from IMAP to a callback URL, logger, or
|
363
360
|
letter_opener
|