cul_omniauth 0.4.3 → 0.5.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a7d79b0f43eeca5c75a633f01fe939ddcc798e5a
4
- data.tar.gz: a09213d0e00ca9642955507fba71d1e940fbcc30
2
+ SHA256:
3
+ metadata.gz: 256693f7dfea34961802ebcc0ddfbdc63c6ffba5e2e64c37867cc8974182dcad
4
+ data.tar.gz: 2152d4fa6aa5880e909a0d2f2de087130d09359f3275e9498fe75c42b2fd5f4e
5
5
  SHA512:
6
- metadata.gz: 977bed10ff96bfcc48668b99313076c2267bf8023071709be49d8d51a2de37317e1dc3bfe2ed00d065b8bd6f84658be2c7ff63623a50c50d3db18f9ff651ccbd
7
- data.tar.gz: bc39d14929e69cbd30e50aeab065f069c8c14cdf935d484dd48ab1341291468ce97d7e65c35a8396e67e8f86800cec0d058c51d1b1a28d3103b23468d0ef50ef
6
+ metadata.gz: 7ef5c36b7e5fbdd799f76aeb4cfb0b977db1ab03ba93772aebd82ef314565106b77a4e759a78225746425cc9e53df558f3c67f366464c3fb4a5d730b01a912a1
7
+ data.tar.gz: 29cc800ed27409b46d77357bca0e0b1dee9e85262715d3e2e1de6b96c98e7cb33e6b75edf76a4f6cb30e3b458f0f811a6ea1f0e163e1c145612effa262379cfa
@@ -28,7 +28,12 @@ module Cul::Omniauth::Callbacks
28
28
  affiliations(@current_user,affils)
29
29
  session["devise.roles"] = affils
30
30
  if @current_user && @current_user.persisted?
31
- flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: auth_type
31
+ message = I18n.t "devise.omniauth_callbacks.success", kind: auth_type
32
+ if message.blank?
33
+ flash.delete(:notice)
34
+ else
35
+ flash[:notice] = message
36
+ end
32
37
  sign_in_and_redirect @current_user, :event => :authentication
33
38
  else
34
39
  reason = @current_user ? 'no persisted user for id' : 'no uid in token'
@@ -5,17 +5,21 @@ module Cul::Omniauth::Abilities
5
5
  ARRAY = [].freeze
6
6
  end
7
7
  def initialize(user=nil, opts={})
8
- @user = user || User.new
9
- roles = opts[:roles] || Empty::HASH
10
8
  if user
9
+ @user = user
10
+ opts = {user_id: user.uid}.merge(opts)
11
+ else
12
+ @user = User.new
13
+ end
14
+ roles = opts[:roles] || Empty::HASH
15
+ if @user
11
16
  role_permissions = self.class.config.select do |role,config|
12
- roles.include?(role) or user.role?(role)
17
+ roles.include?(role) or @user.role?(role)
13
18
  end
14
- role_permissions[:'*'] = self.class.config.fetch(:*,Empty::HASH)
15
- opts = {user_id: user.uid}.merge(opts)
16
19
  else
17
- role_permissions = {:'*' => self.class.config.fetch(:*,Empty::HASH)}
20
+ role_permissions = {}
18
21
  end
22
+ role_permissions[:'*'] = self.class.config.fetch(:*,Empty::HASH)
19
23
  role_permissions.each do |role, config|
20
24
  config.fetch(:can,Empty::HASH).each do |action, conditions|
21
25
  if conditions.blank?
@@ -0,0 +1,12 @@
1
+ module Cul::Omniauth::Users::ConfiguredRoles
2
+ extend ActiveSupport::Concern
3
+ def role? role_sym
4
+ super || begin
5
+ found = false
6
+ found = role_members(role_sym).detect {|member| self.role?(member.to_sym)}
7
+ end
8
+ end
9
+ def role_members(role_sym)
10
+ Ability.config.fetch(role_sym.to_sym,{}).fetch(:members,[])
11
+ end
12
+ end
@@ -1,5 +1,5 @@
1
1
  module Cul
2
2
  module Omniauth
3
- VERSION = "0.4.3"
3
+ VERSION = "0.5.5"
4
4
  end
5
- end
5
+ end
@@ -79,7 +79,9 @@ module OmniAuth
79
79
  end
