challah 1.1.1 → 1.2.0.rc
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -1
- data/README.md +3 -3
- data/app/models/authorization.rb +2 -2
- data/app/models/user.rb +2 -2
- data/lib/challah.rb +60 -53
- data/lib/challah/active_record_extensions.rb +23 -0
- data/lib/challah/{authorization.rb → concerns/authorizeable.rb} +14 -19
- data/lib/challah/concerns/user/attributeable.rb +73 -0
- data/lib/challah/{user/authentication.rb → concerns/user/authenticateable.rb} +2 -2
- data/lib/challah/concerns/user/authorizable.rb +32 -0
- data/lib/challah/concerns/user/findable.rb +45 -0
- data/lib/challah/{user/password.rb → concerns/user/passwordable.rb} +2 -2
- data/lib/challah/{user/providers.rb → concerns/user/provideable.rb} +46 -6
- data/lib/challah/concerns/user/validateable.rb +21 -0
- data/lib/challah/concerns/userable.rb +20 -0
- data/lib/challah/engine.rb +1 -2
- data/lib/challah/test.rb +52 -32
- data/lib/challah/version.rb +1 -1
- metadata +14 -76
- data/lib/challah/user.rb +0 -128
- data/lib/challah/user/attributes.rb +0 -28
- data/lib/challah/user/finders.rb +0 -31
- data/lib/challah/user/reflector.rb +0 -15
- data/test/controllers/controller_test.rb +0 -34
- data/test/controllers/restrictions_controller_test.rb +0 -95
- data/test/controllers/sessions_controller_test.rb +0 -42
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/javascripts/application.js +0 -13
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -5
- data/test/dummy/app/controllers/restrictions_controller.rb +0 -25
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/models/user.rb +0 -15
- data/test/dummy/app/models/widget.rb +0 -3
- data/test/dummy/app/views/bakery/templates/layouts/sample.erb +0 -1
- data/test/dummy/app/views/bakery/templates/partials/sample.html.haml +0 -1
- data/test/dummy/app/views/bakery/templates/themes/sample.haml +0 -1
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -24
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/database.yml +0 -30
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -29
- data/test/dummy/config/environments/production.rb +0 -80
- data/test/dummy/config/environments/test.rb +0 -36
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/i18n.rb +0 -1
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -12
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/routes.rb +0 -5
- data/test/dummy/db/migrate/20140114212939_create_widgets.rb +0 -32
- data/test/dummy/db/migrate/20140307205735_create_users.challah_engine.rb +0 -34
- data/test/dummy/db/migrate/20140307205736_create_authorizations.challah_engine.rb +0 -21
- data/test/dummy/db/schema.rb +0 -81
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/test.log +0 -11547
- data/test/dummy/public/404.html +0 -58
- data/test/dummy/public/422.html +0 -58
- data/test/dummy/public/500.html +0 -57
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/factories.rb +0 -8
- data/test/models/authorization_test.rb +0 -20
- data/test/models/user_test.rb +0 -345
- data/test/services/audit_test.rb +0 -107
- data/test/services/cookie_store_test.rb +0 -97
- data/test/services/encrypter_test.rb +0 -73
- data/test/services/plugins_test.rb +0 -65
- data/test/services/random_test.rb +0 -22
- data/test/services/routes_test.rb +0 -11
- data/test/services/session_test.rb +0 -197
- data/test/services/signup_test.rb +0 -122
- data/test/services/simple_cookie_store_test.rb +0 -122
- data/test/support/stubs.rb +0 -88
- data/test/test_helper.rb +0 -47
data/test/dummy/public/404.html
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
-
<style>
|
6
|
-
body {
|
7
|
-
background-color: #EFEFEF;
|
8
|
-
color: #2E2F30;
|
9
|
-
text-align: center;
|
10
|
-
font-family: arial, sans-serif;
|
11
|
-
}
|
12
|
-
|
13
|
-
div.dialog {
|
14
|
-
width: 25em;
|
15
|
-
margin: 4em auto 0 auto;
|
16
|
-
border: 1px solid #CCC;
|
17
|
-
border-right-color: #999;
|
18
|
-
border-left-color: #999;
|
19
|
-
border-bottom-color: #BBB;
|
20
|
-
border-top: #B00100 solid 4px;
|
21
|
-
border-top-left-radius: 9px;
|
22
|
-
border-top-right-radius: 9px;
|
23
|
-
background-color: white;
|
24
|
-
padding: 7px 4em 0 4em;
|
25
|
-
}
|
26
|
-
|
27
|
-
h1 {
|
28
|
-
font-size: 100%;
|
29
|
-
color: #730E15;
|
30
|
-
line-height: 1.5em;
|
31
|
-
}
|
32
|
-
|
33
|
-
body > p {
|
34
|
-
width: 33em;
|
35
|
-
margin: 0 auto 1em;
|
36
|
-
padding: 1em 0;
|
37
|
-
background-color: #F7F7F7;
|
38
|
-
border: 1px solid #CCC;
|
39
|
-
border-right-color: #999;
|
40
|
-
border-bottom-color: #999;
|
41
|
-
border-bottom-left-radius: 4px;
|
42
|
-
border-bottom-right-radius: 4px;
|
43
|
-
border-top-color: #DADADA;
|
44
|
-
color: #666;
|
45
|
-
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
-
}
|
47
|
-
</style>
|
48
|
-
</head>
|
49
|
-
|
50
|
-
<body>
|
51
|
-
<!-- This file lives in public/404.html -->
|
52
|
-
<div class="dialog">
|
53
|
-
<h1>The page you were looking for doesn't exist.</h1>
|
54
|
-
<p>You may have mistyped the address or the page may have moved.</p>
|
55
|
-
</div>
|
56
|
-
<p>If you are the application owner check the logs for more information.</p>
|
57
|
-
</body>
|
58
|
-
</html>
|
data/test/dummy/public/422.html
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>The change you wanted was rejected (422)</title>
|
5
|
-
<style>
|
6
|
-
body {
|
7
|
-
background-color: #EFEFEF;
|
8
|
-
color: #2E2F30;
|
9
|
-
text-align: center;
|
10
|
-
font-family: arial, sans-serif;
|
11
|
-
}
|
12
|
-
|
13
|
-
div.dialog {
|
14
|
-
width: 25em;
|
15
|
-
margin: 4em auto 0 auto;
|
16
|
-
border: 1px solid #CCC;
|
17
|
-
border-right-color: #999;
|
18
|
-
border-left-color: #999;
|
19
|
-
border-bottom-color: #BBB;
|
20
|
-
border-top: #B00100 solid 4px;
|
21
|
-
border-top-left-radius: 9px;
|
22
|
-
border-top-right-radius: 9px;
|
23
|
-
background-color: white;
|
24
|
-
padding: 7px 4em 0 4em;
|
25
|
-
}
|
26
|
-
|
27
|
-
h1 {
|
28
|
-
font-size: 100%;
|
29
|
-
color: #730E15;
|
30
|
-
line-height: 1.5em;
|
31
|
-
}
|
32
|
-
|
33
|
-
body > p {
|
34
|
-
width: 33em;
|
35
|
-
margin: 0 auto 1em;
|
36
|
-
padding: 1em 0;
|
37
|
-
background-color: #F7F7F7;
|
38
|
-
border: 1px solid #CCC;
|
39
|
-
border-right-color: #999;
|
40
|
-
border-bottom-color: #999;
|
41
|
-
border-bottom-left-radius: 4px;
|
42
|
-
border-bottom-right-radius: 4px;
|
43
|
-
border-top-color: #DADADA;
|
44
|
-
color: #666;
|
45
|
-
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
-
}
|
47
|
-
</style>
|
48
|
-
</head>
|
49
|
-
|
50
|
-
<body>
|
51
|
-
<!-- This file lives in public/422.html -->
|
52
|
-
<div class="dialog">
|
53
|
-
<h1>The change you wanted was rejected.</h1>
|
54
|
-
<p>Maybe you tried to change something you didn't have access to.</p>
|
55
|
-
</div>
|
56
|
-
<p>If you are the application owner check the logs for more information.</p>
|
57
|
-
</body>
|
58
|
-
</html>
|
data/test/dummy/public/500.html
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>We're sorry, but something went wrong (500)</title>
|
5
|
-
<style>
|
6
|
-
body {
|
7
|
-
background-color: #EFEFEF;
|
8
|
-
color: #2E2F30;
|
9
|
-
text-align: center;
|
10
|
-
font-family: arial, sans-serif;
|
11
|
-
}
|
12
|
-
|
13
|
-
div.dialog {
|
14
|
-
width: 25em;
|
15
|
-
margin: 4em auto 0 auto;
|
16
|
-
border: 1px solid #CCC;
|
17
|
-
border-right-color: #999;
|
18
|
-
border-left-color: #999;
|
19
|
-
border-bottom-color: #BBB;
|
20
|
-
border-top: #B00100 solid 4px;
|
21
|
-
border-top-left-radius: 9px;
|
22
|
-
border-top-right-radius: 9px;
|
23
|
-
background-color: white;
|
24
|
-
padding: 7px 4em 0 4em;
|
25
|
-
}
|
26
|
-
|
27
|
-
h1 {
|
28
|
-
font-size: 100%;
|
29
|
-
color: #730E15;
|
30
|
-
line-height: 1.5em;
|
31
|
-
}
|
32
|
-
|
33
|
-
body > p {
|
34
|
-
width: 33em;
|
35
|
-
margin: 0 auto 1em;
|
36
|
-
padding: 1em 0;
|
37
|
-
background-color: #F7F7F7;
|
38
|
-
border: 1px solid #CCC;
|
39
|
-
border-right-color: #999;
|
40
|
-
border-bottom-color: #999;
|
41
|
-
border-bottom-left-radius: 4px;
|
42
|
-
border-bottom-right-radius: 4px;
|
43
|
-
border-top-color: #DADADA;
|
44
|
-
color: #666;
|
45
|
-
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
46
|
-
}
|
47
|
-
</style>
|
48
|
-
</head>
|
49
|
-
|
50
|
-
<body>
|
51
|
-
<!-- This file lives in public/500.html -->
|
52
|
-
<div class="dialog">
|
53
|
-
<h1>We're sorry, but something went wrong.</h1>
|
54
|
-
</div>
|
55
|
-
<p>If you are the application owner check the logs for more information.</p>
|
56
|
-
</body>
|
57
|
-
</html>
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/test/factories.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class AuthorizationTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
context "The Authorization class" do
|
6
|
-
|
7
|
-
should "have a list of attributes that are hashable" do
|
8
|
-
expected_columns = %w( id uid token expires_at ).sort
|
9
|
-
|
10
|
-
assert_equal expected_columns, Authorization.hashable_attributes.sort
|
11
|
-
end
|
12
|
-
|
13
|
-
should "have a reference to the users model" do
|
14
|
-
assert_equal User, Authorization.user_model
|
15
|
-
assert_equal 'users', Authorization.users_table_name
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/test/models/user_test.rb
DELETED
@@ -1,345 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class UserTest < ActiveSupport::TestCase
|
4
|
-
should validate_presence_of :email
|
5
|
-
should validate_presence_of :first_name
|
6
|
-
should validate_presence_of :last_name
|
7
|
-
|
8
|
-
context "With an existing user" do
|
9
|
-
setup do
|
10
|
-
create(:user)
|
11
|
-
end
|
12
|
-
|
13
|
-
should validate_uniqueness_of :email
|
14
|
-
end
|
15
|
-
|
16
|
-
context "A User class" do
|
17
|
-
|
18
|
-
should "find a user by username or email" do
|
19
|
-
user_one = build(:user, :username => ' Test-user ', :email => 'tester@example.com')
|
20
|
-
user_two = build(:user, :username => 'test-user-2 ', :email => 'tester2@example.com')
|
21
|
-
|
22
|
-
user_one.password!('test123')
|
23
|
-
user_two.password!('test123')
|
24
|
-
|
25
|
-
user_one.save
|
26
|
-
user_two.save
|
27
|
-
|
28
|
-
assert_equal user_one, ::User.find_for_session('test-user')
|
29
|
-
assert_equal user_one, ::User.find_for_session('tester@example.com')
|
30
|
-
|
31
|
-
assert_equal user_one, ::User.find_for_session('Test-user')
|
32
|
-
assert_equal user_one, ::User.find_for_session('tester@example.com')
|
33
|
-
|
34
|
-
assert_equal user_two, ::User.find_for_session('test-user-2')
|
35
|
-
assert_equal user_two, ::User.find_for_session('tester2@example.com')
|
36
|
-
|
37
|
-
assert_equal nil, ::User.find_for_session(' ')
|
38
|
-
assert_equal nil, ::User.find_for_session('not-existing')
|
39
|
-
end
|
40
|
-
|
41
|
-
should "have a reference to the authorizations model" do
|
42
|
-
assert_equal Authorization, User.authorization_model
|
43
|
-
assert_equal 'authorizations', User.authorizations_table_name
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
context "A user instance" do
|
49
|
-
should "have a name attribute that returns the full name" do
|
50
|
-
user = ::User.new
|
51
|
-
|
52
|
-
user.stubs(:first_name).returns('Cal')
|
53
|
-
user.stubs(:last_name).returns('Ripken')
|
54
|
-
|
55
|
-
assert_equal "Cal Ripken", user.name
|
56
|
-
assert_equal "Cal R.", user.small_name
|
57
|
-
end
|
58
|
-
|
59
|
-
should "have an active? user flag" do
|
60
|
-
user = ::User.new
|
61
|
-
|
62
|
-
user.active = true
|
63
|
-
assert_equal true, user.active
|
64
|
-
assert_equal true, user.active?
|
65
|
-
assert_equal true, user.valid_session?
|
66
|
-
|
67
|
-
user.active = false
|
68
|
-
assert_equal false, user.active
|
69
|
-
assert_equal false, user.active?
|
70
|
-
assert_equal false, user.valid_session?
|
71
|
-
end
|
72
|
-
|
73
|
-
# Only for Rails 3
|
74
|
-
if defined?(ActiveModel::MassAssignmentSecurity::Error)
|
75
|
-
should "not allow updating of certain protected attributes" do
|
76
|
-
user = create(:user, :first_name => 'Old', :last_name => 'Nombre')
|
77
|
-
|
78
|
-
assert_equal false, user.new_record?
|
79
|
-
|
80
|
-
assert_equal 0, user.created_by
|
81
|
-
assert_equal 'Old Nombre', user.name
|
82
|
-
|
83
|
-
assert_raise ActiveModel::MassAssignmentSecurity::Error do
|
84
|
-
user.update_attributes({
|
85
|
-
:created_by => 1,
|
86
|
-
:first_name => 'New',
|
87
|
-
:last_name => 'Name'
|
88
|
-
})
|
89
|
-
end
|
90
|
-
|
91
|
-
assert_equal 0, user.created_by
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
should "create a user with password and authenticate them" do
|
96
|
-
user = build(:user)
|
97
|
-
|
98
|
-
user.password = 'abc123'
|
99
|
-
user.password_confirmation = 'abc123'
|
100
|
-
assert_equal 'abc123', user.password
|
101
|
-
|
102
|
-
assert user.save
|
103
|
-
|
104
|
-
assert_equal true, user.provider?(:password)
|
105
|
-
assert_not_nil user.provider(:password)
|
106
|
-
|
107
|
-
assert_equal true, user.authenticate('abc123')
|
108
|
-
assert_equal true, user.authenticate(:password, 'abc123')
|
109
|
-
assert_equal false, user.authenticate('test123')
|
110
|
-
end
|
111
|
-
|
112
|
-
should "be able to update a user without changing their password" do
|
113
|
-
user = build(:user)
|
114
|
-
user.password!('abc123')
|
115
|
-
user.save
|
116
|
-
|
117
|
-
assert_equal true, user.authenticate('abc123')
|
118
|
-
|
119
|
-
user.first_name = 'New'
|
120
|
-
user.password = ''
|
121
|
-
user.password_confirmation = ''
|
122
|
-
assert user.save
|
123
|
-
|
124
|
-
assert_equal 'New', user.first_name
|
125
|
-
assert_equal true, user.authenticate('abc123')
|
126
|
-
end
|
127
|
-
|
128
|
-
should "validate a password" do
|
129
|
-
user = build(:user)
|
130
|
-
user.password!('abc123')
|
131
|
-
assert_equal true, user.valid?
|
132
|
-
|
133
|
-
user.username = 'user123'
|
134
|
-
user.password = ''
|
135
|
-
user.password_confirmation = ''
|
136
|
-
assert_equal false, user.valid?
|
137
|
-
assert user.errors.full_messages.include?("Password can't be blank")
|
138
|
-
|
139
|
-
user.password = 'abc'
|
140
|
-
user.password_confirmation = 'abc'
|
141
|
-
assert_equal false, user.valid?
|
142
|
-
assert user.errors.full_messages.include?("Password is not a valid password. Please enter at least 4 letters or numbers.")
|
143
|
-
|
144
|
-
user.password = 'abc456'
|
145
|
-
user.password_confirmation = 'abc123'
|
146
|
-
assert_equal false, user.valid?
|
147
|
-
assert user.errors.full_messages.include?("Password does not match the confirmation password.")
|
148
|
-
end
|
149
|
-
|
150
|
-
should "create a password without confirmation when using !" do
|
151
|
-
user = build(:user)
|
152
|
-
user.password!('holla')
|
153
|
-
assert_equal true, user.valid?
|
154
|
-
end
|
155
|
-
|
156
|
-
should "reasonable validate an email address" do
|
157
|
-
user = build(:user)
|
158
|
-
|
159
|
-
user.email = 'john@challah.me'
|
160
|
-
assert_equal true, user.valid?
|
161
|
-
|
162
|
-
user.email = 'john@challah.m@me.e'
|
163
|
-
assert_equal false, user.valid?
|
164
|
-
end
|
165
|
-
|
166
|
-
should "always lower case a username when setting" do
|
167
|
-
user = build(:user)
|
168
|
-
user.username = 'JimBob'
|
169
|
-
assert_equal 'jimbob', user.username
|
170
|
-
end
|
171
|
-
|
172
|
-
should "not authenticate with a password if none is given" do
|
173
|
-
user = create(:user)
|
174
|
-
assert_equal false, user.authenticate_with_password('abc123')
|
175
|
-
end
|
176
|
-
|
177
|
-
should "authenticate through various means by default" do
|
178
|
-
user = build(:user)
|
179
|
-
user.password!('abc123')
|
180
|
-
user.save
|
181
|
-
|
182
|
-
# By password
|
183
|
-
assert_equal false, user.authenticate_with_password('test123')
|
184
|
-
assert_equal false, user.authenticate(:password, 'test123')
|
185
|
-
assert_equal false, user.authenticate('test123')
|
186
|
-
|
187
|
-
assert_equal true, user.authenticate_with_password('abc123')
|
188
|
-
assert_equal true, user.authenticate(:password, 'abc123')
|
189
|
-
assert_equal true, user.authenticate('abc123')
|
190
|
-
|
191
|
-
# By api key
|
192
|
-
user.stubs(:api_key).returns('this-is-my-api-key')
|
193
|
-
|
194
|
-
assert_equal true, user.authenticate_with_api_key('this-is-my-api-key')
|
195
|
-
assert_equal true, user.authenticate_with_api_key('this-is-my-api-key')
|
196
|
-
|
197
|
-
assert_equal false, user.authenticate_with_api_key('this-is-not-my-api-key')
|
198
|
-
assert_equal false, user.authenticate_with_api_key('this-is-not-my-api-key')
|
199
|
-
|
200
|
-
# With an unknown authentication method
|
201
|
-
assert_equal false, user.authenticate(:blah, 'sdsd', 'sdlsk')
|
202
|
-
end
|
203
|
-
|
204
|
-
should "be able to change a username" do
|
205
|
-
user = create(:user)
|
206
|
-
|
207
|
-
user.password!('test123')
|
208
|
-
user.username = 'john'
|
209
|
-
user.save
|
210
|
-
|
211
|
-
# reload
|
212
|
-
user = User.find_by_id(user.id)
|
213
|
-
|
214
|
-
assert_equal true, user.authenticate('test123')
|
215
|
-
assert_equal 'john', user.username
|
216
|
-
|
217
|
-
user.username = 'johndoe'
|
218
|
-
user.save
|
219
|
-
|
220
|
-
# reload
|
221
|
-
user = User.find_by_id(user.id)
|
222
|
-
|
223
|
-
assert_equal true, user.authenticate('test123')
|
224
|
-
assert_equal 'johndoe', user.username
|
225
|
-
end
|
226
|
-
|
227
|
-
should "have successful and failed authentication methods" do
|
228
|
-
user = create(:user)
|
229
|
-
|
230
|
-
assert_nil user.last_session_ip
|
231
|
-
assert_nil user.last_session_at
|
232
|
-
|
233
|
-
assert_difference 'user.session_count', 1 do
|
234
|
-
user.successful_authentication!('192.168.0.1')
|
235
|
-
end
|
236
|
-
|
237
|
-
assert_not_nil user.last_session_ip
|
238
|
-
assert_not_nil user.last_session_at
|
239
|
-
|
240
|
-
assert_difference 'user.failed_auth_count', 1 do
|
241
|
-
user.failed_authentication!
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
should "calculate an email hash on save" do
|
246
|
-
user = build(:user)
|
247
|
-
|
248
|
-
user.email = 'tester@challah.me'
|
249
|
-
assert user.save
|
250
|
-
assert_equal '859ea8a4ea69b321df4992ca14c08d6b', user.email_hash
|
251
|
-
|
252
|
-
user.email = 'tester-too@challah.me'
|
253
|
-
assert user.save
|
254
|
-
assert_equal '45ab23dd8eb9a00f61cef27004b38b01', user.email_hash
|
255
|
-
end
|
256
|
-
|
257
|
-
should "have custom authorization providers" do
|
258
|
-
user = create(:user)
|
259
|
-
|
260
|
-
auth = Authorization.set({
|
261
|
-
:user_id => user.id,
|
262
|
-
:provider => 'custom',
|
263
|
-
:uid => '12345',
|
264
|
-
:token => 'abcdef1234569'
|
265
|
-
})
|
266
|
-
|
267
|
-
assert_equal false, user.provider?(:password)
|
268
|
-
assert_equal nil, user.provider(:password)
|
269
|
-
|
270
|
-
expected_auth = {
|
271
|
-
:id => auth.id,
|
272
|
-
:uid => '12345',
|
273
|
-
:token => 'abcdef1234569',
|
274
|
-
:expires_at => nil
|
275
|
-
}
|
276
|
-
|
277
|
-
assert_equal true, user.provider?(:custom)
|
278
|
-
assert_equal true, user.custom_provider?
|
279
|
-
|
280
|
-
assert_equal expected_auth, user.provider(:custom)
|
281
|
-
assert_equal expected_auth, user.custom_provider
|
282
|
-
end
|
283
|
-
|
284
|
-
should "have default method_missing when not looking for a provider" do
|
285
|
-
user = create(:user)
|
286
|
-
assert_equal false, user.custom_provider?
|
287
|
-
|
288
|
-
assert_raise NoMethodError do
|
289
|
-
user.does_not_exist?
|
290
|
-
end
|
291
|
-
end
|
292
|
-
|
293
|
-
should "clear authorizations when removing a user" do
|
294
|
-
user = create(:user)
|
295
|
-
|
296
|
-
Authorization.set({
|
297
|
-
:user_id => user.id,
|
298
|
-
:provider => 'custom',
|
299
|
-
:uid => '12345',
|
300
|
-
:token => 'abcdef1234569'
|
301
|
-
})
|
302
|
-
|
303
|
-
user.password!('test123')
|
304
|
-
user.save
|
305
|
-
|
306
|
-
assert_difference 'User.count', -1 do
|
307
|
-
assert_difference 'Authorization.count', -2 do
|
308
|
-
user.destroy
|
309
|
-
end
|
310
|
-
end
|
311
|
-
end
|
312
|
-
|
313
|
-
should "set provider attributes" do
|
314
|
-
user = build(:user)
|
315
|
-
|
316
|
-
user.provider_attributes = {
|
317
|
-
:fake => { :uid => "1", "token" => 'me' }
|
318
|
-
}
|
319
|
-
|
320
|
-
assert_equal true, user.provider?(:fake)
|
321
|
-
assert_equal true, user.valid_provider?(:fake)
|
322
|
-
|
323
|
-
assert_difference [ 'User.count', 'Authorization.count' ], 1 do
|
324
|
-
assert user.save
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
should "not add invalid providers" do
|
329
|
-
provider_attributes = {
|
330
|
-
"fake" => { :uid => "1", "token" => 'not-me' }
|
331
|
-
}
|
332
|
-
|
333
|
-
user = build(:user, :provider_attributes => provider_attributes)
|
334
|
-
|
335
|
-
assert_equal true, user.provider?(:fake)
|
336
|
-
assert_equal false, user.valid_provider?(:fake)
|
337
|
-
|
338
|
-
assert_difference [ 'User.count' ], 1 do
|
339
|
-
assert_no_difference [ 'Authorization.count' ] do
|
340
|
-
assert user.save
|
341
|
-
end
|
342
|
-
end
|
343
|
-
end
|
344
|
-
end
|
345
|
-
end
|