foreman-tasks 4.1.6 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby_tests.yml +0 -1
- data/app/controllers/foreman_tasks/api/tasks_controller.rb +2 -2
- data/app/controllers/foreman_tasks/tasks_controller.rb +7 -6
- data/app/graphql/types/recurring_logic.rb +18 -0
- data/app/graphql/types/task.rb +25 -0
- data/app/graphql/types/triggering.rb +16 -0
- data/app/lib/actions/helpers/with_continuous_output.rb +1 -1
- data/app/lib/actions/middleware/watch_delegated_proxy_sub_tasks.rb +6 -2
- data/app/models/foreman_tasks/recurring_logic.rb +2 -0
- data/app/models/foreman_tasks/task/dynflow_task.rb +3 -8
- data/app/models/foreman_tasks/task.rb +28 -0
- data/app/models/foreman_tasks/triggering.rb +2 -0
- data/app/services/foreman_tasks/dashboard_table_filter.rb +56 -0
- data/foreman-tasks.gemspec +0 -1
- data/lib/foreman_tasks/continuous_output.rb +50 -0
- data/lib/foreman_tasks/engine.rb +6 -15
- data/lib/foreman_tasks/tasks/export_tasks.rake +46 -90
- data/lib/foreman_tasks/version.rb +1 -1
- data/lib/foreman_tasks.rb +2 -5
- data/test/controllers/api/tasks_controller_test.rb +0 -11
- data/test/graphql/queries/recurring_logic_test.rb +28 -0
- data/test/graphql/queries/recurring_logics_query_test.rb +30 -0
- data/test/graphql/queries/task_query_test.rb +33 -0
- data/test/graphql/queries/tasks_query_test.rb +31 -0
- data/test/unit/dashboard_table_filter_test.rb +77 -0
- data/test/unit/task_test.rb +39 -8
- data/webpack/ForemanTasks/Components/TaskActions/TaskActionHelpers.js +4 -11
- data/webpack/ForemanTasks/Components/TaskActions/TaskActionHelpers.test.js +5 -27
- data/webpack/ForemanTasks/Components/TasksTable/TasksTable.js +0 -8
- data/webpack/ForemanTasks/Components/TasksTable/TasksTableActions.js +1 -6
- data/webpack/ForemanTasks/Components/TasksTable/TasksTableHelpers.js +1 -2
- data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.js +11 -22
- data/webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js +16 -17
- data/webpack/ForemanTasks/Components/TasksTable/TasksTableSelectors.js +0 -3
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableHelpers.test.js +1 -1
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTableReducer.test.js +1 -3
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTablePage.test.js.snap +2 -12
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTableReducer.test.js.snap +0 -5
- data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/__snapshots__/selectionHeaderCellFormatter.test.js.snap +0 -1
- data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/selectionHeaderCellFormatter.test.js +1 -1
- data/webpack/ForemanTasks/Components/TasksTable/formatters/selectionHeaderCellFormatter.js +0 -1
- data/webpack/ForemanTasks/Components/TasksTable/index.js +0 -2
- metadata +18 -27
- data/test/core/unit/dispatcher_test.rb +0 -43
- data/test/core/unit/runner_test.rb +0 -116
- data/test/core/unit/task_launcher_test.rb +0 -56
- data/test/foreman_tasks_core_test_helper.rb +0 -4
- data/test/unit/otp_manager_test.rb +0 -77
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dynflow
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.2.3
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: foreman-tasks-core
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: get_process_mem
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,6 +133,9 @@ files:
|
|
147
133
|
- app/controllers/foreman_tasks/react_controller.rb
|
148
134
|
- app/controllers/foreman_tasks/recurring_logics_controller.rb
|
149
135
|
- app/controllers/foreman_tasks/tasks_controller.rb
|
136
|
+
- app/graphql/types/recurring_logic.rb
|
137
|
+
- app/graphql/types/task.rb
|
138
|
+
- app/graphql/types/triggering.rb
|
150
139
|
- app/helpers/foreman_tasks/foreman_tasks_helper.rb
|
151
140
|
- app/helpers/foreman_tasks/tasks_helper.rb
|
152
141
|
- app/lib/actions/action_with_sub_plans.rb
|
@@ -198,6 +187,7 @@ files:
|
|
198
187
|
- app/models/foreman_tasks/task_groups/recurring_logic_task_group.rb
|
199
188
|
- app/models/foreman_tasks/triggering.rb
|
200
189
|
- app/models/setting/foreman_tasks.rb
|
190
|
+
- app/services/foreman_tasks/dashboard_table_filter.rb
|
201
191
|
- app/services/foreman_tasks/proxy_selector.rb
|
202
192
|
- app/services/foreman_tasks/troubleshooting_help_generator.rb
|
203
193
|
- app/services/ui_notifications/tasks.rb
|
@@ -273,6 +263,7 @@ files:
|
|
273
263
|
- lib/foreman_tasks.rb
|
274
264
|
- lib/foreman_tasks/authorizer_ext.rb
|
275
265
|
- lib/foreman_tasks/cleaner.rb
|
266
|
+
- lib/foreman_tasks/continuous_output.rb
|
276
267
|
- lib/foreman_tasks/dynflow.rb
|
277
268
|
- lib/foreman_tasks/dynflow/configuration.rb
|
278
269
|
- lib/foreman_tasks/dynflow/console_authorizer.rb
|
@@ -306,14 +297,14 @@ files:
|
|
306
297
|
- test/controllers/api/tasks_controller_test.rb
|
307
298
|
- test/controllers/recurring_logics_controller_test.rb
|
308
299
|
- test/controllers/tasks_controller_test.rb
|
309
|
-
- test/core/unit/dispatcher_test.rb
|
310
|
-
- test/core/unit/runner_test.rb
|
311
|
-
- test/core/unit/task_launcher_test.rb
|
312
300
|
- test/factories/recurring_logic_factory.rb
|
313
301
|
- test/factories/task_factory.rb
|
314
302
|
- test/factories/triggering_factory.rb
|
315
|
-
- test/foreman_tasks_core_test_helper.rb
|
316
303
|
- test/foreman_tasks_test_helper.rb
|
304
|
+
- test/graphql/queries/recurring_logic_test.rb
|
305
|
+
- test/graphql/queries/recurring_logics_query_test.rb
|
306
|
+
- test/graphql/queries/task_query_test.rb
|
307
|
+
- test/graphql/queries/tasks_query_test.rb
|
317
308
|
- test/helpers/foreman_tasks/foreman_tasks_helper_test.rb
|
318
309
|
- test/helpers/foreman_tasks/tasks_helper_test.rb
|
319
310
|
- test/lib/actions/middleware/keep_current_request_id_test.rb
|
@@ -334,9 +325,9 @@ files:
|
|
334
325
|
- test/unit/actions/recurring_action_test.rb
|
335
326
|
- test/unit/cleaner_test.rb
|
336
327
|
- test/unit/config/environment.rb
|
328
|
+
- test/unit/dashboard_table_filter_test.rb
|
337
329
|
- test/unit/dynflow_console_authorizer_test.rb
|
338
330
|
- test/unit/locking_test.rb
|
339
|
-
- test/unit/otp_manager_test.rb
|
340
331
|
- test/unit/proxy_selector_test.rb
|
341
332
|
- test/unit/recurring_logic_test.rb
|
342
333
|
- test/unit/remote_task_test.rb
|
@@ -611,7 +602,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
611
602
|
- !ruby/object:Gem::Version
|
612
603
|
version: '0'
|
613
604
|
requirements: []
|
614
|
-
rubygems_version: 3.1.
|
605
|
+
rubygems_version: 3.1.2
|
615
606
|
signing_key:
|
616
607
|
specification_version: 4
|
617
608
|
summary: Foreman plugin for showing tasks information for resources and users
|
@@ -620,14 +611,14 @@ test_files:
|
|
620
611
|
- test/controllers/api/tasks_controller_test.rb
|
621
612
|
- test/controllers/recurring_logics_controller_test.rb
|
622
613
|
- test/controllers/tasks_controller_test.rb
|
623
|
-
- test/core/unit/dispatcher_test.rb
|
624
|
-
- test/core/unit/runner_test.rb
|
625
|
-
- test/core/unit/task_launcher_test.rb
|
626
614
|
- test/factories/recurring_logic_factory.rb
|
627
615
|
- test/factories/task_factory.rb
|
628
616
|
- test/factories/triggering_factory.rb
|
629
|
-
- test/foreman_tasks_core_test_helper.rb
|
630
617
|
- test/foreman_tasks_test_helper.rb
|
618
|
+
- test/graphql/queries/recurring_logic_test.rb
|
619
|
+
- test/graphql/queries/recurring_logics_query_test.rb
|
620
|
+
- test/graphql/queries/task_query_test.rb
|
621
|
+
- test/graphql/queries/tasks_query_test.rb
|
631
622
|
- test/helpers/foreman_tasks/foreman_tasks_helper_test.rb
|
632
623
|
- test/helpers/foreman_tasks/tasks_helper_test.rb
|
633
624
|
- test/lib/actions/middleware/keep_current_request_id_test.rb
|
@@ -648,9 +639,9 @@ test_files:
|
|
648
639
|
- test/unit/actions/recurring_action_test.rb
|
649
640
|
- test/unit/cleaner_test.rb
|
650
641
|
- test/unit/config/environment.rb
|
642
|
+
- test/unit/dashboard_table_filter_test.rb
|
651
643
|
- test/unit/dynflow_console_authorizer_test.rb
|
652
644
|
- test/unit/locking_test.rb
|
653
|
-
- test/unit/otp_manager_test.rb
|
654
645
|
- test/unit/proxy_selector_test.rb
|
655
646
|
- test/unit/recurring_logic_test.rb
|
656
647
|
- test/unit/remote_task_test.rb
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'foreman_tasks_core_test_helper'
|
2
|
-
require 'foreman_tasks/test_helpers'
|
3
|
-
require 'foreman_tasks_core/runner'
|
4
|
-
|
5
|
-
module ForemanTasksCore
|
6
|
-
module Runner
|
7
|
-
describe Dispatcher::RunnerActor do
|
8
|
-
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
9
|
-
|
10
|
-
let(:dispatcher) { Dispatcher.instance }
|
11
|
-
let(:suspended_action) { mock }
|
12
|
-
let(:runner) { mock.tap { |r| r.stubs(:id) } }
|
13
|
-
let(:clock) { ForemanTasks.dynflow.world.clock }
|
14
|
-
let(:logger) { mock.tap { |l| l.stubs(:debug) } }
|
15
|
-
let(:actor) do
|
16
|
-
Dispatcher::RunnerActor.new dispatcher, suspended_action, runner, clock, logger
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'delivers all updates to actions' do
|
20
|
-
targets = (0..2).map { mock }.each_with_index { |mock, index| mock.expects(:<<).with(index) }
|
21
|
-
updates = targets.each_with_index.reduce({}) { |acc, (cur, index)| acc.merge(cur => index) }
|
22
|
-
runner.expects(:run_refresh).returns(updates)
|
23
|
-
actor.expects(:plan_next_refresh)
|
24
|
-
actor.refresh_runner
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'plans next refresh' do
|
28
|
-
runner.expects(:run_refresh).returns({})
|
29
|
-
actor.expects(:plan_next_refresh)
|
30
|
-
actor.refresh_runner
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'does not plan next resfresh if done' do
|
34
|
-
update = Update.new(nil, 0)
|
35
|
-
suspended_action.expects(:<<).with(update)
|
36
|
-
runner.expects(:run_refresh).returns(suspended_action => update)
|
37
|
-
dispatcher.expects(:finish)
|
38
|
-
dispatcher.ticker.expects(:tell).never
|
39
|
-
actor.refresh_runner
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
require 'foreman_tasks_core_test_helper'
|
2
|
-
require 'foreman_tasks/test_helpers'
|
3
|
-
require 'foreman_tasks_core/runner'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
module ForemanTasksCore
|
7
|
-
module Runner
|
8
|
-
class RunnerTest < ActiveSupport::TestCase
|
9
|
-
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
10
|
-
|
11
|
-
describe Base do
|
12
|
-
let(:suspended_action) { Class.new }
|
13
|
-
let(:runner) { Base.new suspended_action: suspended_action }
|
14
|
-
|
15
|
-
describe '#generate_updates' do
|
16
|
-
it 'returns empty hash when there are no outputs' do
|
17
|
-
_(runner.generate_updates).must_be :empty?
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'returns a hash with outputs' do
|
21
|
-
message = 'a message'
|
22
|
-
type = 'stdout'
|
23
|
-
runner.publish_data(message, type)
|
24
|
-
updates = runner.generate_updates
|
25
|
-
_(updates.keys).must_equal [suspended_action]
|
26
|
-
update = updates.values.first
|
27
|
-
_(update.exit_status).must_be :nil?
|
28
|
-
_(update.continuous_output.raw_outputs.count).must_equal 1
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'works in compatibility mode' do
|
32
|
-
runner = Base.new
|
33
|
-
message = 'a message'
|
34
|
-
type = 'stdout'
|
35
|
-
runner.publish_data(message, type)
|
36
|
-
updates = runner.generate_updates
|
37
|
-
_(updates.keys).must_equal [nil]
|
38
|
-
update = updates.values.first
|
39
|
-
_(update.exit_status).must_be :nil?
|
40
|
-
_(update.continuous_output.raw_outputs.count).must_equal 1
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
describe Parent do
|
46
|
-
let(:suspended_action) { ::Dynflow::Action::Suspended.allocate }
|
47
|
-
let(:runner) { Parent.new targets, suspended_action: suspended_action }
|
48
|
-
let(:targets) do
|
49
|
-
{ 'foo' => { 'execution_plan_id' => '123', 'run_step_id' => 2 },
|
50
|
-
'bar' => { 'execution_plan_id' => '456', 'run_step_id' => 2 } }
|
51
|
-
end
|
52
|
-
|
53
|
-
describe '#initialize_continuous_outputs' do
|
54
|
-
it 'initializes outputs for targets and parent' do
|
55
|
-
outputs = runner.initialize_continuous_outputs
|
56
|
-
_(outputs.keys.count).must_equal 2
|
57
|
-
outputs.values.each { |output| _(output).must_be_instance_of ContinuousOutput }
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '#generate_updates' do
|
62
|
-
it 'returns only updates for hosts with pending outputs' do
|
63
|
-
_(runner.generate_updates).must_equal({})
|
64
|
-
runner.publish_data_for('foo', 'something', 'something')
|
65
|
-
updates = runner.generate_updates
|
66
|
-
_(updates.keys.count).must_equal 1
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'works without compatibility mode' do
|
70
|
-
runner.broadcast_data('something', 'stdout')
|
71
|
-
updates = runner.generate_updates
|
72
|
-
_(updates.keys.count).must_equal 2
|
73
|
-
updates.keys.each do |key|
|
74
|
-
_(key).must_be_instance_of ::Dynflow::Action::Suspended
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe '#publish_data_for' do
|
80
|
-
it 'publishes data for a single host' do
|
81
|
-
runner.publish_data_for('foo', 'message', 'stdout')
|
82
|
-
_(runner.generate_updates.keys.count).must_equal 1
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe '#broadcast_data' do
|
87
|
-
it 'publishes data for all hosts' do
|
88
|
-
runner.broadcast_data('message', 'stdout')
|
89
|
-
_(runner.generate_updates.keys.count).must_equal 2
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe '#publish_exception' do
|
94
|
-
let(:exception) do
|
95
|
-
exception = RuntimeError.new
|
96
|
-
exception.stubs(:backtrace).returns([])
|
97
|
-
exception
|
98
|
-
end
|
99
|
-
|
100
|
-
before { runner.logger.stubs(:error) }
|
101
|
-
|
102
|
-
it 'broadcasts the exception to all targets' do
|
103
|
-
runner.expects(:publish_exit_status).never
|
104
|
-
runner.publish_exception('general failure', exception, false)
|
105
|
-
_(runner.generate_updates.keys.count).must_equal 2
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'publishes exit status if fatal' do
|
109
|
-
runner.expects(:publish_exit_status)
|
110
|
-
runner.publish_exception('general failure', exception, true)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'foreman_tasks_core_test_helper'
|
2
|
-
require 'foreman_tasks/test_helpers'
|
3
|
-
|
4
|
-
module ForemanTasksCore
|
5
|
-
module TaskLauncher
|
6
|
-
class TaskLauncherTest < ActiveSupport::TestCase
|
7
|
-
include ForemanTasks::TestHelpers::WithInThreadExecutor
|
8
|
-
|
9
|
-
describe ForemanTasksCore::TaskLauncher do
|
10
|
-
let(:launcher) { launcher_class.new ForemanTasks.dynflow.world, {} }
|
11
|
-
let(:launcher_input) { { 'action_class' => Support::DummyDynflowAction.to_s, 'action_input' => input } }
|
12
|
-
let(:input) { { :do => :something } }
|
13
|
-
let(:expected_result) { input.merge(:callback_host => {}) }
|
14
|
-
|
15
|
-
describe ForemanTasksCore::TaskLauncher::Single do
|
16
|
-
let(:launcher_class) { Single }
|
17
|
-
|
18
|
-
it 'triggers an action' do
|
19
|
-
Support::DummyDynflowAction.any_instance.expects(:plan).with do |arg|
|
20
|
-
_(arg).must_equal(expected_result)
|
21
|
-
end
|
22
|
-
launcher.launch!(launcher_input)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'provides results' do
|
26
|
-
plan = launcher.launch!(launcher_input).finished.value!
|
27
|
-
_(launcher.results[:result]).must_equal 'success'
|
28
|
-
_(plan.result).must_equal :success
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe ForemanTasksCore::TaskLauncher::Batch do
|
33
|
-
let(:launcher_class) { Batch }
|
34
|
-
|
35
|
-
it 'triggers the actions' do
|
36
|
-
Support::DummyDynflowAction.any_instance.expects(:plan).with { |arg| arg == expected_result }.twice
|
37
|
-
parent = launcher.launch!('foo' => launcher_input, 'bar' => launcher_input)
|
38
|
-
plan = parent.finished.value!
|
39
|
-
_(plan.result).must_equal :success
|
40
|
-
_(plan.sub_plans.count).must_equal 2
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'provides results' do
|
44
|
-
launcher.launch!('foo' => launcher_input, 'bar' => launcher_input)
|
45
|
-
_(launcher.results.keys).must_equal %w[foo bar]
|
46
|
-
launcher.results.values.each do |result|
|
47
|
-
plan = ForemanTasks.dynflow.world.persistence.load_execution_plan(result[:task_id])
|
48
|
-
_(result[:result]).must_equal 'success'
|
49
|
-
_(plan.result).must_equal :success
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'foreman_tasks_test_helper'
|
2
|
-
require 'foreman_tasks_core/otp_manager'
|
3
|
-
|
4
|
-
module ForemanTasksCore
|
5
|
-
class OtpManagerTest < ActiveSupport::TestCase
|
6
|
-
class TestOtpManager < OtpManager
|
7
|
-
def self.reset!
|
8
|
-
@passwords = nil
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def try_to_authenticate(username, password)
|
13
|
-
TestOtpManager.authenticate(OtpManager.tokenize(username, password))
|
14
|
-
end
|
15
|
-
|
16
|
-
before do
|
17
|
-
TestOtpManager.reset!
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:username) { 'myuser' }
|
21
|
-
let(:password) { '123456789' }
|
22
|
-
let(:base64) { 'bXl1c2VyOjEyMzQ1Njc4OQ==' }
|
23
|
-
|
24
|
-
it 'it doesn\'t raise when no passwords were generated yet' do
|
25
|
-
assert_not try_to_authenticate('missing', 'password')
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'generates OTPs using SecureRandom.hex and converts them to strings' do
|
29
|
-
otp = 4
|
30
|
-
SecureRandom.stubs(:hex).returns(otp)
|
31
|
-
_(TestOtpManager.generate_otp(username)).must_equal otp.to_s
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'provides #drop_otp method that removes OTP only when correct username and password is provided' do
|
35
|
-
otp = TestOtpManager.generate_otp(username)
|
36
|
-
assert_not TestOtpManager.drop_otp('wrong_username', 'wrong_password')
|
37
|
-
assert_not TestOtpManager.drop_otp(username, 'wrong_password')
|
38
|
-
assert_not TestOtpManager.drop_otp('wrong_username', otp)
|
39
|
-
assert TestOtpManager.drop_otp(username, otp)
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'authenticate removes OTP only when correct username and password is provided' do
|
43
|
-
otp = TestOtpManager.generate_otp(username)
|
44
|
-
assert_not try_to_authenticate('wrong_username', 'wrong_password')
|
45
|
-
assert_not try_to_authenticate(username, 'wrong_password')
|
46
|
-
assert_not try_to_authenticate(username, 'wrong_password')
|
47
|
-
assert_not try_to_authenticate('wrong_username', otp)
|
48
|
-
assert try_to_authenticate(username, otp)
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'authenticates correctly' do
|
52
|
-
SecureRandom.stubs(:hex).returns(password)
|
53
|
-
TestOtpManager.generate_otp(username)
|
54
|
-
|
55
|
-
assert TestOtpManager.authenticate(base64)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'OTPs can be used only once' do
|
59
|
-
SecureRandom.stubs(:hex).returns(password)
|
60
|
-
TestOtpManager.generate_otp(username)
|
61
|
-
|
62
|
-
assert TestOtpManager.authenticate(base64)
|
63
|
-
assert_not TestOtpManager.authenticate(base64)
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'creates token from username and password correctly' do
|
67
|
-
_(TestOtpManager.tokenize(username, password)).must_equal base64
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'overwrites old OTP when generating a new one for the same username' do
|
71
|
-
old = TestOtpManager.generate_otp(username)
|
72
|
-
new = TestOtpManager.generate_otp(username)
|
73
|
-
assert_not try_to_authenticate(username, old)
|
74
|
-
assert try_to_authenticate(username, new)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|