foreman_scc_manager 1.8.9 → 1.8.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab78f155bda869b47a6124ada7ebcdf9d067c6173c400dfd9c052c70227695f9
4
- data.tar.gz: '009d1c1db82b1c52e4e0ab47ebdb1769dbb4ea0e71fb6a2a0b5b26fff5b0cb41'
3
+ metadata.gz: d9bb11cd54075948f57fe205b39e75e2d2bac3092cdcd3c1f15e9101bfaa0b3c
4
+ data.tar.gz: 61351f372d614b5de85b9ec6f490f08bea0c7b1848b06b66b89ca78fd6b4ca29
5
5
  SHA512:
6
- metadata.gz: da25af4b803899a68ef9b3fae9646901437051d5b69dd4b5c588cca5e0018ea0b797d32255ed4dc5ba6ccb5044a119c2d712bb3b35905aeb231182145f910878
7
- data.tar.gz: 15b7aa5a3f7a05e3c517aa6aa41fcef1c9bee3fb00d5f49405166264d21a7857fc348940c06a0279d88330d29b7480e90d2f3e32025ee2bcba95c1acf84f1c7b
6
+ metadata.gz: 8eb54567950e62fef53342af59aa070cf0f45c31832c8869b181250c20953b5850024ded8792ce2abd7a2c947b6317d86ac99a5038f97ffdb61f67728a2a50b8
7
+ data.tar.gz: ea314767654f27ab0d26097ccc235fbf83fb426e46ef242284f0da8572cc1dcdfe44d2966b471a177c45bf8fbe99c857105b653f61883e39441b021cf9f67c48
@@ -2,7 +2,7 @@ class SccAccountsController < ApplicationController
2
2
  helper_method :scc_filtered_products
3
3
  before_action :find_organization
4
4
  before_action :find_resource, only: %i[show edit update destroy sync bulk_subscribe]
5
- before_action :find_available_gpg_keys, only: %i[new edit]
5
+ before_action :find_available_gpg_keys, only: %i[new edit update create]
6
6
  include Foreman::Controller::AutoCompleteSearch
7
7
 
8
8
  # GET /scc_accounts
@@ -45,12 +45,7 @@ class SccAccount < ApplicationRecord
45
45
  end
46
46
 
47
47
  def sync_date_is_valid_datetime
48
- errors.add(:sync_date, 'must be a valid datetime') if interval != NEVER &&
49
- sync_date.present? &&
50
- !sync_date.respond_to?(:min) &&
51
- !sync_date.respond_to?(:hour) &&
52
- !sync_date.respond_to?(:wday) &&
53
- !sync_date.respond_to?(:day)
48
+ errors.add(:sync_date, 'must be a valid datetime') if interval != NEVER && sync_date.blank?
54
49
  end
55
50
 
56
51
  def to_s
@@ -104,7 +99,7 @@ class SccAccount < ApplicationRecord
104
99
  end
105
100
 
106
101
  def add_recurring_logic(sync_date, interval)
107
- sd = sync_date
102
+ sd = sync_date.presence || Time.now
108
103
 
109
104
  raise _('Interval cannot be nil') if interval.nil?
110
105
 
@@ -0,0 +1,19 @@
1
+ class AddPermissions < ActiveRecord::Migration[6.0]
2
+ PERMISSIONS = [
3
+ { 'name' => 'view_scc_products', 'resource_type' => 'SccProduct' },
4
+ { 'name' => 'subscribe_scc_products', 'resource_type' => 'SccProduct' },
5
+ { 'name' => 'test_connection_scc_accounts', 'resource_type' => 'SccAccount' }
6
+ ].freeze
7
+
8
+ def up
9
+ PERMISSIONS.each do |p|
10
+ Permission.find_or_create_by(:name => p['name'], :resource_type => p['resource_type'])
11
+ end
12
+ end
13
+
14
+ def down
15
+ PERMISSIONS.each do |p|
16
+ Permission.where(:name => p['name']).destroy_all
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module ForemanSccManager
2
- VERSION = '1.8.9'.freeze
2
+ VERSION = '1.8.10'.freeze
3
3
  end
@@ -208,13 +208,52 @@ class Api::V2::SccAccountsControllerTest < ActionController::TestCase
208
208
  assert_response :ok
209
209
  end
210
210
 
211
- test 'should refuse update scc_account' do
211
+ test 'should refuse update scc_account with invalid interval' do
212
212
  account = scc_accounts(:two)
