sidekiq 4.1.1 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sidekiq might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/issue_template.md +4 -0
- data/.travis.yml +3 -6
- data/4.0-Upgrade.md +3 -0
- data/COMM-LICENSE +1 -1
- data/Changes.md +69 -0
- data/Ent-Changes.md +40 -0
- data/Gemfile +6 -5
- data/Pro-3.0-Upgrade.md +5 -7
- data/Pro-Changes.md +66 -0
- data/README.md +2 -1
- data/bin/sidekiqload +2 -2
- data/lib/sidekiq.rb +5 -1
- data/lib/sidekiq/api.rb +3 -1
- data/lib/sidekiq/cli.rb +15 -2
- data/lib/sidekiq/client.rb +11 -3
- data/lib/sidekiq/core_ext.rb +1 -0
- data/lib/sidekiq/exception_handler.rb +2 -1
- data/lib/sidekiq/extensions/action_mailer.rb +1 -0
- data/lib/sidekiq/extensions/active_record.rb +1 -0
- data/lib/sidekiq/extensions/class_methods.rb +1 -0
- data/lib/sidekiq/extensions/generic_proxy.rb +1 -0
- data/lib/sidekiq/fetch.rb +1 -0
- data/lib/sidekiq/launcher.rb +9 -3
- data/lib/sidekiq/logging.rb +2 -1
- data/lib/sidekiq/manager.rb +2 -0
- data/lib/sidekiq/middleware/chain.rb +1 -0
- data/lib/sidekiq/middleware/i18n.rb +1 -0
- data/lib/sidekiq/middleware/server/retry_jobs.rb +7 -7
- data/lib/sidekiq/paginator.rb +1 -0
- data/lib/sidekiq/processor.rb +29 -25
- data/lib/sidekiq/rails.rb +18 -0
- data/lib/sidekiq/redis_connection.rb +6 -3
- data/lib/sidekiq/scheduled.rb +2 -0
- data/lib/sidekiq/testing.rb +1 -0
- data/lib/sidekiq/testing/inline.rb +1 -0
- data/lib/sidekiq/util.rb +1 -0
- data/lib/sidekiq/version.rb +2 -1
- data/lib/sidekiq/web.rb +80 -202
- data/lib/sidekiq/web/action.rb +99 -0
- data/lib/sidekiq/web/application.rb +335 -0
- data/lib/sidekiq/{web_helpers.rb → web/helpers.rb} +31 -11
- data/lib/sidekiq/web/router.rb +96 -0
- data/lib/sidekiq/worker.rb +1 -0
- data/sidekiq.gemspec +2 -2
- data/test/fake_env.rb +1 -0
- data/test/helper.rb +1 -0
- data/test/test_actors.rb +1 -0
- data/test/test_api.rb +1 -0
- data/test/test_cli.rb +15 -2
- data/test/test_client.rb +34 -0
- data/test/test_exception_handler.rb +2 -1
- data/test/test_extensions.rb +1 -0
- data/test/test_fetch.rb +1 -0
- data/test/test_launcher.rb +17 -2
- data/test/test_logging.rb +1 -0
- data/test/test_manager.rb +1 -0
- data/test/test_middleware.rb +1 -0
- data/test/test_processor.rb +1 -0
- data/test/test_rails.rb +1 -0
- data/test/test_redis_connection.rb +7 -1
- data/test/test_retry.rb +1 -0
- data/test/test_scheduled.rb +1 -0
- data/test/test_scheduling.rb +1 -0
- data/test/test_sidekiq.rb +1 -0
- data/test/test_testing.rb +1 -0
- data/test/test_testing_fake.rb +1 -0
- data/test/test_testing_inline.rb +2 -1
- data/test/test_util.rb +1 -0
- data/test/test_web.rb +53 -5
- data/test/test_web_helpers.rb +1 -0
- data/web/assets/images/{status-sd8051fd480.png → status.png} +0 -0
- data/web/assets/javascripts/application.js +5 -0
- data/web/assets/javascripts/locales/{jquery.timeago.no.js → jquery.timeago.nb.js} +1 -1
- data/web/assets/stylesheets/application.css +26 -1
- data/web/assets/stylesheets/bootstrap.css +4 -8
- data/web/locales/de.yml +1 -1
- data/web/locales/en.yml +1 -0
- data/web/locales/ru.yml +3 -0
- data/web/views/_footer.erb +1 -1
- data/web/views/_nav.erb +1 -1
- data/web/views/busy.erb +4 -4
- data/web/views/dashboard.erb +2 -2
- data/web/views/dead.erb +1 -1
- data/web/views/layout.erb +3 -3
- data/web/views/morgue.erb +2 -2
- data/web/views/queue.erb +3 -3
- data/web/views/queues.erb +1 -1
- data/web/views/retries.erb +2 -2
- data/web/views/retry.erb +1 -1
- data/web/views/scheduled.erb +2 -2
- data/web/views/scheduled_job_info.erb +1 -1
- metadata +17 -29
- data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
- data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
- data/web/assets/images/status/active.png +0 -0
- data/web/assets/images/status/idle.png +0 -0
- data/web/views/_poll_js.erb +0 -5
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rack'
|
3
|
+
|
4
|
+
module Sidekiq
|
5
|
+
module WebRouter
|
6
|
+
GET = 'GET'.freeze
|
7
|
+
DELETE = 'DELETE'.freeze
|
8
|
+
POST = 'POST'.freeze
|
9
|
+
PUT = 'PUT'.freeze
|
10
|
+
PATCH = 'PATCH'.freeze
|
11
|
+
HEAD = 'HEAD'.freeze
|
12
|
+
|
13
|
+
ROUTE_PARAMS = 'rack.route_params'.freeze
|
14
|
+
REQUEST_METHOD = 'REQUEST_METHOD'.freeze
|
15
|
+
PATH_INFO = 'PATH_INFO'.freeze
|
16
|
+
|
17
|
+
def get(path, &block)
|
18
|
+
route(GET, path, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def post(path, &block)
|
22
|
+
route(POST, path, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
def put(path, &block)
|
26
|
+
route(PUT, path, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def patch(path, &block)
|
30
|
+
route(PATCH, path, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete(path, &block)
|
34
|
+
route(DELETE, path, &block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def route(method, path, &block)
|
38
|
+
@routes ||= { GET => [], POST => [], PUT => [], PATCH => [], DELETE => [], HEAD => [] }
|
39
|
+
|
40
|
+
@routes[method] << WebRoute.new(method, path, block)
|
41
|
+
@routes[HEAD] << WebRoute.new(method, path, block) if method == GET
|
42
|
+
end
|
43
|
+
|
44
|
+
def match(env)
|
45
|
+
request_method = env[REQUEST_METHOD]
|
46
|
+
path_info = ::Rack::Utils.unescape env[PATH_INFO]
|
47
|
+
|
48
|
+
@routes[request_method].each do |route|
|
49
|
+
if params = route.match(request_method, path_info)
|
50
|
+
env[ROUTE_PARAMS] = params
|
51
|
+
|
52
|
+
return WebAction.new(env, route.block)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class WebRoute
|
61
|
+
attr_accessor :request_method, :pattern, :block, :name
|
62
|
+
|
63
|
+
NAMED_SEGMENTS_PATTERN = /\/([^\/]*):([^\.:$\/]+)/.freeze
|
64
|
+
|
65
|
+
def initialize(request_method, pattern, block)
|
66
|
+
@request_method = request_method
|
67
|
+
@pattern = pattern
|
68
|
+
@block = block
|
69
|
+
end
|
70
|
+
|
71
|
+
def matcher
|
72
|
+
@matcher ||= compile
|
73
|
+
end
|
74
|
+
|
75
|
+
def compile
|
76
|
+
if pattern.match(NAMED_SEGMENTS_PATTERN)
|
77
|
+
p = pattern.gsub(NAMED_SEGMENTS_PATTERN, '/\1(?<\2>[^$/]+)')
|
78
|
+
|
79
|
+
Regexp.new("\\A#{p}\\Z")
|
80
|
+
else
|
81
|
+
pattern
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def match(request_method, path)
|
86
|
+
case matcher
|
87
|
+
when String
|
88
|
+
{} if path == matcher
|
89
|
+
else
|
90
|
+
if path_match = path.match(matcher)
|
91
|
+
Hash[path_match.names.map(&:to_sym).zip(path_match.captures)]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/sidekiq/worker.rb
CHANGED
data/sidekiq.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_dependency 'redis', '~> 3.2', '>= 3.2.1'
|
19
19
|
gem.add_dependency 'connection_pool', '~> 2.2', '>= 2.2.0'
|
20
20
|
gem.add_dependency 'concurrent-ruby', '~> 1.0'
|
21
|
+
gem.add_dependency 'rack-protection', '~> 1.5'
|
21
22
|
gem.add_development_dependency 'redis-namespace', '~> 1.5', '>= 1.5.2'
|
22
|
-
gem.add_development_dependency 'sinatra', '~> 1.4', '>= 1.4.6'
|
23
23
|
gem.add_development_dependency 'minitest', '~> 5.7', '>= 5.7.0'
|
24
24
|
gem.add_development_dependency 'rake', '~> 10.0'
|
25
|
-
gem.add_development_dependency 'rails', '
|
25
|
+
gem.add_development_dependency 'rails', '>= 3.2.0'
|
26
26
|
end
|
data/test/fake_env.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
# frozen_string_literal: true
|
data/test/helper.rb
CHANGED
data/test/test_actors.rb
CHANGED
data/test/test_api.rb
CHANGED
data/test/test_cli.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'helper'
|
2
3
|
require 'sidekiq/cli'
|
3
4
|
require 'tempfile'
|
@@ -41,6 +42,18 @@ class TestCli < Sidekiq::Test
|
|
41
42
|
assert_equal 60, Sidekiq.options[:concurrency]
|
42
43
|
end
|
43
44
|
|
45
|
+
it 'changes concurrency with ENV' do
|
46
|
+
begin
|
47
|
+
ENV['RAILS_MAX_THREADS'] = '9'
|
48
|
+
@cli.parse(['sidekiq', '-c', '60', '-r', './test/fake_env.rb'])
|
49
|
+
assert_equal 60, Sidekiq.options[:concurrency]
|
50
|
+
@cli.parse(['sidekiq', '-r', './test/fake_env.rb'])
|
51
|
+
assert_equal 9, Sidekiq.options[:concurrency]
|
52
|
+
ensure
|
53
|
+
ENV.delete('RAILS_MAX_THREADS')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
44
57
|
it 'changes queues' do
|
45
58
|
@cli.parse(['sidekiq', '-q', 'foo', '-r', './test/fake_env.rb'])
|
46
59
|
assert_equal ['foo'], Sidekiq.options[:queues]
|
@@ -329,7 +342,7 @@ class TestCli < Sidekiq::Test
|
|
329
342
|
end
|
330
343
|
|
331
344
|
after do
|
332
|
-
File.unlink @tmp_log_path if File.
|
345
|
+
File.unlink @tmp_log_path if File.exist? @tmp_log_path
|
333
346
|
end
|
334
347
|
|
335
348
|
it 'shuts down the worker' do
|
@@ -364,7 +377,7 @@ class TestCli < Sidekiq::Test
|
|
364
377
|
end
|
365
378
|
|
366
379
|
after do
|
367
|
-
File.unlink @tmp_log_path if File.
|
380
|
+
File.unlink @tmp_log_path if File.exist? @tmp_log_path
|
368
381
|
end
|
369
382
|
|
370
383
|
describe 'with backtrace' do
|
data/test/test_client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'helper'
|
2
3
|
|
3
4
|
class TestClient < Sidekiq::Test
|
@@ -32,6 +33,23 @@ class TestClient < Sidekiq::Test
|
|
32
33
|
assert_equal 24, jid.size
|
33
34
|
end
|
34
35
|
|
36
|
+
it 'allows middleware to stop bulk jobs' do
|
37
|
+
mware = Class.new do
|
38
|
+
def call(worker_klass,msg,q,r)
|
39
|
+
msg['args'][0] == 1 ? yield : false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
client = Sidekiq::Client.new
|
43
|
+
client.middleware do |chain|
|
44
|
+
chain.add mware
|
45
|
+
end
|
46
|
+
q = Sidekiq::Queue.new
|
47
|
+
q.clear
|
48
|
+
result = client.push_bulk('class' => 'Blah', 'args' => [[1],[2],[3]])
|
49
|
+
assert_equal 1, result.size
|
50
|
+
assert_equal 1, q.size
|
51
|
+
end
|
52
|
+
|
35
53
|
it 'allows local middleware modification' do
|
36
54
|
$called = false
|
37
55
|
mware = Class.new { def call(worker_klass,msg,q,r); $called = true; msg;end }
|
@@ -108,6 +126,10 @@ class TestClient < Sidekiq::Test
|
|
108
126
|
assert_match(/[0-9a-f]{12}/, jid)
|
109
127
|
end
|
110
128
|
end
|
129
|
+
it 'handles no jobs' do
|
130
|
+
result = Sidekiq::Client.push_bulk('class' => 'QueuedWorker', 'args' => [])
|
131
|
+
assert_equal 0, result.size
|
132
|
+
end
|
111
133
|
end
|
112
134
|
|
113
135
|
class BaseWorker
|
@@ -164,6 +186,18 @@ class TestClient < Sidekiq::Test
|
|
164
186
|
conn.verify
|
165
187
|
end
|
166
188
|
|
189
|
+
it 'allows #via to point to same Redi' do
|
190
|
+
conn = MiniTest::Mock.new
|
191
|
+
conn.expect(:multi, [0, 1])
|
192
|
+
sharded_pool = ConnectionPool.new(size: 1) { conn }
|
193
|
+
Sidekiq::Client.via(sharded_pool) do
|
194
|
+
Sidekiq::Client.via(sharded_pool) do
|
195
|
+
CWorker.perform_async(1,2,3)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
conn.verify
|
199
|
+
end
|
200
|
+
|
167
201
|
it 'allows #via to point to different Redi' do
|
168
202
|
conn = MiniTest::Mock.new
|
169
203
|
conn.expect(:multi, [0, 1])
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'helper'
|
2
3
|
require 'sidekiq/exception_handler'
|
3
4
|
require 'stringio'
|
@@ -32,7 +33,7 @@ class TestExceptionHandler < Sidekiq::Test
|
|
32
33
|
Component.new.invoke_exception(:a => 1)
|
33
34
|
@str_logger.rewind
|
34
35
|
log = @str_logger.readlines
|
35
|
-
assert_match(/a
|
36
|
+
assert_match(/"a":1/, log[0], "didn't include the context")
|
36
37
|
assert_match(/Something didn't work!/, log[1], "didn't include the exception message")
|
37
38
|
assert_match(/test\/test_exception_handler.rb/, log[2], "didn't include the backtrace")
|
38
39
|
end
|
data/test/test_extensions.rb
CHANGED
data/test/test_fetch.rb
CHANGED
data/test/test_launcher.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'helper'
|
2
3
|
require 'sidekiq/launcher'
|
3
4
|
|
@@ -14,8 +15,6 @@ class TestLauncher < Sidekiq::Test
|
|
14
15
|
|
15
16
|
describe 'heartbeat' do
|
16
17
|
before do
|
17
|
-
uow = Object.new
|
18
|
-
|
19
18
|
@mgr = new_manager(options)
|
20
19
|
@launcher = Sidekiq::Launcher.new(options)
|
21
20
|
@launcher.manager = @mgr
|
@@ -30,6 +29,18 @@ class TestLauncher < Sidekiq::Test
|
|
30
29
|
$0 = @proctitle
|
31
30
|
end
|
32
31
|
|
32
|
+
it 'fires new heartbeat events' do
|
33
|
+
i = 0
|
34
|
+
Sidekiq.on(:heartbeat) do
|
35
|
+
i += 1
|
36
|
+
end
|
37
|
+
assert_equal 0, i
|
38
|
+
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
|
39
|
+
assert_equal 1, i
|
40
|
+
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
|
41
|
+
assert_equal 1, i
|
42
|
+
end
|
43
|
+
|
33
44
|
describe 'when manager is active' do
|
34
45
|
before do
|
35
46
|
Sidekiq::CLI::PROCTITLES << proc { "xyz" }
|
@@ -55,6 +66,10 @@ class TestLauncher < Sidekiq::Test
|
|
55
66
|
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
|
56
67
|
end
|
57
68
|
|
69
|
+
#after do
|
70
|
+
#puts system('redis-cli -n 15 keys "*" | while read LINE ; do TTL=`redis-cli -n 15 ttl "$LINE"`; if [ "$TTL" -eq -1 ]; then echo "$LINE"; fi; done;')
|
71
|
+
#end
|
72
|
+
|
58
73
|
it 'indicates stopping status in proctitle' do
|
59
74
|
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [1 of 3 busy] stopping", $0
|
60
75
|
end
|
data/test/test_logging.rb
CHANGED
data/test/test_manager.rb
CHANGED
data/test/test_middleware.rb
CHANGED
data/test/test_processor.rb
CHANGED
data/test/test_rails.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'helper'
|
2
3
|
|
3
4
|
class TestRedisConnection < Sidekiq::Test
|
@@ -26,11 +27,16 @@ class TestRedisConnection < Sidekiq::Test
|
|
26
27
|
end
|
27
28
|
|
28
29
|
describe "namespace" do
|
29
|
-
it "uses a given :namespace" do
|
30
|
+
it "uses a given :namespace set by a symbol key" do
|
30
31
|
pool = Sidekiq::RedisConnection.create(:namespace => "xxx")
|
31
32
|
assert_equal "xxx", pool.checkout.namespace
|
32
33
|
end
|
33
34
|
|
35
|
+
it "uses a given :namespace set by a string key" do
|
36
|
+
pool = Sidekiq::RedisConnection.create("namespace" => "xxx")
|
37
|
+
assert_equal "xxx", pool.checkout.namespace
|
38
|
+
end
|
39
|
+
|
34
40
|
it "uses given :namespace over :namespace from Sidekiq.options" do
|
35
41
|
Sidekiq.options[:namespace] = "xxx"
|
36
42
|
pool = Sidekiq::RedisConnection.create(:namespace => "yyy")
|
data/test/test_retry.rb
CHANGED
data/test/test_scheduled.rb
CHANGED
data/test/test_scheduling.rb
CHANGED
data/test/test_sidekiq.rb
CHANGED
data/test/test_testing.rb
CHANGED
data/test/test_testing_fake.rb
CHANGED
data/test/test_testing_inline.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require_relative 'helper'
|
2
3
|
|
3
4
|
require 'active_record'
|
@@ -86,7 +87,7 @@ class TestInline < Sidekiq::Test
|
|
86
87
|
end
|
87
88
|
|
88
89
|
it 'should relay parameters through json' do
|
89
|
-
assert Sidekiq::Client.enqueue(InlineWorkerWithTimeParam, Time.now)
|
90
|
+
assert Sidekiq::Client.enqueue(InlineWorkerWithTimeParam, Time.now.to_f)
|
90
91
|
end
|
91
92
|
|
92
93
|
end
|
data/test/test_util.rb
CHANGED
data/test/test_web.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# encoding: utf-8
|
2
3
|
require_relative 'helper'
|
3
4
|
require 'sidekiq/web'
|
4
5
|
require 'rack/test'
|
5
|
-
require 'tilt/erubis'
|
6
6
|
|
7
7
|
class TestWeb < Sidekiq::Test
|
8
|
-
|
9
8
|
describe 'sidekiq web' do
|
10
9
|
include Rack::Test::Methods
|
11
10
|
|
@@ -306,7 +305,7 @@ class TestWeb < Sidekiq::Test
|
|
306
305
|
it 'calls updatePage() once when polling' do
|
307
306
|
get '/busy?poll=true'
|
308
307
|
assert_equal 200, last_response.status
|
309
|
-
assert_equal 1, last_response.body.scan('
|
308
|
+
assert_equal 1, last_response.body.scan('data-poll-path="/busy').count
|
310
309
|
end
|
311
310
|
|
312
311
|
it 'escape job args and error messages' do
|
@@ -340,7 +339,6 @@ class TestWeb < Sidekiq::Test
|
|
340
339
|
assert last_response.body.include?( "<a>hello</a>" )
|
341
340
|
assert !last_response.body.include?( "<a>hello</a>" )
|
342
341
|
|
343
|
-
|
344
342
|
# on /queues page
|
345
343
|
params = add_xss_retry # sorry, don't know how to easily make this show up on queues page otherwise.
|
346
344
|
post "/retries/#{job_params(*params)}", 'retry' => 'Retry'
|
@@ -373,7 +371,7 @@ class TestWeb < Sidekiq::Test
|
|
373
371
|
before do
|
374
372
|
Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), "fixtures")
|
375
373
|
Sidekiq::Web.tabs['Custom Tab'] = '/custom'
|
376
|
-
Sidekiq::
|
374
|
+
Sidekiq::WebApplication.get('/custom') do
|
377
375
|
clear_caches # ugly hack since I can't figure out how to access WebHelpers outside of this context
|
378
376
|
t('translated_text')
|
379
377
|
end
|
@@ -386,6 +384,7 @@ class TestWeb < Sidekiq::Test
|
|
386
384
|
|
387
385
|
it 'can show user defined tab with custom locales' do
|
388
386
|
get '/custom'
|
387
|
+
|
389
388
|
assert_match(/Changed text/, last_response.body)
|
390
389
|
end
|
391
390
|
end
|
@@ -563,6 +562,7 @@ class TestWeb < Sidekiq::Test
|
|
563
562
|
Sidekiq.redis do |conn|
|
564
563
|
conn.zadd('retry', score, Sidekiq.dump_json(msg))
|
565
564
|
end
|
565
|
+
|
566
566
|
[msg, score]
|
567
567
|
end
|
568
568
|
|
@@ -595,6 +595,7 @@ class TestWeb < Sidekiq::Test
|
|
595
595
|
Sidekiq.redis do |conn|
|
596
596
|
conn.zadd('retry', score, Sidekiq.dump_json(msg))
|
597
597
|
end
|
598
|
+
|
598
599
|
[msg, score]
|
599
600
|
end
|
600
601
|
|
@@ -610,4 +611,51 @@ class TestWeb < Sidekiq::Test
|
|
610
611
|
end
|
611
612
|
end
|
612
613
|
end
|
614
|
+
|
615
|
+
describe 'sidekiq web with basic auth' do
|
616
|
+
include Rack::Test::Methods
|
617
|
+
|
618
|
+
def app
|
619
|
+
app = Sidekiq::Web.new
|
620
|
+
app.use(Rack::Auth::Basic) { |user, pass| user == "a" && pass == "b" }
|
621
|
+
|
622
|
+
app
|
623
|
+
end
|
624
|
+
|
625
|
+
it 'requires basic authentication' do
|
626
|
+
get '/'
|
627
|
+
|
628
|
+
assert_equal 401, last_response.status
|
629
|
+
refute_nil last_response.header["WWW-Authenticate"]
|
630
|
+
end
|
631
|
+
|
632
|
+
it 'authenticates successfuly' do
|
633
|
+
basic_authorize 'a', 'b'
|
634
|
+
|
635
|
+
get '/'
|
636
|
+
|
637
|
+
assert_equal 200, last_response.status
|
638
|
+
end
|
639
|
+
end
|
640
|
+
|
641
|
+
describe 'sidekiq web with custom session' do
|
642
|
+
include Rack::Test::Methods
|
643
|
+
|
644
|
+
def app
|
645
|
+
app = Sidekiq::Web.new
|
646
|
+
|
647
|
+
app.use Rack::Session::Cookie, secret: 'v3rys3cr31', host: 'nicehost.org'
|
648
|
+
|
649
|
+
app
|
650
|
+
end
|
651
|
+
|
652
|
+
it 'requires basic authentication' do
|
653
|
+
get '/'
|
654
|
+
|
655
|
+
session_options = last_request.env['rack.session'].options
|
656
|
+
|
657
|
+
assert_equal 'v3rys3cr31', session_options[:secret]
|
658
|
+
assert_equal 'nicehost.org', session_options[:host]
|
659
|
+
end
|
660
|
+
end
|
613
661
|
end
|