ncs_navigator_authority 0.0.2

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 (46) hide show
  1. data/.gitignore +5 -0
  2. data/.rvmrc +3 -0
  3. data/Gemfile +4 -0
  4. data/Rakefile +8 -0
  5. data/build.yaml +4 -0
  6. data/buildfile +7 -0
  7. data/lib/ncs_navigator/.DS_Store +0 -0
  8. data/lib/ncs_navigator/authorization.rb +7 -0
  9. data/lib/ncs_navigator/authorization/core.rb +3 -0
  10. data/lib/ncs_navigator/authorization/core/authority.rb +84 -0
  11. data/lib/ncs_navigator/authorization/psc.rb +3 -0
  12. data/lib/ncs_navigator/authorization/psc/authority.rb +193 -0
  13. data/lib/ncs_navigator/authorization/staff_portal.rb +6 -0
  14. data/lib/ncs_navigator/authorization/staff_portal/aker_token.rb +26 -0
  15. data/lib/ncs_navigator/authorization/staff_portal/client.rb +8 -0
  16. data/lib/ncs_navigator/authorization/staff_portal/connection.rb +33 -0
  17. data/lib/ncs_navigator/authorization/staff_portal/http_basic.rb +16 -0
  18. data/lib/ncs_navigator/authorization/version.rb +5 -0
  19. data/ncs_navigator_authority.gemspec +34 -0
  20. data/spec/fixtures/.DS_Store +0 -0
  21. data/spec/fixtures/vcr_cassettes/staff_portal/core/unknown_user.yml +32 -0
  22. data/spec/fixtures/vcr_cassettes/staff_portal/core/user.yml +32 -0
  23. data/spec/fixtures/vcr_cassettes/staff_portal/psc/all_users.yml +34 -0
  24. data/spec/fixtures/vcr_cassettes/staff_portal/psc/empty_users_by_role.yml +34 -0
  25. data/spec/fixtures/vcr_cassettes/staff_portal/psc/empty_users_by_search_criteria.yml +34 -0
  26. data/spec/fixtures/vcr_cassettes/staff_portal/psc/unknown_user.yml +32 -0
  27. data/spec/fixtures/vcr_cassettes/staff_portal/psc/user_by_numeric_id.yml +34 -0
  28. data/spec/fixtures/vcr_cassettes/staff_portal/psc/user_by_username.yml +34 -0
  29. data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_name.yml +34 -0
  30. data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_last_name.yml +34 -0
  31. data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_last_or_user_name.yml +34 -0
  32. data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_user_name.yml +34 -0
  33. data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_last_name.yml +34 -0
  34. data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_last_or_user_name.yml +34 -0
  35. data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_role.yml +34 -0
  36. data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_username.yml +34 -0
  37. data/spec/navigator.ini +118 -0
  38. data/spec/ncs_navigator/.DS_Store +0 -0
  39. data/spec/ncs_navigator/authorization/core/authority_spec.rb +69 -0
  40. data/spec/ncs_navigator/authorization/psc/authority_spec.rb +292 -0
  41. data/spec/ncs_navigator/authorization/psc/role_mapping_spec.rb +99 -0
  42. data/spec/ncs_navigator/authorization/staff_portal/aker_token_spec.rb +36 -0
  43. data/spec/ncs_navigator/authorization/staff_portal/http_basic_spec.rb +17 -0
  44. data/spec/spec_helper.rb +18 -0
  45. data/spec/support/vcr_setup.rb +7 -0
  46. metadata +257 -0