213
213
  put :update, params: { id: account.id, :scc_account => { :interval => 'yearly' } }
214
214
  assert_equal 'yearly', assigns(:scc_account).interval
215
215
  assert_response :unprocessable_entity
216
216
  end
217
217
 
218
+ test 'should refuse update scc_account with empty date' do
219
+ account = scc_accounts(:two)
220
+ put :update, params: { id: account.id, :scc_account => { :interval => 'weekly', :sync_date => '' } }
221
+ assert_response :unprocessable_entity
222
+ assert_error_message 'Sync date must be a valid datetime'
223
+ end
224
+
225
+ test 'should fail to update scc_account with interval set and invalid date' do
226
+ account = scc_accounts(:two)
227
+ put :update, params: { id: account.id, :scc_account => { :sync_date => 'invalid_date', :interval => 'weekly' } }
228
+
229
+ assert_response :unprocessable_entity
230
+ assert_error_message 'Sync date must be a valid datetime'
231
+ end
232
+
233
+ test 'should fail to update scc_account with empty name' do
234
+ account = scc_accounts(:two)
235
+ put :update, params: { id: account.id, :scc_account => { :name => '', :sync_date => Time.now, :interval => 'weekly' } }
236
+
237
+ assert_response :unprocessable_entity
238
+ assert_error_message "Name can't be blank"
239
+ end
240
+
241
+ test 'should fail to update scc_account with empty login' do
242
+ account = scc_accounts(:two)
243
+ put :update, params: { id: account.id, :scc_account => { :login => '', :sync_date => Time.now, :interval => 'weekly' } }
244
+
245
+ assert_response :unprocessable_entity
246
+ assert_error_message "Login can't be blank"
247
+ end
248
+
249
+ test 'should fail to update scc_account with empty base_url' do
250
+ account = scc_accounts(:two)
251
+ put :update, params: { id: account.id, :scc_account => { :base_url => '', :sync_date => Time.now, :interval => 'weekly' } }
252
+
253
+ assert_response :unprocessable_entity
254
+ assert_error_message "Base url can't be blank"
255
+ end
256
+
218
257
  test 'new account SCC server connection-test' do
219
258
  scc_setup
220
259
  account = scc_accounts(:one)
@@ -305,4 +344,10 @@ class Api::V2::SccAccountsControllerTest < ActionController::TestCase
305
344
  end
306
345
  assert_response :ok
307
346
  end
347
+
348
+ private
349
+
350
+ def assert_error_message(message)
351
+ assert_includes JSON.parse(response.body)['error']['full_messages'], message
352
+ end
308
353
  end
@@ -69,8 +69,58 @@ class SccAccountsControllerTest < ActionController::TestCase
69
69
  test 'should update scc_account' do
70
70
  account = scc_accounts(:two)
71
71
  put :update, params: { id: account.id, :scc_account => { :sync_date => Time.now, :interval => 'weekly' } }, session: set_session_user
72
+ assert_redirected_to '/scc_accounts'
73
+ assert_equal 'weekly', SccAccount.find(account.id).interval
74
+ end
75
+
76
+ test 'should update scc_account with empty date if interval not set' do
77
+ account = scc_accounts(:two)
78
+ put :update, params: { id: account.id, :scc_account => { :name => 'new_name', :sync_date => '', :interval => 'never' } }, session: set_session_user
79
+
80
+ assert_equal 'new_name', SccAccount.find(account.id).name
81
+ end
82
+
83
+ test 'updates scc_account even if the date is invalid' do
84
+ # @todo reminder to fix this in the future
85
+ account = scc_accounts(:two)
86
+ put :update, params: { id: account.id, :scc_account => { :name => 'new_name', :sync_date => 'invalid_date', :interval => 'never' } }, session: set_session_user
87
+
88
+ assert_not_equal account.name, SccAccount.find(account.id).name
89
+ end
90
+
91
+ test 'should fail to update scc_account with interval set and empty date' do
92
+ account = scc_accounts(:two)
93
+ put :update, params: { id: account.id, :scc_account => { :sync_date => '', :interval => 'weekly' } }, session: set_session_user
94
+
95
+ assert_equal SccAccount.find(account.id).sync_date, account.sync_date
96
+ end
97
+
98
+ test 'should fail to update scc_account with interval set and invalid date' do
99
+ account = scc_accounts(:two)
100
+ put :update, params: { id: account.id, :scc_account => { :sync_date => 'invalid_date', :interval => 'weekly' } }, session: set_session_user
101
+
102
+ assert_equal SccAccount.find(account.id).sync_date, account.sync_date
103
+ end
104
+
105
+ test 'should fail to update scc_account with empty name' do
106
+ account = scc_accounts(:two)
107
+ put :update, params: { id: account.id, :scc_account => { :name => '', :sync_date => Time.now, :interval => 'weekly' } }, session: set_session_user
108
+
109
+ assert_equal account.name, SccAccount.find(account.id).name
110
+ end
111
+
112
+ test 'should fail to update scc_account with empty login' do
113
+ account = scc_accounts(:two)
114
+ put :update, params: { id: account.id, :scc_account => { :login => '', :sync_date => Time.now, :interval => 'weekly' } }, session: set_session_user
115
+
116
+ assert_equal account.login, SccAccount.find(account.id).login
117
+ end
118
+
119
+ test 'should fail to update scc_account with empty base url' do
120
+ account = scc_accounts(:two)
121
+ put :update, params: { id: account.id, :scc_account => { :base_url => '', :sync_date => Time.now, :interval => 'weekly' } }, session: set_session_user
72
122
 