80
80
 
81
81
  def login_url(service)
82
- cas_url + append_params(options.login_url, { TARGET: service })
82
+ target_url = service.split('?').first
83
+ parms = { TARGET: target_url }
84
+ cas_url + append_params(options.login_url, parms)
83
85
  end
84
86
  def logout_url(service)
85
87
  cas_url + append_params(options.logout_url, { service: service})
@@ -117,11 +119,10 @@ module OmniAuth
117
119
  end
118
120
 
119
121
  def service_validate_url(service_url, ticket)
120
- service_url = Addressable::URI.parse(service_url).origin
122
+ target_url = service_url.split('?').first
123
+
121
124
  parms = {
122
- TARGET: service_url,
123
- # service: service_url,
124
- # ticket: ticket
125
+ TARGET: target_url,
125
126
  }
126
127
  r = cas_url + append_params(options.service_validate_url, parms)
127
128
  r
@@ -8,7 +8,7 @@ module OmniAuth
8
8
  class ServiceTicketValidator < OmniAuth::Strategies::CAS::ServiceTicketValidator
9
9
  ART_TEMPLATE = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
10
10
  "<SOAP-ENV:Header/><SOAP-ENV:Body>" +
11
- "<samlp:Request IssueInstant=\"%s\" MajorVersion=\"1\" MinorVersion=\"1\" xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\">" +
11
+ "<samlp:Request IssueInstant=\"%s\" RequestID=\"%s\" MajorVersion=\"1\" MinorVersion=\"1\" xmlns:samlp=\"urn:oasis:names:tc:SAML:1.0:protocol\">" +
12
12
  "<samlp:AssertionArtifact>%s</samlp:AssertionArtifact>" +
13
13
  "</samlp:Request>" +
14
14
  "</SOAP-ENV:Body>" +
@@ -52,7 +52,7 @@ module OmniAuth
52
52
  end
53
53
  end
54
54
  def get_service_request_body
55
- ART_TEMPLATE % [Time.now.utc.iso8601(3), @ticket]
55
+ ART_TEMPLATE % [Time.now.utc.iso8601(3), SecureRandom.hex(16), @ticket]
56
56
  end
57
57
  # retrieves the `<sprot:Response>` XML from the CAS server
58
58
  def get_service_response_body
@@ -22,8 +22,8 @@ namespace :cul_omniauth do
22
22
  end
23
23
 
24
24
  rescue LoadError => e
25
- puts "[Warning] Exception creating rspec rake tasks. This message can be ignored in environments that intentionally do not pull in the RSpec gem (i.e. production)."
26
- puts e
25
+ # https://github.com/rspec/rspec-core/issues/1638
26
+ # rspec is not available
27
27
  end
28
28
  desc "Execute specs with coverage"
29
29
  task :coverage do
