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
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SignupTest < ActiveSupport::TestCase
|
4
|
-
context "A signup instance" do
|
5
|
-
should "be properly named" do
|
6
|
-
assert_equal "Signup", Challah::Signup.model_name
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
context "A user" do
|
11
|
-
should "sign up for an app with a password" do
|
12
|
-
signup = Challah::Signup.new
|
13
|
-
signup.first_name = 'Avon'
|
14
|
-
signup.last_name = 'Barksdale'
|
15
|
-
signup.email = 'avon@challah.me'
|
16
|
-
signup.password = 'test123'
|
17
|
-
signup.password_confirmation = 'test123'
|
18
|
-
|
19
|
-
assert_difference [ 'User.count', 'Authorization.count' ], 1 do
|
20
|
-
assert signup.save, 'Signup could not save!'
|
21
|
-
end
|
22
|
-
|
23
|
-
assert_equal false, signup.new_record?
|
24
|
-
assert_equal "Avon Barksdale", signup.user.name
|
25
|
-
assert_equal true, signup.user.authenticate_with_password('test123')
|
26
|
-
assert_equal :password, signup.provider
|
27
|
-
end
|
28
|
-
|
29
|
-
should "sign up using a params hash" do
|
30
|
-
user_params = {
|
31
|
-
first_name: 'Stringer',
|
32
|
-
last_name: 'Bell',
|
33
|
-
email: 'stringer@challah.me',
|
34
|
-
password: 'abc123',
|
35
|
-
password_confirmation: 'abc123'
|
36
|
-
}
|
37
|
-
|
38
|
-
signup = Challah::Signup.new(user_params)
|
39
|
-
|
40
|
-
assert_difference [ 'User.count', 'Authorization.count' ], 1 do
|
41
|
-
assert signup.save, 'Signup could not save'
|
42
|
-
end
|
43
|
-
|
44
|
-
assert_equal false, signup.new_record?
|
45
|
-
assert_equal 'Stringer Bell', signup.user.name
|
46
|
-
assert_equal true, signup.user.authenticate_with_password('abc123')
|
47
|
-
end
|
48
|
-
|
49
|
-
should "not sign up without a password" do
|
50
|
-
signup = Challah::Signup.new
|
51
|
-
signup.first_name = 'Avon'
|
52
|
-
signup.last_name = 'Barksdale'
|
53
|
-
signup.email = 'avon@challah.me'
|
54
|
-
|
55
|
-
assert_no_difference [ 'User.count', 'Authorization.count' ] do
|
56
|
-
assert_equal false, signup.save
|
57
|
-
end
|
58
|
-
|
59
|
-
assert_equal true, signup.new_record?
|
60
|
-
assert_equal "Avon Barksdale", signup.user.name
|
61
|
-
assert_equal :password, signup.provider
|
62
|
-
end
|
63
|
-
|
64
|
-
should "sign up with another valid provider" do
|
65
|
-
signup = Challah::Signup.new
|
66
|
-
signup.first_name = 'Avon'
|
67
|
-
signup.last_name = 'Barksdale'
|
68
|
-
signup.email = 'avon@challah.me'
|
69
|
-
signup.provider = "fake"
|
70
|
-
signup.password = ""
|
71
|
-
signup.password_confirmation = ""
|
72
|
-
signup.provider_attributes = { "fake" => { "uid" => "1", "token" => "me" } }
|
73
|
-
|
74
|
-
assert_difference [ 'User.count', 'Authorization.count' ], 1 do
|
75
|
-
assert signup.save, 'Signup could not save'
|
76
|
-
end
|
77
|
-
|
78
|
-
assert_equal :fake, signup.provider
|
79
|
-
assert_equal "me", signup.user.providers[:fake].fetch(:token)
|
80
|
-
end
|
81
|
-
|
82
|
-
should "not sign up without any providers" do
|
83
|
-
signup = Challah::Signup.new
|
84
|
-
signup.first_name = 'Avon'
|
85
|
-
signup.last_name = 'Barksdale'
|
86
|
-
signup.email = 'avon@challah.me'
|
87
|
-
signup.provider = nil
|
88
|
-
|
89
|
-
assert_no_difference [ 'User.count', 'Authorization.count' ] do
|
90
|
-
assert_equal false, signup.save
|
91
|
-
end
|
92
|
-
|
93
|
-
assert_equal true, signup.new_record?
|
94
|
-
assert_equal "Avon Barksdale", signup.user.name
|
95
|
-
assert_equal nil, signup.provider
|
96
|
-
end
|
97
|
-
|
98
|
-
should "not sign up with an invalid provider" do
|
99
|
-
signup = Challah::Signup.new
|
100
|
-
signup.first_name = 'Avon'
|
101
|
-
signup.last_name = 'Barksdale'
|
102
|
-
signup.email = 'avon@challah.me'
|
103
|
-
signup.provider = "blank"
|
104
|
-
signup.provider_attributes = { "blank" => { "uid" => "1", "token" => "1" } }
|
105
|
-
|
106
|
-
assert_no_difference [ 'User.count', 'Authorization.count' ], 1 do
|
107
|
-
assert_equal false, signup.save
|
108
|
-
end
|
109
|
-
|
110
|
-
assert_equal true, signup.new_record?
|
111
|
-
assert_equal "Avon Barksdale", signup.user.name
|
112
|
-
assert_equal :blank, signup.provider
|
113
|
-
end
|
114
|
-
|
115
|
-
should "consolidate error messages" do
|
116
|
-
signup = Challah::Signup.new
|
117
|
-
assert_equal false, signup.save
|
118
|
-
expected_error_fields = [ :first_name, :last_name, :email, :password ].sort
|
119
|
-
assert_equal expected_error_fields, signup.errors.messages.keys.sort
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SimpleCookieStoreTest < ActiveSupport::TestCase
|
4
|
-
include Challah
|
5
|
-
|
6
|
-
class FakeUserModel
|
7
|
-
|
8
|
-
def self.table_name
|
9
|
-
'fake_user_peoples'
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
context "The SimpleCookieStore class" do
|
15
|
-
setup do
|
16
|
-
@user = create(:user)
|
17
|
-
@request = MockRequest.new
|
18
|
-
end
|
19
|
-
|
20
|
-
should "save session in a request cookie store" do
|
21
|
-
assert_equal [], @request.cookies.keys
|
22
|
-
|
23
|
-
session = Session.new(@request)
|
24
|
-
session.store = SimpleCookieStore.new(session)
|
25
|
-
session.persist = true
|
26
|
-
session.user = @user
|
27
|
-
session.save
|
28
|
-
|
29
|
-
assert_equal %w( challah-s challah-v ), @request.cookies.keys.sort
|
30
|
-
assert_equal "#{@user.persistence_token}@#{@user.id}", @request.cookies['challah-s'][:value]
|
31
|
-
assert_equal "test.dev", @request.cookies['challah-s'][:domain]
|
32
|
-
|
33
|
-
assert_equal Encrypter.md5("#{@user.persistence_token}@#{@user.id}"), @request.cookies['challah-v'][:value]
|
34
|
-
assert_equal "test.dev", @request.cookies['challah-v'][:domain]
|
35
|
-
end
|
36
|
-
|
37
|
-
should "save session in a namespaced cookie store for non user tables" do
|
38
|
-
assert_equal [], @request.cookies.keys
|
39
|
-
|
40
|
-
session = Session.new(@request, {}, FakeUserModel)
|
41
|
-
session.store = SimpleCookieStore.new(session)
|
42
|
-
session.persist = true
|
43
|
-
session.user = @user
|
44
|
-
session.save
|
45
|
-
|
46
|
-
assert_equal %w( challah-d635fd-s challah-d635fd-v ), @request.cookies.keys.sort
|
47
|
-
assert_equal "#{@user.persistence_token}@#{@user.id}", @request.cookies['challah-d635fd-s'][:value]
|
48
|
-
assert_equal "test.dev", @request.cookies['challah-d635fd-s'][:domain]
|
49
|
-
|
50
|
-
assert_equal Encrypter.md5("#{@user.persistence_token}@#{@user.id}"), @request.cookies['challah-d635fd-v'][:value]
|
51
|
-
assert_equal "test.dev", @request.cookies['challah-d635fd-v'][:domain]
|
52
|
-
end
|
53
|
-
|
54
|
-
should "be able to inspect the store" do
|
55
|
-
session = Session.new(@request)
|
56
|
-
session.store = SimpleCookieStore.new(session)
|
57
|
-
session.persist = true
|
58
|
-
session.user = @user
|
59
|
-
session.save
|
60
|
-
|
61
|
-
assert session.store.inspect =~ /<SimpleCookieStore:(.*?)>/, 'Does not match'
|
62
|
-
end
|
63
|
-
|
64
|
-
should "read cookies and detect tampered verification cookies" do
|
65
|
-
assert_equal [], @request.cookies.keys
|
66
|
-
|
67
|
-
session = Session.new(@request)
|
68
|
-
session.store = SimpleCookieStore.new(session)
|
69
|
-
session.persist = true
|
70
|
-
session.user = @user
|
71
|
-
session.save
|
72
|
-
|
73
|
-
validation_cookie_val = Encrypter.md5("#{@user.persistence_token}@#{@user.id}")
|
74
|
-
session_cookie_val = "#{@user.persistence_token}@#{@user.id}"
|
75
|
-
|
76
|
-
assert_equal session_cookie_val, @request.cookies['challah-s'][:value]
|
77
|
-
assert_equal session_cookie_val, session.store.send(:session_cookie)[:value]
|
78
|
-
assert_equal validation_cookie_val, @request.cookies['challah-v'][:value]
|
79
|
-
assert_equal validation_cookie_val, session.store.send(:validation_cookie)[:value]
|
80
|
-
|
81
|
-
session.store.stubs(:validation_cookie).returns(validation_cookie_val)
|
82
|
-
session.store.stubs(:session_cookie).returns(session_cookie_val)
|
83
|
-
|
84
|
-
session2 = Session.new(@request)
|
85
|
-
session2.persist = true
|
86
|
-
session2.store = session.store
|
87
|
-
session2.read
|
88
|
-
|
89
|
-
assert_equal true, session2.store.send(:existing?)
|
90
|
-
assert_equal true, session2.valid?
|
91
|
-
assert_equal @user.id, session2.user_id
|
92
|
-
|
93
|
-
session.store.stubs(:validation_cookie).returns('bad-value')
|
94
|
-
|
95
|
-
session3 = Session.new(@request)
|
96
|
-
session3.store = session.store
|
97
|
-
session3.read
|
98
|
-
|
99
|
-
assert_equal false, session3.store.send(:existing?)
|
100
|
-
assert_equal false, session3.valid?
|
101
|
-
end
|
102
|
-
|
103
|
-
should "delete sessions from cookies" do
|
104
|
-
session = Session.new(@request)
|
105
|
-
session.store = SimpleCookieStore.new(session)
|
106
|
-
session.user = @user
|
107
|
-
session.persist = true
|
108
|
-
|
109
|
-
session.save
|
110
|
-
|
111
|
-
assert_equal true, session.valid?
|
112
|
-
assert_equal @user, session.user
|
113
|
-
assert_equal %w( challah-s challah-v ), @request.cookies.keys.sort
|
114
|
-
|
115
|
-
session.destroy
|
116
|
-
|
117
|
-
assert_equal false, session.valid?
|
118
|
-
assert_equal nil, session.user
|
119
|
-
assert_equal [], @request.cookies.keys.sort
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
data/test/support/stubs.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
class MockController
|
2
|
-
include Challah::Controller
|
3
|
-
|
4
|
-
attr_accessor :request, :session, :params
|
5
|
-
|
6
|
-
def initialize()
|
7
|
-
@request = MockRequest.new
|
8
|
-
@session ||= {}
|
9
|
-
@params ||= {}
|
10
|
-
end
|
11
|
-
|
12
|
-
def redirect_to(*args)
|
13
|
-
# do nothing
|
14
|
-
end
|
15
|
-
|
16
|
-
def login_path
|
17
|
-
"/login"
|
18
|
-
end
|
19
|
-
|
20
|
-
def logout_path
|
21
|
-
"/logout"
|
22
|
-
end
|
23
|
-
|
24
|
-
def signin_path
|
25
|
-
"/sign-in"
|
26
|
-
end
|
27
|
-
|
28
|
-
def signout_path
|
29
|
-
"/sign-out"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class MockRequest
|
34
|
-
attr_accessor :cookie_jar, :session_options, :url
|
35
|
-
|
36
|
-
class MockCookieJar < Hash
|
37
|
-
def delete(key, options = {})
|
38
|
-
super(key)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def initialize
|
43
|
-
@cookie_jar = MockCookieJar.new
|
44
|
-
@session_options = { :domain => 'test.dev' }
|
45
|
-
@url = "http://example.com/"
|
46
|
-
end
|
47
|
-
|
48
|
-
def cookies
|
49
|
-
@cookie_jar
|
50
|
-
end
|
51
|
-
|
52
|
-
def cookies=(value)
|
53
|
-
@cookie_jar = value
|
54
|
-
end
|
55
|
-
|
56
|
-
def remote_ip
|
57
|
-
"8.8.8.8"
|
58
|
-
end
|
59
|
-
|
60
|
-
def user_agent
|
61
|
-
"Some Cool Browser"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
class FakeProvider
|
66
|
-
def self.save(record)
|
67
|
-
set(record.fake_provider.merge(user_id: record.id))
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.set(options = {})
|
71
|
-
user_id = options.fetch(:user_id)
|
72
|
-
uid = options.fetch(:uid, '')
|
73
|
-
token = options.fetch(:token, '')
|
74
|
-
|
75
|
-
Authorization.set({
|
76
|
-
provider: :fake,
|
77
|
-
user_id: user_id,
|
78
|
-
uid: uid,
|
79
|
-
token: token
|
80
|
-
})
|
81
|
-
end
|
82
|
-
|
83
|
-
def self.valid?(record)
|
84
|
-
record.fake_provider? and record.fake_provider.fetch(:token) == 'me'
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
Challah.register_provider :fake, FakeProvider
|
data/test/test_helper.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# Coverage reporting, needs to be loaded first to capture all code coverage stats
|
2
|
-
require 'simplecov'
|
3
|
-
|
4
|
-
# Configure Rails Environment
|
5
|
-
ENV["RAILS_ENV"] ||= "test"
|
6
|
-
|
7
|
-
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
8
|
-
|
9
|
-
# Some other dependencies for testing w/ shoulda and factory girl
|
10
|
-
require 'shoulda'
|
11
|
-
require 'mocha/setup'
|
12
|
-
require 'factory_girl'
|
13
|
-
require 'factories'
|
14
|
-
require 'rails/test_help'
|
15
|
-
|
16
|
-
Rails.backtrace_cleaner.remove_silencers!
|
17
|
-
|
18
|
-
# Load the challah libraries
|
19
|
-
require 'challah'
|
20
|
-
require 'challah/test'
|
21
|
-
|
22
|
-
db_files = Dir["#{ Rails.root.join("db") }/**/*challah*.rb"]
|
23
|
-
|
24
|
-
# Allow repeat tests to run, dropping the db after each suite run
|
25
|
-
# (*not called on CI server)
|
26
|
-
if db_files.size > 0
|
27
|
-
`rake --rakefile #{ File.expand_path("../dummy/Rakefile", __FILE__) } db:test:purge`
|
28
|
-
|
29
|
-
FileUtils.rm_rf(db_files)
|
30
|
-
FileUtils.rm_rf(Rails.root.join("db", "schema.rb"))
|
31
|
-
end
|
32
|
-
|
33
|
-
`rake --rakefile #{ File.expand_path("../dummy/Rakefile", __FILE__) } challah_engine:install:migrations`
|
34
|
-
`rake --rakefile #{ File.expand_path("../dummy/Rakefile", __FILE__) } db:migrate`
|
35
|
-
|
36
|
-
Dir["#{ File.dirname(__FILE__) }/support/**/*.rb"].each { |f| require f }
|
37
|
-
|
38
|
-
class ActiveSupport::TestCase
|
39
|
-
ActiveRecord::Migration.check_pending!
|
40
|
-
|
41
|
-
fixtures :all
|
42
|
-
|
43
|
-
include FactoryGirl::Syntax::Methods
|
44
|
-
|
45
|
-
self.use_transactional_fixtures = true
|
46
|
-
end
|
47
|
-
|