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.
- data/.gitignore +5 -0
- data/.rvmrc +3 -0
- data/Gemfile +4 -0
- data/Rakefile +8 -0
- data/build.yaml +4 -0
- data/buildfile +7 -0
- data/lib/ncs_navigator/.DS_Store +0 -0
- data/lib/ncs_navigator/authorization.rb +7 -0
- data/lib/ncs_navigator/authorization/core.rb +3 -0
- data/lib/ncs_navigator/authorization/core/authority.rb +84 -0
- data/lib/ncs_navigator/authorization/psc.rb +3 -0
- data/lib/ncs_navigator/authorization/psc/authority.rb +193 -0
- data/lib/ncs_navigator/authorization/staff_portal.rb +6 -0
- data/lib/ncs_navigator/authorization/staff_portal/aker_token.rb +26 -0
- data/lib/ncs_navigator/authorization/staff_portal/client.rb +8 -0
- data/lib/ncs_navigator/authorization/staff_portal/connection.rb +33 -0
- data/lib/ncs_navigator/authorization/staff_portal/http_basic.rb +16 -0
- data/lib/ncs_navigator/authorization/version.rb +5 -0
- data/ncs_navigator_authority.gemspec +34 -0
- data/spec/fixtures/.DS_Store +0 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/core/unknown_user.yml +32 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/core/user.yml +32 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/all_users.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/empty_users_by_role.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/empty_users_by_search_criteria.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/unknown_user.yml +32 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/user_by_numeric_id.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/user_by_username.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_name.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_last_name.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_last_or_user_name.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_first_or_user_name.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_last_name.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_last_or_user_name.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_role.yml +34 -0
- data/spec/fixtures/vcr_cassettes/staff_portal/psc/users_by_username.yml +34 -0
- data/spec/navigator.ini +118 -0
- data/spec/ncs_navigator/.DS_Store +0 -0
- data/spec/ncs_navigator/authorization/core/authority_spec.rb +69 -0
- data/spec/ncs_navigator/authorization/psc/authority_spec.rb +292 -0
- data/spec/ncs_navigator/authorization/psc/role_mapping_spec.rb +99 -0
- data/spec/ncs_navigator/authorization/staff_portal/aker_token_spec.rb +36 -0
- data/spec/ncs_navigator/authorization/staff_portal/http_basic_spec.rb +17 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/vcr_setup.rb +7 -0
- metadata +257 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://psc_application:psc_application@staffportal.local/users.json?last_name=Palbo
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- Basic cHNjX2FwcGxpY2F0aW9uOnBzY19hcHBsaWNhdGlvbg==
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
x-ua-compatible:
|
16
|
+
- IE=Edge
|
17
|
+
etag:
|
18
|
+
- "\"33bac0b7c6ebd02d6dafec00470c8b01\""
|
19
|
+
content-type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
x-runtime:
|
22
|
+
- "0.164258"
|
23
|
+
server:
|
24
|
+
- WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)
|
25
|
+
date:
|
26
|
+
- Tue, 13 Mar 2012 21:35:32 GMT
|
27
|
+
content-length:
|
28
|
+
- "505"
|
29
|
+
set-cookie:
|
30
|
+
- _OMA_session=BAh7ByIZYWtlci5sYXN0X3JlcXVlc3RfYXRsKwekvV9PIg9zZXNzaW9uX2lkIiU0ZWJjOTIxNTY0OGI5YTgzMDdkNTJhNGNhYjRhM2M3OA%3D%3D--27298574ac00c0e2f59c215c49a2c2b6b74faebb; path=/; HttpOnly
|
31
|
+
cache-control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
body: "[{\"notify\":true,\"study_center\":20000029,\"roles\":[{\"name\":\"Field Staff\"},{\"name\":\"Outreach Staff\"}],\"ncs_inactive_date\":null,\"staff_type_other\":null,\"ethnicity\":null,\"staff_id\":\"5de404f5-9c37-4d92-8f2a-30041400ba06\",\"zipcode\":null,\"numeric_id\":1885042269,\"race_other\":null,\"username\":\"outreach\",\"gender\":null,\"external\":false,\"staff_type\":null,\"languages\":[],\"last_name\":\"Palbo\",\"subcontractor\":null,\"race\":null,\"experience\":null,\"email\":\"nolan_palbo@test.com\",\"first_name\":\"Nolan\",\"ncs_active_date\":null}]"
|
34
|
+
http_version: "1.1"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://psc_application:psc_application@staffportal.local/users.json?username=gd123&operator=OR&last_name=Palbo
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- Basic cHNjX2FwcGxpY2F0aW9uOnBzY19hcHBsaWNhdGlvbg==
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
x-ua-compatible:
|
16
|
+
- IE=Edge
|
17
|
+
etag:
|
18
|
+
- "\"9480eca2433582026080ff7c71e9fc0a\""
|
19
|
+
content-type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
x-runtime:
|
22
|
+
- "0.083331"
|
23
|
+
server:
|
24
|
+
- WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)
|
25
|
+
date:
|
26
|
+
- Wed, 14 Mar 2012 17:53:56 GMT
|
27
|
+
content-length:
|
28
|
+
- "996"
|
29
|
+
set-cookie:
|
30
|
+
- _OMA_session=BAh7ByIZYWtlci5sYXN0X3JlcXVlc3RfYXRsKwc022BPIg9zZXNzaW9uX2lkIiUxNmVlZDk4OGZlYzlmZGVhMTdhNzQyYTA2MTAyNjU2Mw%3D%3D--cc07514dceefc84282085682a1c32f227f7f0af6; path=/; HttpOnly
|
31
|
+
cache-control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
body: "[{\"notify\":true,\"study_center\":20000029,\"roles\":[{\"name\":\"Field Staff\"},{\"name\":\"Outreach Staff\"}],\"ncs_inactive_date\":null,\"staff_type_other\":null,\"ethnicity\":null,\"staff_id\":\"5de404f5-9c37-4d92-8f2a-30041400ba06\",\"zipcode\":null,\"numeric_id\":1885042269,\"race_other\":null,\"username\":\"outreach\",\"gender\":null,\"external\":false,\"staff_type\":null,\"languages\":[],\"last_name\":\"Palbo\",\"subcontractor\":null,\"race\":null,\"experience\":null,\"email\":\"nolan_palbo@test.com\",\"first_name\":\"Nolan\",\"ncs_active_date\":null},{\"notify\":true,\"study_center\":20000029,\"roles\":[{\"name\":\"Administrative Staff\"}],\"ncs_inactive_date\":\"2011-12-21\",\"staff_type_other\":null,\"ethnicity\":null,\"staff_id\":\"c1b46c80-0c24-460d-ae89-343aadc7ac68\",\"zipcode\":null,\"numeric_id\":1000943389,\"race_other\":null,\"username\":\"gd123\",\"gender\":null,\"external\":true,\"staff_type\":null,\"languages\":[],\"last_name\":\"Devan\",\"subcontractor\":null,\"race\":null,\"experience\":null,\"email\":\"grace_devan@test.com\",\"first_name\":\"Grace\",\"ncs_active_date\":null}]"
|
34
|
+
http_version: "1.1"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://psc_application:psc_application@staffportal.local/users.json?role%5B%5D=Field%20Staff&role%5B%5D=Phone%20Staff
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- Basic cHNjX2FwcGxpY2F0aW9uOnBzY19hcHBsaWNhdGlvbg==
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
x-ua-compatible:
|
16
|
+
- IE=Edge
|
17
|
+
etag:
|
18
|
+
- "\"59c92e159922355929ebc5d1e6250f07\""
|
19
|
+
content-type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
x-runtime:
|
22
|
+
- "0.163889"
|
23
|
+
server:
|
24
|
+
- WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)
|
25
|
+
date:
|
26
|
+
- Tue, 06 Mar 2012 19:28:46 GMT
|
27
|
+
content-length:
|
28
|
+
- "1005"
|
29
|
+
set-cookie:
|
30
|
+
- _OMA_session=BAh7ByIZYWtlci5sYXN0X3JlcXVlc3RfYXRsKwduZVZPIg9zZXNzaW9uX2lkIiU0YzBmZWYxMzU3NDljYmI0OTRhMTg1Nzg4ZTc1YzFkMg%3D%3D--74de3cd65976130dd9df4118f7ba156d94661db8; path=/; HttpOnly
|
31
|
+
cache-control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
body: "[{\"notify\":true,\"study_center\":20000029,\"ncs_inactive_date\":null,\"staff_type_other\":null,\"roles\":[{\"name\":\"Field Staff\"},{\"name\":\"Outreach Staff\"}],\"ethnicity\":null,\"staff_id\":\"5de404f5-9c37-4d92-8f2a-30041400ba06\",\"zipcode\":null,\"numeric_id\":1885042269,\"race_other\":null,\"username\":\"outreach\",\"gender\":null,\"external\":false,\"staff_type\":null,\"languages\":[],\"last_name\":\"Palbo\",\"subcontractor\":null,\"race\":null,\"experience\":null,\"email\":\"nolan_palbo@test.com\",\"first_name\":\"Nolan\",\"ncs_active_date\":null},{\"notify\":true,\"study_center\":20000029,\"ncs_inactive_date\":null,\"staff_type_other\":null,\"roles\":[{\"name\":\"Field Staff\"},{\"name\":\"Phone Staff\"},{\"name\":\"System Administrator\"},{\"name\":\"User Administrator\"},{\"name\":\"Staff Supervisor\"},{\"name\":\"Biological Specimen Collector\"}],\"ethnicity\":null,\"staff_id\":\"16912345-ba05-481d-aa80-96e71e1ac9d9\",\"zipcode\":null,\"numeric_id\":960833693,\"race_other\":null,\"username\":\"testuser\",\"gender\":null,\"external\":false,\"staff_type\":null,\"languages\":[],\"last_name\":\"Grant\",\"subcontractor\":null,\"race\":null,\"experience\":null,\"email\":\"perry_grant@test.com\",\"first_name\":\"Perry\",\"ncs_active_date\":null}]"
|
34
|
+
http_version: "1.1"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: https://psc_application:psc_application@staffportal.local/users.json?username=gd123
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- Basic cHNjX2FwcGxpY2F0aW9uOnBzY19hcHBsaWNhdGlvbg==
|
10
|
+
response: !ruby/struct:VCR::Response
|
11
|
+
status: !ruby/struct:VCR::ResponseStatus
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
x-ua-compatible:
|
16
|
+
- IE=Edge
|
17
|
+
etag:
|
18
|
+
- "\"99d918e8fb17027c7b0740a347ea326c\""
|
19
|
+
content-type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
x-runtime:
|
22
|
+
- "0.162940"
|
23
|
+
server:
|
24
|
+
- WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18)
|
25
|
+
date:
|
26
|
+
- Tue, 13 Mar 2012 21:40:39 GMT
|
27
|
+
content-length:
|
28
|
+
- "492"
|
29
|
+
set-cookie:
|
30
|
+
- _OMA_session=BAh7ByIZYWtlci5sYXN0X3JlcXVlc3RfYXRsKwfXvl9PIg9zZXNzaW9uX2lkIiU3MjgwZmI4MDlkMzliM2RhZTdiNDkwY2YwZjk5ZGZjNg%3D%3D--166a76eaed18538e9cf0320da8523bcae5dc6a57; path=/; HttpOnly
|
31
|
+
cache-control:
|
32
|
+
- max-age=0, private, must-revalidate
|
33
|
+
body: "[{\"notify\":true,\"study_center\":20000029,\"roles\":[{\"name\":\"Administrative Staff\"}],\"ncs_inactive_date\":\"2011-12-21\",\"staff_type_other\":null,\"ethnicity\":null,\"staff_id\":\"c1b46c80-0c24-460d-ae89-343aadc7ac68\",\"zipcode\":null,\"numeric_id\":1000943389,\"race_other\":null,\"username\":\"gd123\",\"gender\":null,\"external\":true,\"staff_type\":null,\"languages\":[],\"last_name\":\"Devan\",\"subcontractor\":null,\"race\":null,\"experience\":null,\"email\":\"grace_devan@test.com\",\"first_name\":\"Grace\",\"ncs_active_date\":null}]"
|
34
|
+
http_version: "1.1"
|
data/spec/navigator.ini
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# Sample common configuration for NCS Navigator. By default the suite
|
2
|
+
# applications will expect to find a customized version of this file
|
3
|
+
# in /etc/nubic/ncs/navigator.ini.
|
4
|
+
|
5
|
+
[Study Center]
|
6
|
+
# Information about the study center which is using this deployment of
|
7
|
+
# NCS Navigator. Each NCS Navigator instance is only for one study
|
8
|
+
# center.
|
9
|
+
|
10
|
+
# The ID for the study center from the MDES
|
11
|
+
sc_id = "20000029"
|
12
|
+
|
13
|
+
recruitment_type_id = "3"
|
14
|
+
|
15
|
+
# A pointer to a CSV describing the sampling units for this study
|
16
|
+
# center. If the path is not absolute it will be resolved relative to
|
17
|
+
# this file.
|
18
|
+
#
|
19
|
+
# The CSV must have the following header (along with the contents it
|
20
|
+
# implies):
|
21
|
+
#
|
22
|
+
# PSU_ID, AREA, SSU_ID, SSU_NAME, TSU_ID, TSU_NAME
|
23
|
+
#
|
24
|
+
# While this format allows for multiple PSUs, NCS Navigator currently
|
25
|
+
# only supports one per deployment. This will change in the future
|
26
|
+
# when multiple PSUs are active per center.
|
27
|
+
#
|
28
|
+
# TSU_ID and TSU_NAME may be omitted for centers that are not on
|
29
|
+
# Hi-Lo.
|
30
|
+
#
|
31
|
+
# AREA is an intermediate concept introduced by NCS Navigator. It
|
32
|
+
# allows the grouping of one or more SSUs for ease of reporting
|
33
|
+
# something (e.g., outreach events) across all of them. If a center
|
34
|
+
# doesn't wish to make use of this concept, the AREA should be made
|
35
|
+
# the same as the SSU_NAME.
|
36
|
+
sampling_units_file = "spec_ssus.csv"
|
37
|
+
|
38
|
+
# The name of the institutional user identity used in NCS
|
39
|
+
# Navigator. E.g., for the Greater Chicago Study Center, this is the
|
40
|
+
# Northwestern NetID. The default is "Username" if nothing is
|
41
|
+
# specifed.
|
42
|
+
#username = "NetID"
|
43
|
+
|
44
|
+
# The absolute path to local files containing logos that should appear
|
45
|
+
# on either end of the footer in Staff Portal and Core.
|
46
|
+
#footer_logo_left = "/etc/nubic/ncs/logos/sc_20000000L.png"
|
47
|
+
#footer_logo_right = "/etc/nubic/ncs/logos/sc_20000000R.png"
|
48
|
+
|
49
|
+
# The text that should appear in the center of the footer in Staff
|
50
|
+
# Portal and Core. Line breaks in this text will be preserved.
|
51
|
+
footer_text = "National Children's Study - Greater Chicago Study Center
|
52
|
+
Institute for Healthcare Studies, Feinberg School of Medicine
|
53
|
+
Northwestern University
|
54
|
+
420 East Superior, 10th Floor
|
55
|
+
Chicago, IL 60611"
|
56
|
+
|
57
|
+
[Staff Portal]
|
58
|
+
# Configuration options which are used by or which describe Staff
|
59
|
+
# Portal in this instance of the suite.
|
60
|
+
|
61
|
+
# The root URI for Staff Portal.
|
62
|
+
uri = "https://staffportal.local/"
|
63
|
+
#uri = "http://localhost:3000/"
|
64
|
+
|
65
|
+
# The e-mail address from which mail sent by Staff Pportal will
|
66
|
+
# appear to come.
|
67
|
+
mail_from = "staffportal@greaterchicagoncs.org"
|
68
|
+
|
69
|
+
bootstrap_user = test_user
|
70
|
+
psc_user_password = "psc_application"
|
71
|
+
|
72
|
+
[Core]
|
73
|
+
# Configuration options which are used by or which describe NCS
|
74
|
+
# Navigator Core in this instance of the suite.
|
75
|
+
|
76
|
+
# The root URI for NCS Navigator Core.
|
77
|
+
uri = "https://ncsnavigator.local/"
|
78
|
+
|
79
|
+
# TODO: add to README
|
80
|
+
recruitment_type = "HILI"
|
81
|
+
with_specimens = "false"
|
82
|
+
|
83
|
+
[PSC]
|
84
|
+
# Configuration options which describe PSC as used by this instance of
|
85
|
+
# the suite. (For now, PSC's own configuration options must be set
|
86
|
+
# through its configuration interfaces.)
|
87
|
+
|
88
|
+
# The root URI for PSC.
|
89
|
+
uri = "https://ncsn-psc.local/"
|
90
|
+
|
91
|
+
[SMTP]
|
92
|
+
# Configuration for the SMTP server for MDES Warehouse, Staff Portal,
|
93
|
+
# and NCS Navigator Core.
|
94
|
+
|
95
|
+
# The hostname or IP of the SMTP server to use to send mail from the
|
96
|
+
# suite. Default is localhost.
|
97
|
+
#host = "ns.northwestern.edu"
|
98
|
+
|
99
|
+
# The port to use to communicate with the SMTP server. Default is 25.
|
100
|
+
#port = "25"
|
101
|
+
|
102
|
+
# The domain to use in SMTP HELO, if necessary. Default is none.
|
103
|
+
#domain =
|
104
|
+
|
105
|
+
# The type of authentication your SMTP server uses. Default is
|
106
|
+
# none. Legal values are "plain", "login", or "cram_md5".
|
107
|
+
#authentication =
|
108
|
+
|
109
|
+
# The username to use to authenticate to the SMTP server, if
|
110
|
+
# necessary. Default is none.
|
111
|
+
#username =
|
112
|
+
|
113
|
+
# The password to use to authenticate to the SMTP server, if
|
114
|
+
# necessary. Default is none.
|
115
|
+
#password =
|
116
|
+
|
117
|
+
# Whether to use STARTTLS if your SMTP server supports it. Default is false.
|
118
|
+
#starttls = false
|
Binary file
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'aker'
|
3
|
+
require 'vcr'
|
4
|
+
require 'faraday'
|
5
|
+
require 'faraday_stack'
|
6
|
+
describe NcsNavigator::Authorization::Core::Authority do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@ncs_navigator_authority = NcsNavigator::Authorization::Core::Authority.new
|
10
|
+
@user = mock(:username => "lee", :cas_proxy_ticket => "PT-cas-ticket")
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "user" do
|
14
|
+
before do
|
15
|
+
VCR.use_cassette('staff_portal/core/user') do
|
16
|
+
@return_user = @ncs_navigator_authority.user(@user)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "copies first name from staff portal user" do
|
21
|
+
@return_user.first_name.should == "Lee"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "copies last name from staff portal user" do
|
25
|
+
@return_user.last_name.should == "Peterson"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "copies email from staff portal user" do
|
29
|
+
@return_user.email.should == "lee@test.com"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "copies staff_id as identifiers from staff portal staff_id" do
|
33
|
+
@return_user.identifiers[:staff_id].should == "test_staff_id"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "generate group membership from staff role" do
|
37
|
+
@return_user.group_memberships(:NCSNavigator).include?("Staff Supervisor").should be_true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
describe "#amplify!" do
|
43
|
+
before do
|
44
|
+
@lee = mock(Aker::User, :username => "lee", :cas_proxy_ticket => "PT-cas-ticket",:first_name => "Lee", :portals => [:NCSNavigator])
|
45
|
+
@before_lee = mock(Aker::User, :username => "lee", :cas_proxy_ticket => "PT-cas-ticket", :merge! => @lee)
|
46
|
+
end
|
47
|
+
|
48
|
+
def actual
|
49
|
+
VCR.use_cassette('staff_portal/core/user') do
|
50
|
+
@ncs_navigator_authority.amplify!(@before_lee)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "copies simple attributes" do
|
55
|
+
actual.first_name.should == "Lee"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "copies portal" do
|
59
|
+
actual.portals.should == [:NCSNavigator]
|
60
|
+
end
|
61
|
+
|
62
|
+
it "does nothing for an unknown user" do
|
63
|
+
VCR.use_cassette('staff_portal/core/unknown_user') do
|
64
|
+
lambda { @ncs_navigator_authority.amplify!(mock(Aker::User, :username => "lees", :cas_proxy_ticket => "PT-cas-ticket"))}.should_not raise_error
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,292 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'aker'
|
3
|
+
require 'vcr'
|
4
|
+
require 'faraday'
|
5
|
+
require 'faraday_stack'
|
6
|
+
|
7
|
+
describe NcsNavigator::Authorization::Psc::Authority do
|
8
|
+
before do
|
9
|
+
@psc_authority = NcsNavigator::Authorization::Psc::Authority.new
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "user" do
|
13
|
+
before do
|
14
|
+
VCR.use_cassette('staff_portal/psc/user_by_numeric_id') do
|
15
|
+
@return_user = @psc_authority.user(1234)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has id" do
|
20
|
+
@return_user[:id].should == 1234
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has username" do
|
24
|
+
@return_user[:username].should == "testuser"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has email_address" do
|
28
|
+
@return_user[:email_address].should == "testuser@test.com"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has first_name" do
|
32
|
+
@return_user[:first_name].should == "TestFirstName"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has last_name" do
|
36
|
+
@return_user[:last_name].should == "TestLastName"
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has roles" do
|
40
|
+
@return_user[:roles].should_not be_empty
|
41
|
+
@return_user[:roles].count.should == 13
|
42
|
+
end
|
43
|
+
|
44
|
+
it "does nothing for an unknown user and return nil" do
|
45
|
+
VCR.use_cassette('staff_portal/psc/unknown_user') do
|
46
|
+
@return_user = @psc_authority.user("unknown")
|
47
|
+
end
|
48
|
+
@return_user.should == nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "get_user_by_username" do
|
53
|
+
describe "for valid username" do
|
54
|
+
before do
|
55
|
+
VCR.use_cassette('staff_portal/psc/user_by_username') do
|
56
|
+
@return_user = @psc_authority.get_user_by_username("testuser", nil)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
it "return user_hash for user with known username" do
|
60
|
+
@return_user.should_not == nil
|
61
|
+
end
|
62
|
+
|
63
|
+
[:username, :id, :first_name, :email_address, :first_name, :last_name, :roles].each do |key|
|
64
|
+
it "has #{key}" do
|
65
|
+
@return_user.has_key?(key).should == true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns nil for unknown username" do
|
71
|
+
VCR.use_cassette('staff_portal/psc/unknown_user') do
|
72
|
+
@return_user = @psc_authority.get_user_by_username("unknown", nil)
|
73
|
+
end
|
74
|
+
@return_user.should == nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe "get_user_by_id" do
|
79
|
+
describe "for valid id" do
|
80
|
+
before do
|
81
|
+
VCR.use_cassette('staff_portal/psc/user_by_numeric_id') do
|
82
|
+
@return_user = @psc_authority.get_user_by_id(1234, nil)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "return user_hash for user with known username" do
|
87
|
+
@return_user.should_not == nil
|
88
|
+
end
|
89
|
+
|
90
|
+
[:username, :id, :first_name, :email_address, :first_name, :last_name, :roles].each do |key|
|
91
|
+
it "has #{key}" do
|
92
|
+
@return_user.has_key?(key).should == true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "returns nil for unknown username" do
|
98
|
+
VCR.use_cassette('staff_portal/psc/unknown_user') do
|
99
|
+
@return_user = @psc_authority.get_user_by_id("unknown", nil)
|
100
|
+
end
|
101
|
+
@return_user.should == nil
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "get_users_by_role" do
|
106
|
+
it "returns empty array for unknown role" do
|
107
|
+
return_users = @psc_authority.get_users_by_role(:unknown)
|
108
|
+
return_users.should be_empty
|
109
|
+
end
|
110
|
+
|
111
|
+
describe "for valid role" do
|
112
|
+
before do
|
113
|
+
VCR.use_cassette('staff_portal/psc/users_by_role') do
|
114
|
+
@return_users = @psc_authority.get_users_by_role(:subject_manager)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
it "returns users with roles" do
|
119
|
+
@return_users.count.should == 2
|
120
|
+
end
|
121
|
+
|
122
|
+
[:username, :id, :first_name, :email_address, :last_name, :roles].each do |key|
|
123
|
+
it "has #{key}" do
|
124
|
+
@return_users[0].has_key?(key).should == true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
it "returns empty array if no users with role" do
|
129
|
+
VCR.use_cassette('staff_portal/psc/empty_users_by_role') do
|
130
|
+
@return_users = @psc_authority.get_users_by_role(:subject_manager)
|
131
|
+
end
|
132
|
+
@return_users.should be_empty
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "search_users" do
|
138
|
+
it "returns all the users for empty hash" do
|
139
|
+
VCR.use_cassette('staff_portal/psc/all_users') do
|
140
|
+
@return_users = @psc_authority.search_users({})
|
141
|
+
end
|
142
|
+
@return_users.count.should == 6
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "with first_name" do
|
146
|
+
before do
|
147
|
+
VCR.use_cassette('staff_portal/psc/users_by_first_name') do
|
148
|
+
@return_users = @psc_authority.search_users({:first_name_substring => "an"})
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it "returns all the users with first_name criteria match" do
|
153
|
+
@return_users.count.should == 2
|
154
|
+
end
|
155
|
+
|
156
|
+
it "has user with first_name match with criteria" do
|
157
|
+
@return_users[0][:first_name].should == "Nolan"
|
158
|
+
@return_users[1][:first_name].should == "Lithan"
|
159
|
+
end
|
160
|
+
|
161
|
+
[:username, :id, :first_name, :email_address, :first_name, :last_name, :roles].each do |key|
|
162
|
+
it "user has #{key}" do
|
163
|
+
@return_users[0].has_key?(key).should == true
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "with last_name" do
|
169
|
+
before do
|
170
|
+
VCR.use_cassette('staff_portal/psc/users_by_last_name') do
|
171
|
+
@return_users = @psc_authority.search_users({:last_name_substring => "Palbo"})
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
it "returns all the users with last_name criteria match" do
|
176
|
+
@return_users.count.should == 1
|
177
|
+
end
|
178
|
+
|
179
|
+
it "has user with last_name match with criteria" do
|
180
|
+
@return_users[0][:last_name].should == "Palbo"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "with username" do
|
185
|
+
before do
|
186
|
+
VCR.use_cassette('staff_portal/psc/users_by_username') do
|
187
|
+
@return_users = @psc_authority.search_users({:username_substring => "gd123"})
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
it "returns all the users with username criteria match" do
|
192
|
+
@return_users.count.should == 1
|
193
|
+
end
|
194
|
+
|
195
|
+
it "has user with username match with criteria" do
|
196
|
+
@return_users[0][:username].should == "gd123"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "with first_name or last_name" do
|
201
|
+
before do
|
202
|
+
VCR.use_cassette('staff_portal/psc/users_by_first_or_last_name') do
|
203
|
+
@return_users = @psc_authority.search_users({:first_name_substring => "Lithan", :last_name_substring => "Palbo"})
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
it "returns all the users with first_name or last_name criteria match" do
|
208
|
+
@return_users.count.should == 2
|
209
|
+
end
|
210
|
+
|
211
|
+
it "has user with first_name match with criteria" do
|
212
|
+
@return_users[1][:first_name].should == "Lithan"
|
213
|
+
end
|
214
|
+
|
215
|
+
it "has user with last_name match with criteria" do
|
216
|
+
@return_users[0][:last_name].should == "Palbo"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "with first_name or username" do
|
221
|
+
before do
|
222
|
+
VCR.use_cassette('staff_portal/psc/users_by_first_or_user_name') do
|
223
|
+
@return_users = @psc_authority.search_users({:first_name_substring => "Lithan", :username_substring => "gd123"})
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
it "returns all the users with first_name or username criteria match" do
|
228
|
+
@return_users.count.should == 2
|
229
|
+
end
|
230
|
+
|
231
|
+
it "has user with username match with criteria" do
|
232
|
+
@return_users[0][:username].should == "gd123"
|
233
|
+
end
|
234
|
+
|
235
|
+
it "has user with first_name match with criteria" do
|
236
|
+
@return_users[1][:first_name].should == "Lithan"
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe "with last_name or username" do
|
241
|
+
before do
|
242
|
+
VCR.use_cassette('staff_portal/psc/users_by_last_or_user_name') do
|
243
|
+
@return_users = @psc_authority.search_users({:last_name_substring => "Palbo", :username_substring => "gd123"})
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
it "returns all the users with last_name or username criteria match" do
|
248
|
+
@return_users.count.should == 2
|
249
|
+
end
|
250
|
+
|
251
|
+
it "has user with username match with criteria" do
|
252
|
+
@return_users[1][:username].should == "gd123"
|
253
|
+
end
|
254
|
+
|
255
|
+
it "has user with last_name match with criteria" do
|
256
|
+
@return_users[0][:last_name].should == "Palbo"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe "with first_name or last_name or username" do
|
261
|
+
before do
|
262
|
+
VCR.use_cassette('staff_portal/psc/users_by_first_or_last_or_user_name') do
|
263
|
+
@return_users = @psc_authority.search_users({:first_name_substring => "Lithan", :last_name_substring => "Palbo", :username_substring => "gd123"})
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
it "returns all the users with first_name or last_name or username criteria match" do
|
268
|
+
@return_users.count.should == 3
|
269
|
+
end
|
270
|
+
|
271
|
+
it "has user with username match with criteria" do
|
272
|
+
@return_users[1][:username].should == "gd123"
|
273
|
+
end
|
274
|
+
|
275
|
+
it "has user with last_name match with criteria" do
|
276
|
+
@return_users[0][:last_name].should == "Palbo"
|
277
|
+
end
|
278
|
+
|
279
|
+
it "has user with first_name match with criteria" do
|
280
|
+
@return_users[2][:first_name].should == "Lithan"
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
it "returns empty array if no users with match with search criteria" do
|
285
|
+
VCR.use_cassette('staff_portal/psc/empty_users_by_search_criteria') do
|
286
|
+
@return_users = @psc_authority.search_users({:first_name_substring => "unknown", :last_name_substring => "unknown", :username_substring => "unknown"})
|
287
|
+
end
|
288
|
+
@return_users.should be_empty
|
289
|
+
end
|
290
|
+
|
291
|
+
end
|
292
|
+
end
|