@@ -1,124 +1,3 @@
1
-  (0.1ms) begin transaction
2
- ---------------------------
3
- CulOmniauthTest: test_truth
4
- ---------------------------
5
-  (0.0ms) rollback transaction
6
-  (0.1ms) begin transaction
7
- ---------------------------
8
- CulOmniauthTest: test_truth
9
- ---------------------------
10
-  (0.0ms) rollback transaction
11
-  (0.1ms) begin transaction
12
- ---------------------------
13
- CulOmniauthTest: test_truth
14
- ---------------------------
15
-  (0.0ms) rollback transaction
16
-  (0.2ms) begin transaction
17
- ------------------------------------------------------------------
18
- OmniAuth::Strategies::WIND::ServiceTicketValidatorTest: test_truth
19
- ------------------------------------------------------------------
20
-  (0.0ms) rollback transaction
21
-  (0.0ms) begin transaction
22
- ---------------------------
23
- CulOmniauthTest: test_truth
24
- ---------------------------
25
-  (0.0ms) rollback transaction
26
-  (0.1ms) begin transaction
27
- ----------------------------------------------------------------------------
28
- OmniAuth::Strategies::WIND::ServiceTicketValidatorTest: test_success_parsing
29
- ----------------------------------------------------------------------------
30
-  (0.0ms) rollback transaction
31
-  (0.0ms) begin transaction
32
- ------------------------------------------------------------------
33
- OmniAuth::Strategies::WIND::ServiceTicketValidatorTest: test_truth
34
- ------------------------------------------------------------------
35
-  (0.0ms) rollback transaction
36
-  (0.0ms) begin transaction
37
- ---------------------------
38
- CulOmniauthTest: test_truth
39
- ---------------------------
40
-  (0.0ms) rollback transaction
41
-  (0.1ms) begin transaction
42
- ---------------------------
43
- CulOmniauthTest: test_truth
44
- ---------------------------
45
-  (0.0ms) rollback transaction
46
-  (0.1ms) begin transaction
47
- ---------------------------
48
- CulOmniauthTest: test_truth
49
- ---------------------------
50
-  (0.0ms) rollback transaction
51
-  (0.1ms) begin transaction
52
- ---------------------------
53
- CulOmniauthTest: test_truth
54
- ---------------------------
55
-  (0.0ms) rollback transaction
56
-  (0.1ms) begin transaction
57
- ---------------------------
58
- CulOmniauthTest: test_truth
59
- ---------------------------
60
-  (0.0ms) rollback transaction
61
-  (0.1ms) begin transaction
62
- ---------------------------
63
- CulOmniauthTest: test_truth
64
- ---------------------------
65
-  (0.0ms) rollback transaction
66
-  (0.1ms) begin transaction
67
- ---------------------------
68
- CulOmniauthTest: test_truth
69
- ---------------------------
70
-  (0.0ms) rollback transaction
71
-  (0.1ms) begin transaction
72
- ---------------------------
73
- CulOmniauthTest: test_truth
74
- ---------------------------
75
-  (0.0ms) rollback transaction
76
-  (0.1ms) begin transaction
77
- ---------------------------------------------------
78
- CulOmniauthTest: test_FailureApp_provider_overrides
79
- ---------------------------------------------------
80
-  (0.1ms) rollback transaction
81
-  (0.1ms) begin transaction
82
- ----------------------------
83
- CulOmniauthTest: test_module
84
- ----------------------------
85
-  (0.1ms) rollback transaction
86
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
87
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
88
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
89
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
90
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
91
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
92
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
93
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
94
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
95
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
96
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
97
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
98
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
99
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
100
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
101
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
102
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
103
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
104
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
105
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
106
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
107
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
108
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
109
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
110
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
111
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
112
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
113
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
114
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
115
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
116
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
117
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
118
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
119
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
120
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
121
- no persisted user for id {"uid"=>"foo", "extra"=>{}}
122
1
  no persisted user for id {"uid"=>"foo", "extra"=>{}}
123
2
  no persisted user for id {"uid"=>"foo", "extra"=>{}}
124
3
  no persisted user for id {"uid"=>"foo", "extra"=>{}}
@@ -163,4 +163,30 @@ describe Cul::Omniauth::Abilities do
163
163
  end
164
164
  end
165
165
  end
166
+
167
+ context "with no user" do
168
+ let(:current_user) { nil }
169
+ let(:rules) do
170
+ YAML.load(fixture('test/role_config/members.yml').read)['_all_environments']
171
+ end
172
+ before do
173
+ Ability.instance_variable_set :@role_proxy_config, symbolize_hash_keys(rules)
174
+ rig.instance_variable_set :@current_ability, nil
175
+ end
176
+ after do
177
+ Ability.instance_variable_set :@role_proxy_config, nil
178
+ end
179
+ subject do
180
+ rig.current_ability
181
+ end
182
+ it "has abilities of *" do
183
+ expect(subject.can? :index, proxy).to be
184
+ end
185
+ it "has abilities of roles with member *" do
186
+ expect(subject.can? :download, proxy).to be
187
+ end
188
+ it "doesn't have unexpected abilities" do
189
+ expect(subject.can? :update, proxy).not_to be
190
+ end
191
+ end
166
192
  end
@@ -59,6 +59,21 @@ describe Cul::Omniauth::Callbacks do
59
59
  subject.send method.downcase.to_sym
60
60
  expect(rig.flash[:notice]).to be
61
61
  end
62
+ context "and success translation is empty" do
63
+ before do
64
+ I18n.load_path.unshift fixture_path(File.join('test', 'locales', 'translation.en.yml'))
65
+ I18n.backend.reload!
66
+ end
67
+ after do
68
+ I18n.load_path.shift
69
+ I18n.backend.reload!
70
+ end
71
+ it do
72
+ is_expected.to receive(:sign_in_and_redirect)
73
+ subject.send method.downcase.to_sym
74
+ expect(rig.flash[:notice]).not_to be
75
+ end
76
+ end
62
77
  context "no current_user" do