@@ -0,0 +1,99 @@
1
+ describe NcsNavigator::Authorization::Psc::RoleMapping do
2
+ before do
3
+ @role_mapping = NcsNavigator::Authorization::Psc::RoleMapping
4
+ end
5
+ describe "psc_to_staff_portal" do
6
+ [:study_creator, :study_calendar_template_builder, :study_qa_manager, :study_site_participation_administrator,
7
+ :system_administrator, :data_importer, :business_administrator, :person_and_organization_information_manager].each do |key|
8
+ it "maps '#{key}' to 'System Administrator' role" do
9
+ has_correct_psc_to_sp_role_mapping(key, "System Administrator")
10
+ end
11
+ end
12
+
13
+ it "maps ':user_administrator' to 'User Administrator' role" do
14
+ has_correct_psc_to_sp_role_mapping(:user_administrator, "User Administrator")
15
+ end
16
+
17
+ it "maps ':study_team_administrator' to 'Staff Supervisor' role" do
18
+ has_correct_psc_to_sp_role_mapping(:study_team_administrator, "Staff Supervisor")
19
+ end
20
+
21
+ it "maps ':data_reader' to 'Data Reader' role" do
22
+ has_correct_psc_to_sp_role_mapping(:data_reader, "Data Reader")
23
+ end
24
+
25
+ it "maps ':subject_manager' to 'Field Staff' and 'Phone Staff' roles" do
26
+ roles = @role_mapping.psc_to_staff_portal(:subject_manager)
27
+ roles.count.should == 2
28
+ roles.should include "Field Staff"
29
+ roles.should include "Phone Staff"
30
+ end
31
+
32
+ it "maps ':study_subject_calendar_manager' to 'Field Staff', 'Phone Staff' and 'Biological Specimen Collector' roles" do
33
+ roles = @role_mapping.psc_to_staff_portal(:study_subject_calendar_manager)
34
+ roles.count.should == 3
35
+ roles.should include "Field Staff"
36
+ roles.should include "Phone Staff"
37
+ roles.should include "Biological Specimen Collector"
38
+ end
39
+ end
40
+
41
+ describe "staff_portal_to_psc" do
42
+ describe "maps 'System Administrator'" do
43
+ before do
44
+ @roles = @role_mapping.staff_portal_to_psc("System Administrator")
45
+ @roles.count.should == 8
46
+ end
47
+
48
+ [:study_creator, :study_calendar_template_builder, :study_qa_manager, :study_site_participation_administrator,
49
+ :system_administrator, :data_importer, :business_administrator, :person_and_organization_information_manager].each do |key|
50
+ it "to ':#{key}' role" do
51
+ @roles.should include key
52
+ end
53
+ end
54
+ end
55
+
56
+ it "maps 'User Administrator' to ':user_administrator' role" do
57
+ has_correct_sp_to_psc_role_mapping("User Administrator", :user_administrator)
58
+ end
59
+
60
+ it "maps 'Staff Supervisor' to ':study_team_administrator' role" do
61
+ has_correct_sp_to_psc_role_mapping("Staff Supervisor", :study_team_administrator)
62
+ end
63
+
64
+ it "maps 'Data Reader' to ':data_reader' role" do
65
+ has_correct_sp_to_psc_role_mapping("Data Reader", :data_reader)
66
+ end
67
+
68
+ it "maps 'Biological Specimen Collector' to ':study_subject_calendar_manager' role" do
69
+ has_correct_sp_to_psc_role_mapping("Biological Specimen Collector", :study_subject_calendar_manager)
70
+ end
71
+
72
+ it "maps 'Field Staff' to ':subject_manager' and ':study_subject_calendar_manager' roles" do
73
+ roles = @role_mapping.staff_portal_to_psc('Field Staff')
74
+ roles.count.should == 2
75
+ roles.should include :subject_manager
76
+ roles.should include :study_subject_calendar_manager
77
+ end
78
+
79
+ it "maps 'Phone Staff' to ':subject_manager' and ':study_subject_calendar_manager' roles" do
80
+ roles = @role_mapping.staff_portal_to_psc('Phone Staff')
81
+ roles.count.should == 2
82
+ roles.should include :subject_manager
83
+ roles.should include :study_subject_calendar_manager
84
+ end
85
+ end
86
+
87
+ private
88
+ def has_correct_psc_to_sp_role_mapping(psc_role, sp_role)
89
+ roles = @role_mapping.psc_to_staff_portal(psc_role)
90
+ roles.count.should == 1
91
+ roles.should include sp_role
92
+ end
93
+
94
+ def has_correct_sp_to_psc_role_mapping(sp_role, psc_role)
95
+ roles = @role_mapping.staff_portal_to_psc(sp_role)
96
+ roles.count.should == 1
97
+ roles.should include psc_role
98
+ end
99
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe NcsNavigator::Authorization::StaffPortal::AkerToken do
4
+ let(:app) { mock('app') }
5
+ let(:env) { { :request_headers => ::Faraday::Utils::Headers.new } }
6
+ let(:headers) { env[:request_headers] }
7
+
8
+ before { app.stub!(:call) }
9
+
10
+ describe "static token" do
11
+ subject { NcsNavigator::Authorization::StaffPortal::AkerToken.new(app, 'jo-9') }
12
+
13
+ it 'adds the appropriate Authorization header' do
14
+ subject.call(env)
15
+ headers['Authorization'].should == 'CasProxy jo-9'
16
+ end
17
+ end
18
+
19
+ describe "dynamic token" do
20
+ subject do
21
+ i = 6
22
+ NcsNavigator::Authorization::StaffPortal::AkerToken.new(app, lambda { i += 2; i ** 2 })
23
+ end
24
+
25
+ it 'adds the appropriate Authorization header' do
26
+ subject.call(env)
27
+ headers['Authorization'].should == 'CasProxy 64'
28
+ end
29
+
30
+ it 'invokes the lambda for each call' do
31
+ subject.call(env)
32
+ subject.call(env)
33
+ headers['Authorization'].should == 'CasProxy 100'
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe NcsNavigator::Authorization::StaffPortal::HttpBasic do
4
+ let(:app) { mock('app') }
5
+ let(:env) { { :request_headers => ::Faraday::Utils::Headers.new } }
6
+ let(:headers) { env[:request_headers] }
7
+
8
+ before { app.stub!(:call) }
9
+ describe "token" do
10
+ subject { NcsNavigator::Authorization::StaffPortal::HttpBasic.new(app, 'user', 'pwd') }
11
+
12
+ it 'adds the appropriate Authorization header' do
13
+ subject.call(env)
14
+ headers['Authorization'].should == 'Basic dXNlcjpwd2Q='
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'rspec'
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
+ require 'ncs_navigator/configuration'
5
+ NcsNavigator.configuration =
6
+ NcsNavigator::Configuration.new(File.expand_path('../navigator.ini', __FILE__))
7
+
8
+ require 'ncs_navigator/authorization/core/authority'
9
+ require 'ncs_navigator/authorization/psc/authority'
10
+ require 'ncs_navigator/authorization/staff_portal/aker_token'
11
+ require 'ncs_navigator/authorization/staff_portal/client'
12
+ require 'ncs_navigator/authorization/staff_portal/connection'
13
+ require 'ncs_navigator/authorization/staff_portal/http_basic'
14
+
15
+ require 'spec/support/vcr_setup.rb'
16
+ RSpec.configure do |config|
17
+ # config.fixture_path = "/spec/fixtures"
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'vcr'
2
+
3
+ VCR.config do |c|
4
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
5
+ c.stub_with :fakeweb
6
+ c.default_cassette_options = { :record => :once }
7
+ end
metadata ADDED
@@ -0,0 +1,257 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ncs_navigator_authority
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Jalpa Patel
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-29 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: ncs_navigator_configuration
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 15
30
+ segments:
31
+ - 0
32
+ - 2
33
+ version: "0.2"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: aker
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 7
45
+ segments:
46
+ - 3
47
+ - 0
48
+ version: "3.0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: faraday
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 9
60
+ segments:
61
+ - 0
62
+ - 7
63
+ - 5
64
+ version: 0.7.5
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: faraday-stack
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 29
76
+ segments:
77
+ - 0
78
+ - 1
79
+ - 3
80
+ version: 0.1.3
81
+ type: :runtime
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ hash: 15
92
+ segments:
93
+ - 2
94
+ - 6
95
+ version: "2.6"
96
+ type: :development
97
+ version_requirements: *id005
98
+ - !ruby/object:Gem::Dependency
99
+ name: rake
100
+ prerelease: false
101
+ requirement: &id006 !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ~>
105
+ - !ruby/object:Gem::Version
106
+ hash: 63
107
+ segments:
108
+ - 0
109
+ - 9
110
+ - 2
111
+ version: 0.9.2
112
+ type: :development
113
+ version_requirements: *id006
114
+ - !ruby/object:Gem::Dependency
115
+ name: vcr
116
+ prerelease: false
117
+ requirement: &id007 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ type: :development
127
+ version_requirements: *id007
128
+ - !ruby/object:Gem::Dependency
129
+ name: fakeweb
130
+ prerelease: false
131
+ requirement: &id008 !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ hash: 3
137
+ segments:
138
+ - 0
139
+ version: "0"
140
+ type: :development
141
+ version_requirements: *id008
142
+ description: This is a shared library which consume Staff Portal's authorization API and provides group membership information for the NcsNavigator portal and role authorization mapping for PSC.
143
+ email:
144
+ - jalpa-patel@northwestern.edu
145
+ executables: []
146
+
147
+ extensions: []
148
+
149
+ extra_rdoc_files: []
150
+
151
+ files:
152
+ - .gitignore
153
+ - .rvmrc
154
+ - Gemfile
155
+ - Rakefile
156
+ - build.yaml
157
+ - buildfile
158
+ - lib/ncs_navigator/.DS_Store
159
+ - lib/ncs_navigator/authorization.rb
160
+ - lib/ncs_navigator/authorization/core.rb
161
+ - lib/ncs_navigator/authorization/core/authority.rb
162
+ - lib/ncs_navigator/authorization/psc.rb
163
+ - lib/ncs_navigator/authorization/psc/authority.rb
164
+ - lib/ncs_navigator/authorization/staff_portal.rb
165
+ - lib/ncs_navigator/authorization/staff_portal/aker_token.rb
166
+ - lib/ncs_navigator/authorization/staff_portal/client.rb
167
+ - lib/ncs_navigator/authorization/staff_portal/connection.rb
168
+ - lib/ncs_navigator/authorization/staff_portal/http_basic.rb
169
+ - lib/ncs_navigator/authorization/version.rb
170
+ - ncs_navigator_authority.gemspec
171
+ - spec/fixtures/.DS_Store
172
+ - spec/fixtures/vcr_cassettes/staff_portal/core/unknown_user.yml
173
+ - spec/fixtures/vcr_cassettes/staff_portal/core/user.yml
174
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/all_users.yml
175
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/empty_users_by_role.yml
176
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/empty_users_by_search_criteria.yml
177
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/unknown_user.yml
178
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/user_by_numeric_id.yml
179
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/user_by_username.yml
180
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_name.yml
181
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_last_name.yml
182
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_last_or_user_name.yml
183
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_user_name.yml
184
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_last_name.yml
185
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_last_or_user_name.yml
186
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_role.yml
187
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_username.yml
188
+ - spec/navigator.ini
189
+ - spec/ncs_navigator/.DS_Store
190
+ - spec/ncs_navigator/authorization/core/authority_spec.rb
191
+ - spec/ncs_navigator/authorization/psc/authority_spec.rb
192
+ - spec/ncs_navigator/authorization/psc/role_mapping_spec.rb
193
+ - spec/ncs_navigator/authorization/staff_portal/aker_token_spec.rb
194
+ - spec/ncs_navigator/authorization/staff_portal/http_basic_spec.rb
195
+ - spec/spec_helper.rb
196
+ - spec/support/vcr_setup.rb
197
+ has_rdoc: true
198
+ homepage: ""
199
+ licenses: []
200
+
201
+ post_install_message:
202
+ rdoc_options: []
203
+
204
+ require_paths:
205
+ - lib
206
+ required_ruby_version: !ruby/object:Gem::Requirement
207
+ none: false
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ hash: 3
212
+ segments:
213
+ - 0
214
+ version: "0"
215
+ required_rubygems_version: !ruby/object:Gem::Requirement
216
+ none: false
217
+ requirements:
218
+ - - ">="
219
+ - !ruby/object:Gem::Version
220
+ hash: 3
221
+ segments:
222
+ - 0
223
+ version: "0"
224
+ requirements: []
225
+
226
+ rubyforge_project: ncs_navigator_authority
227
+ rubygems_version: 1.5.2
228
+ signing_key:
229
+ specification_version: 3
230
+ summary: Authorization module for NCS Navigator
231
+ test_files:
232
+ - spec/fixtures/.DS_Store
233
+ - spec/fixtures/vcr_cassettes/staff_portal/core/unknown_user.yml
234
+ - spec/fixtures/vcr_cassettes/staff_portal/core/user.yml
235
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/all_users.yml
236
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/empty_users_by_role.yml
237
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/empty_users_by_search_criteria.yml
238
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/unknown_user.yml
239
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/user_by_numeric_id.yml
240
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/user_by_username.yml
241
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_name.yml
242
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_last_name.yml
243
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_last_or_user_name.yml
244
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_user_name.yml
245
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_last_name.yml
246
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_last_or_user_name.yml
247
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_role.yml
248
+ - spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_username.yml
249
+ - spec/navigator.ini
250
+ - spec/ncs_navigator/.DS_Store
251
+ - spec/ncs_navigator/authorization/core/authority_spec.rb
252
+ - spec/ncs_navigator/authorization/psc/authority_spec.rb
253
+ - spec/ncs_navigator/authorization/psc/role_mapping_spec.rb
254
+ - spec/ncs_navigator/authorization/staff_portal/aker_token_spec.rb
255
+ - spec/ncs_navigator/authorization/staff_portal/http_basic_spec.rb
256
+ - spec/spec_helper.rb
257
+ - spec/support/vcr_setup.rb