ucb_rails_user 1.0.0 → 1.1.0
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
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dc5620499c364c14d79ea1c8da21d420617fc235
|
4
|
+
data.tar.gz: b801bf9e74db566224e301efc79744ca0fc9b774
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 493ed7ef342b66b11c8e36b23b4a7d1087defc96108059994678702d734a849308c19f8030e43f22eb28bd02387f70d5ff2dfce24e9dc7bcab2d587edc211f77
|
7
|
+
data.tar.gz: 70bf635518c74e56f5e8c3edb992a8328278232274315f5512fcb0838346160279322a5ee7c015dff3e5d4d4feb3d6367103cde3ee67cfdc85616106412c240b
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ A [Rails engine](http://guides.rubyonrails.org/engines.html) that provides authe
|
|
8
8
|
* controller filters that block access to resources unless user is logged in
|
9
9
|
* a default home page that reflects user's login status
|
10
10
|
* admin screens for updating and deleting user records
|
11
|
-
|
11
|
+
|
12
12
|
This engine also includes the [Datatables](https://datatables.net/) JQuery plug-in, which is used in the user management screens. Host apps can make use of this as well.
|
13
13
|
|
14
14
|
## Prerequisites
|
@@ -128,6 +128,44 @@ skip_before_action :ensure_authenticated_user
|
|
128
128
|
|
129
129
|
`UsersController` uses `ensure_admin_user` as a `before_filter`
|
130
130
|
|
131
|
+
## Testing Support
|
132
|
+
|
133
|
+
This engine comes with a few features to help with testing.
|
134
|
+
|
135
|
+
The `UcbRailsUser::UserSessionManager::TestSessionManager` is a specialized session manager designed for test cases. It overrides the `login` method to lookup the given `uid` in the `users` table of the database. As long as the user record already exists, the `login` method will return successfully.
|
136
|
+
|
137
|
+
There is also a `UcbRailsUser::SpecHelpers` module that provides some support methods. Specifically, the `login_user` method can be used in request or integration specs to perform the behind-the-scenes work needed to login a given user. This method is implemented according to the [omniauth gem documentation.](https://github.com/omniauth/omniauth/wiki/Integration-Testing)
|
138
|
+
|
139
|
+
To add the testing support, add the following lines to your `spec_helper.rb` or `rails_helper.rb` file:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
# add this line
|
143
|
+
require 'ucb_rails_user/spec_helpers'
|
144
|
+
|
145
|
+
# then, somewhere in this block...
|
146
|
+
RSpec.configure do |config|
|
147
|
+
|
148
|
+
...
|
149
|
+
|
150
|
+
# ...add these lines
|
151
|
+
config.include UcbRailsUser::SpecHelpers
|
152
|
+
UcbRailsUser.config do |config|
|
153
|
+
config.user_session_manager = "UcbRailsUser::UserSessionManager::TestSessionManager"
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
Then, from within any request or integration spec, you should be able to do this:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
it "should do some neato feature" do
|
161
|
+
user = create(:user) # assumes you've added FactoryBot or similiar
|
162
|
+
login_user(user)
|
163
|
+
end
|
164
|
+
```
|
165
|
+
|
166
|
+
and the user should now be logged in.
|
167
|
+
|
168
|
+
|
131
169
|
## Overriding Model And Controller Behavior
|
132
170
|
|
133
171
|
The host app can add or override behavior of the `User` model and `UserController` as needed. We've followed the conventions suggested in the [Rails guide](http://guides.rubyonrails.org/engines.html#implementing-decorator-pattern-using-activesupport-concern) to make this as easy as possible.
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#
|
2
|
+
# Session manager designed to be used in tests. This bypasses the usual LDAP lookup when
|
3
|
+
# given a uid, and instead simply looks up the user in the current database.
|
4
|
+
#
|
5
|
+
# This assumes that the user already exists in the database, so your test scenario should
|
6
|
+
# set that up before attempting a login
|
7
|
+
#
|
8
|
+
module UcbRailsUser
|
9
|
+
module UserSessionManager
|
10
|
+
class TestSessionManager < ActiveInUserTable
|
11
|
+
|
12
|
+
def login(uid)
|
13
|
+
User.find_by_ldap_uid(uid)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module UcbRailsUser
|
2
|
+
module SpecHelpers
|
3
|
+
|
4
|
+
def login_user(user)
|
5
|
+
OmniAuth.config.test_mode = true
|
6
|
+
auth_mock(user.ldap_uid)
|
7
|
+
get "/login"
|
8
|
+
follow_redirect!
|
9
|
+
follow_redirect!
|
10
|
+
end
|
11
|
+
|
12
|
+
def auth_mock(uid)
|
13
|
+
OmniAuth.config.mock_auth[:cas] = OmniAuth::AuthHash.new(
|
14
|
+
provider: "cas",
|
15
|
+
uid: uid,
|
16
|
+
user_info: {
|
17
|
+
name: "mockuser"
|
18
|
+
},
|
19
|
+
credentials: {
|
20
|
+
token: "mock_token",
|
21
|
+
secret: "mock_secret"
|
22
|
+
}
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ucb_rails_user
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Downey
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2018-08-
|
14
|
+
date: 2018-08-29 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rails
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- app/models/ucb_rails_user/user_session_manager/in_people_ou.rb
|
226
226
|
- app/models/ucb_rails_user/user_session_manager/in_people_ou_add_to_users_table.rb
|
227
227
|
- app/models/ucb_rails_user/user_session_manager/ldap_person_user_wrapper.rb
|
228
|
+
- app/models/ucb_rails_user/user_session_manager/test_session_manager.rb
|
228
229
|
- app/models/user.rb
|
229
230
|
- app/views/ucb_rails_user/home/logged_in.html.haml
|
230
231
|
- app/views/ucb_rails_user/home/not_logged_in.html.haml
|
@@ -248,6 +249,7 @@ files:
|
|
248
249
|
- lib/templates/erb/scaffold/_form.html.erb
|
249
250
|
- lib/ucb_rails_user.rb
|
250
251
|
- lib/ucb_rails_user/engine.rb
|
252
|
+
- lib/ucb_rails_user/spec_helpers.rb
|
251
253
|
- lib/ucb_rails_user/version.rb
|
252
254
|
homepage: https://github.com/ucb-ist-eas/ucb_rails_user
|
253
255
|
licenses:
|
@@ -269,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
271
|
version: '0'
|
270
272
|
requirements: []
|
271
273
|
rubyforge_project:
|
272
|
-
rubygems_version: 2.
|
274
|
+
rubygems_version: 2.4.8
|
273
275
|
signing_key:
|
274
276
|
specification_version: 4
|
275
277
|
summary: Rails engine for UCB user accounts
|