63
78
  before do
64
79
  rig.instance_variable_set :@current_user, nil
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cul::Omniauth::Users::ConfiguredRoles do
4
+
5
+ it do
6
+ is_expected.to be_a Module
7
+ end
8
+ context "is included" do
9
+ let(:uid) { 'foo' }
10
+ let(:rules) do
11
+ YAML.load(fixture('test/role_config/members.yml').read)['_all_environments']
12
+ end
13
+ let(:test_class) {
14
+ c = Class.new(User)
15
+ c.class_eval do
16
+ attr_accessor :request, :flash, :session
17
+ include Cul::Omniauth::Users::ConfiguredRoles
18
+ end
19
+ c
20
+ }
21
+
22
+ before do
23
+ Ability.instance_variable_set :@role_proxy_config, symbolize_hash_keys(rules)
24
+ end
25
+
26
+ after do
27
+ Ability.instance_variable_set :@role_proxy_config, nil
28
+ end
29
+
30
+ subject { test_class.new }
31
+
32
+ context "a role as ad-hoc members" do
33
+ it 'should find memberships one level removed' do
34
+ expect(subject.role? 'one_level').to be
35
+ end
36
+ it 'should find memberships several levels removed' do
37
+ expect(subject.role? 'three_level').to be
38
+ end
39
+ it 'should still return false for other roles' do
40
+ expect(subject.role? 'none_level').not_to be
41
+ end
42
+ end
43
+ end
44
+ end
@@ -28,6 +28,10 @@ if ActiveSupport::TestCase.method_defined?(:fixture_path=)
28
28
  ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
29
29
  end
30
30
 
31
+ def fixture_path(filename)
32
+ path = File.join(File.dirname(__FILE__),'..','fixtures',filename)
33
+ end
34
+
31
35
  def fixture(filename, mode="r")
32
36
  path = File.join(File.dirname(__FILE__),'..','fixtures',filename)
33
37
  if block_given?
@@ -57,4 +61,5 @@ class User
57
61
  def self.devise(*args); end
58
62
  def persisted?; persisted; end
59
63
  include Cul::Omniauth::Users
64
+ include Cul::Omniauth::Users::ConfiguredRoles
60
65
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cul_omniauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - barmintor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-02 00:00:00.000000000 Z
11
+ date: 2020-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 3.0.0
89
+ version: '3.5'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 3.0.0
96
+ version: '3.5'
97
97
  description: Engine and model mixins for Omniauth with CAS and SSL.
98
98
  email:
99
99
  - LASTNAME at gmail
@@ -113,6 +113,7 @@ files:
113
113
  - app/helpers/cul/omniauth/application_helper.rb
114
114
  - app/models/concerns/cul/omniauth/abilities.rb
115
115
  - app/models/concerns/cul/omniauth/users.rb
116
+ - app/models/concerns/cul/omniauth/users/configured_roles.rb
116
117
  - app/views/layouts/cul/omniauth/application.html.erb
117
118
  - config/locales/cul_omniauth.en.yml
118
119
  - config/routes.rb
@@ -170,6 +171,7 @@ files:
170
171
  - spec/lib/cul/omniauth/abilities_spec.rb
171
172
  - spec/lib/cul/omniauth/callbacks_spec.rb
172
173
  - spec/lib/cul/omniauth/remote_ip_ability_spec.rb
174
+ - spec/lib/cul/omniauth/users/configured_roles_spec.rb
173
175
  - spec/lib/cul/omniauth/users_spec.rb
174
176
  - spec/lib/omni_auth/strategies/saml/service_ticket_validator_spec.rb
175
177
  - spec/lib/omni_auth/strategies/wind/service_ticket_validator_spec.rb
@@ -193,55 +195,54 @@ required_rubygems_version: !ruby/object:Gem::Requirement
193
195
  - !ruby/object:Gem::Version
194
196
  version: '0'
195
197
  requirements: []
196
- rubyforge_project:
197
- rubygems_version: 2.4.6
198
+ rubygems_version: 3.0.8
198
199
  signing_key:
199
200
  specification_version: 4
