foreman-tasks 4.0.0 → 5.0.0

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby_tests.yml +4 -3
  3. data/app/controllers/concerns/foreman_tasks/find_tasks_common.rb +14 -0
  4. data/app/controllers/foreman_tasks/api/tasks_controller.rb +4 -6
  5. data/app/controllers/foreman_tasks/tasks_controller.rb +3 -11
  6. data/app/graphql/types/recurring_logic.rb +18 -0
  7. data/app/graphql/types/task.rb +25 -0
  8. data/app/graphql/types/triggering.rb +16 -0
  9. data/app/lib/actions/helpers/with_continuous_output.rb +1 -1
  10. data/app/lib/actions/middleware/load_setting_values.rb +35 -0
  11. data/app/lib/actions/observable_action.rb +1 -1
  12. data/app/lib/actions/proxy_action.rb +2 -4
  13. data/app/models/foreman_tasks/recurring_logic.rb +2 -0
  14. data/app/models/foreman_tasks/task.rb +30 -2
  15. data/app/models/foreman_tasks/triggering.rb +2 -0
  16. data/db/migrate/20180927120509_add_user_id.foreman_tasks.rb +4 -2
  17. data/foreman-tasks.gemspec +0 -1
  18. data/lib/foreman_tasks.rb +2 -5
  19. data/lib/foreman_tasks/continuous_output.rb +50 -0
  20. data/lib/foreman_tasks/engine.rb +7 -15
  21. data/lib/foreman_tasks/version.rb +1 -1
  22. data/locale/action_names.rb +3 -2
  23. data/locale/en/foreman_tasks.po +60 -27
  24. data/locale/foreman_tasks.pot +180 -132
  25. data/locale/fr/foreman_tasks.po +61 -28
  26. data/locale/ja/foreman_tasks.po +61 -28
  27. data/locale/zh_CN/foreman_tasks.po +61 -28
  28. data/test/controllers/api/tasks_controller_test.rb +16 -1
  29. data/test/controllers/tasks_controller_test.rb +2 -2
  30. data/test/factories/task_factory.rb +31 -4
  31. data/test/graphql/queries/recurring_logic_test.rb +28 -0
  32. data/test/graphql/queries/recurring_logics_query_test.rb +30 -0
  33. data/test/graphql/queries/task_query_test.rb +33 -0
  34. data/test/graphql/queries/tasks_query_test.rb +31 -0
  35. data/test/unit/actions/proxy_action_test.rb +4 -1
  36. data/test/unit/task_test.rb +54 -23
  37. data/test/unit/triggering_test.rb +2 -2
  38. metadata +16 -26
  39. data/test/core/unit/dispatcher_test.rb +0 -43
  40. data/test/core/unit/runner_test.rb +0 -129
  41. data/test/core/unit/task_launcher_test.rb +0 -56
  42. data/test/foreman_tasks_core_test_helper.rb +0 -4
  43. 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