73
- assert_equal 'weekly', assigns(:scc_account).interval
123
+ assert_equal account.base_url, SccAccount.find(account.id).base_url
74
124
  end
75
125
 
76
126
  test 'SCC server sync products' do
@@ -6,6 +6,7 @@ one:
6
6
  name: onename
7
7
  interval: never
8
8
  organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %>
9
+ sync_date: Time.now
9
10
 
10
11
  two:
11
12
  login: twouser
@@ -14,6 +15,7 @@ two:
14
15
  name: twoname
15
16
  interval: never
16
17
  organization_id: <%= ActiveRecord::FixtureSet.identify(:empty_organization) %>
18
+ sync_date: 2021-07-05T21:33:49
17
19
 
18
20
  account_missing_url:
19
21
  login: fakeuser1
@@ -0,0 +1,16 @@
1
+ require 'test_plugin_helper'
2
+ require 'unit/shared/access_permissions_test_base'
3
+
4
+ # Permissions are added in AccessPermissions with lists of controllers and
5
+ # actions that they enable access to. For non-admin users, we need to test
6
+ # that there are permissions available that cover every controller action, else
7
+ # it can't be delegated and this will lead to parts of the application that
8
+ # aren't functional for non-admin users.
9
+ #
10
+ # In particular, it's important that actions for AJAX requests are added to
11
+ # an appropriate permission so views using those requests function.
12
+ class AccessPermissionsTest < ActiveSupport::TestCase
13
+ include AccessPermissionsTestBase
14
+
15
+ check_routes(ForemanSccManager::Engine.routes, [])
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_scc_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.9
4
+ version: 1.8.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - ATIX AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-27 00:00:00.000000000 Z
11
+ date: 2021-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -158,6 +158,7 @@ files:
158
158
  - db/migrate/20210205082733_add_subscription_valid_to_scc_products_and_repos.rb
159
159
  - db/migrate/20210210104407_add_root_repository_id_to_scc_repository.rb
160
160
  - db/migrate/20210224095050_connect_katello_root_repository_to_scc_repository.rb
161
+ - db/migrate/20210713092440_add_permissions.rb
161
162
  - lib/foreman_scc_manager.rb
162
163
  - lib/foreman_scc_manager/engine.rb
163
164
  - lib/foreman_scc_manager/version.rb
@@ -194,6 +195,7 @@ files:
194
195
  - test/support/fixtures_support.rb
195
196
  - test/test_controller_helper.rb
196
197
  - test/test_plugin_helper.rb
198
+ - test/unit/access_permissions_test.rb
197
199
  - test/unit/foreman_scc_manager_test.rb
198
200
  homepage: https://www.orcharhino.com/
199
201
  licenses:
@@ -219,6 +221,7 @@ signing_key:
219
221
  specification_version: 4
220
222
  summary: Suse Customer Center plugin for Foreman
221
223
  test_files:
224
+ - test/unit/access_permissions_test.rb
222
225
  - test/unit/foreman_scc_manager_test.rb
223
226
  - test/test_controller_helper.rb
224
227
  - test/features/sync_test.rb