foreman-tasks 4.1.5 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby_tests.yml +0 -1
  3. data/.rubocop.yml +0 -4
  4. data/.rubocop_todo.yml +0 -2
  5. data/README.md +8 -6
  6. data/app/assets/javascripts/foreman_tasks/trigger_form.js +7 -0
  7. data/app/controllers/foreman_tasks/api/tasks_controller.rb +2 -2
  8. data/app/controllers/foreman_tasks/tasks_controller.rb +2 -2
  9. data/app/graphql/mutations/recurring_logics/cancel.rb +27 -0
  10. data/app/graphql/types/recurring_logic.rb +21 -0
  11. data/app/graphql/types/task.rb +25 -0
  12. data/app/graphql/types/triggering.rb +16 -0
  13. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +4 -1
  14. data/app/lib/actions/helpers/with_continuous_output.rb +1 -1
  15. data/app/lib/actions/proxy_action.rb +2 -12
  16. data/app/lib/actions/trigger_proxy_batch.rb +79 -0
  17. data/app/models/foreman_tasks/recurring_logic.rb +10 -0
  18. data/app/models/foreman_tasks/remote_task.rb +3 -19
  19. data/app/models/foreman_tasks/task.rb +29 -0
  20. data/app/models/foreman_tasks/triggering.rb +14 -4
  21. data/app/views/foreman_tasks/api/tasks/show.json.rabl +1 -1
  22. data/app/views/foreman_tasks/layouts/react.html.erb +0 -1
  23. data/app/views/foreman_tasks/recurring_logics/index.html.erb +4 -2
  24. data/app/views/foreman_tasks/task_groups/recurring_logic_task_groups/_recurring_logic_task_group.html.erb +8 -0
  25. data/db/migrate/20210720115251_add_purpose_to_recurring_logic.rb +6 -0
  26. data/extra/foreman-tasks-cleanup.sh +127 -0
  27. data/extra/foreman-tasks-export.sh +121 -0
  28. data/foreman-tasks.gemspec +1 -4
  29. data/lib/foreman_tasks/continuous_output.rb +50 -0
  30. data/lib/foreman_tasks/engine.rb +8 -15
  31. data/lib/foreman_tasks/tasks/export_tasks.rake +29 -8
  32. data/lib/foreman_tasks/version.rb +1 -1
  33. data/lib/foreman_tasks.rb +2 -5
  34. data/locale/fr/LC_MESSAGES/foreman_tasks.mo +0 -0
  35. data/locale/ja/LC_MESSAGES/foreman_tasks.mo +0 -0
  36. data/locale/zh_CN/LC_MESSAGES/foreman_tasks.mo +0 -0
  37. data/package.json +7 -9
  38. data/test/controllers/api/tasks_controller_test.rb +19 -1
  39. data/test/controllers/tasks_controller_test.rb +19 -0
  40. data/test/factories/recurring_logic_factory.rb +7 -1
  41. data/test/graphql/mutations/recurring_logics/cancel_mutation_test.rb +66 -0
  42. data/test/graphql/queries/recurring_logic_test.rb +28 -0
  43. data/test/graphql/queries/recurring_logics_query_test.rb +30 -0
  44. data/test/graphql/queries/task_query_test.rb +33 -0
  45. data/test/graphql/queries/tasks_query_test.rb +31 -0
  46. data/test/support/dummy_proxy_action.rb +6 -0
  47. data/test/unit/actions/proxy_action_test.rb +11 -11
  48. data/test/unit/actions/trigger_proxy_batch_test.rb +59 -0
  49. data/test/unit/remote_task_test.rb +0 -8
  50. data/test/unit/task_test.rb +39 -8
  51. data/test/unit/triggering_test.rb +22 -0
  52. metadata +23 -26
  53. data/test/core/unit/dispatcher_test.rb +0 -43
  54. data/test/core/unit/runner_test.rb +0 -116
  55. data/test/core/unit/task_launcher_test.rb +0 -56
  56. data/test/foreman_tasks_core_test_helper.rb +0 -4
  57. data/test/unit/otp_manager_test.rb +0 -77
@@ -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,4 +0,0 @@
1
- require 'foreman_tasks_test_helper'
2
- require 'foreman_tasks_core'
3
-
4
- ForemanTasksCore.dynflow_setup ForemanTasks.dynflow.world
@@ -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