200
201
  summary: Omniauth engine for CUL web apps.
201
202
  test_files:
202
- - spec/cul_omniauth_spec.rb
203
+ - spec/spec_helper.rb
204
+ - spec/dummy/app/controllers/application_controller.rb
205
+ - spec/dummy/app/views/layouts/application.html.erb
203
206
  - spec/dummy/app/assets/javascripts/application.js
204
207
  - spec/dummy/app/assets/stylesheets/application.css
205
- - spec/dummy/app/controllers/application_controller.rb
206
208
  - spec/dummy/app/helpers/application_helper.rb
207
- - spec/dummy/app/views/layouts/application.html.erb
209
+ - spec/dummy/bin/rake
208
210
  - spec/dummy/bin/bundle
209
211
  - spec/dummy/bin/rails
210
- - spec/dummy/bin/rake
211
- - spec/dummy/config/application.rb
212
- - spec/dummy/config/boot.rb
213
- - spec/dummy/config/database.yml
214
- - spec/dummy/config/environment.rb
215
- - spec/dummy/config/environments/development.rb
212
+ - spec/dummy/config/secrets.yml
213
+ - spec/dummy/config/routes.rb
214
+ - spec/dummy/config/locales/en.yml
216
215
  - spec/dummy/config/environments/production.rb
216
+ - spec/dummy/config/environments/development.rb
217
217
  - spec/dummy/config/environments/test.rb
218
- - spec/dummy/config/initializers/assets.rb
218
+ - spec/dummy/config/environment.rb
219
+ - spec/dummy/config/application.rb
220
+ - spec/dummy/config/database.yml
221
+ - spec/dummy/config/boot.rb
222
+ - spec/dummy/config/roles.yml
219
223
  - spec/dummy/config/initializers/backtrace_silencers.rb
220
- - spec/dummy/config/initializers/cookies_serializer.rb
221
- - spec/dummy/config/initializers/filter_parameter_logging.rb
222
- - spec/dummy/config/initializers/inflections.rb
223
224
  - spec/dummy/config/initializers/mime_types.rb
225
+ - spec/dummy/config/initializers/filter_parameter_logging.rb
224
226
  - spec/dummy/config/initializers/session_store.rb
225
227
  - spec/dummy/config/initializers/wrap_parameters.rb
226
- - spec/dummy/config/locales/en.yml
227
- - spec/dummy/config/roles.yml
228
- - spec/dummy/config/routes.rb
229
- - spec/dummy/config/secrets.yml
228
+ - spec/dummy/config/initializers/assets.rb
229
+ - spec/dummy/config/initializers/cookies_serializer.rb
230
+ - spec/dummy/config/initializers/inflections.rb
230
231
  - spec/dummy/config.ru
231
- - spec/dummy/db/test.sqlite3
232
- - spec/dummy/log/test.log
233
- - spec/dummy/public/404.html
232
+ - spec/dummy/Rakefile
233
+ - spec/dummy/public/favicon.ico
234
234
  - spec/dummy/public/422.html
235
235
  - spec/dummy/public/500.html
236
- - spec/dummy/public/favicon.ico
237
- - spec/dummy/Rakefile
236
+ - spec/dummy/public/404.html
237
+ - spec/dummy/db/test.sqlite3
238
+ - spec/dummy/log/test.log
238
239
  - spec/dummy/README.rdoc
239
240
  - spec/integration/navigation_spec.rb
240
241
  - spec/lib/cul/omniauth/abilities_spec.rb
241
242
  - spec/lib/cul/omniauth/callbacks_spec.rb
242
- - spec/lib/cul/omniauth/remote_ip_ability_spec.rb
243
+ - spec/lib/cul/omniauth/users/configured_roles_spec.rb
243
244
  - spec/lib/cul/omniauth/users_spec.rb
244
- - spec/lib/omni_auth/strategies/saml/service_ticket_validator_spec.rb
245
+ - spec/lib/cul/omniauth/remote_ip_ability_spec.rb
245
246
  - spec/lib/omni_auth/strategies/wind/service_ticket_validator_spec.rb
246
- - spec/spec_helper.rb
247
- has_rdoc:
247
+ - spec/lib/omni_auth/strategies/saml/service_ticket_validator_spec.rb
248
+ - spec/cul_omniauth_spec.rb