solidus_auth_devise 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_auth_devise might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 68251ee8c8dbd193472c5d9e77c082699d99cbec
4
- data.tar.gz: 9230ce9f639bd25adaa884ec143131a963279777
3
+ metadata.gz: 069e3cf3d0b487a02fd0cd8f90229d91d21ee49c
4
+ data.tar.gz: 8c03169fd0298d4ddeeb75b82974fffcd97faf5c
5
5
  SHA512:
6
- metadata.gz: abfef5712300c46f1af842e9107ce7484e5a313a98ec04e16a00fdb4ba764f62387aeb64ac55c62a1d69423ff83ad99b9328e1691b40346e170a994ddedc10b6
7
- data.tar.gz: 9e090cb6ddbfda0e779e9b5159f3f8a78e67d8becc9050d0124aeac557c421601e19fbbdd9da816d7d24b07db3e711ba5d7f24f4266a41b3a9d9b35b53a4dce4
6
+ metadata.gz: b4cfbbb456e6a83241eb691cf1fa639bf30a8803ceb2a24cf2f18b7f36cd091ee20b16eb44cfe38c2e059afbe0f53ac23c0580b906f12265ca597845ce5b546a
7
+ data.tar.gz: f4caa243ed037ab7dfe34e629c36b43a5e0cce9d2b6ecc82d353917bd1e5389a0b1a42fc9c92ac5a95ab22481313a206559f39d559aecde8927e9a158b4c6734
data/.gitignore CHANGED
@@ -7,3 +7,5 @@ Gemfile.lock
7
7
  .ruby-gemsets
8
8
  .ruby-version
9
9
  .bundle
10
+ pkg
11
+ vendor
@@ -1,11 +1,16 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 1.9.3
4
- - 2.1.3
4
+ - 2.1.8
5
5
  env:
6
- - DB=mysql
7
- - DB=postgres
8
- before_script:
9
- - bundle exec rake test_app
10
- - export DISPLAY=:99.0
11
- - sh -e /etc/init.d/xvfb start
6
+ matrix:
7
+ - SOLIDUS_BRANCH=v1.0 DB=postgres
8
+ - SOLIDUS_BRANCH=v1.1 DB=postgres
9
+ - SOLIDUS_BRANCH=v1.2 DB=postgres
10
+ - SOLIDUS_BRANCH=v1.3 DB=postgres
11
+ - SOLIDUS_BRANCH=master DB=postgres
12
+ - SOLIDUS_BRANCH=v1.0 DB=mysql
13
+ - SOLIDUS_BRANCH=v1.1 DB=mysql
14
+ - SOLIDUS_BRANCH=v1.2 DB=mysql
15
+ - SOLIDUS_BRANCH=v1.3 DB=mysql
16
+ - SOLIDUS_BRANCH=master DB=mysql
data/Gemfile CHANGED
@@ -1,6 +1,10 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "solidus", git: "git@github.com:solidusio/solidus.git", branch: "master"
3
+ branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
4
+ gem "solidus", github: "solidusio/solidus", branch: branch
5
+
6
+ gem 'pg'
7
+ gem 'mysql2'
4
8
 
5
9
  group :development, :test do
6
10
  gem "pry-rails"
data/README.md CHANGED
@@ -71,13 +71,7 @@ Inside of your host application you can then use CanCan like you normally would.
71
71
  Testing
72
72
  -------
73
73
 
74
- Until Solidus is publicly available, the easiest way to satisfy the Solidus dependancy is with a local Bundler override:
75
-
76
- ```shell
77
- bundle config local.spree /path/to/local/solidus/repository
78
- ```
79
-
80
- Then just run the following to automatically build a dummy app if necessary and run the tests:
74
+ Run the following to automatically build a dummy app if necessary and run the tests:
81
75
 
82
76
  ```shell
83
77
  bundle exec rake
@@ -3,7 +3,7 @@ module Spree
3
3
  include UserMethods
4
4
 
5
5
  devise :database_authenticatable, :registerable, :recoverable,
6
- :rememberable, :trackable, :validatable, :encryptable, :encryptor => 'authlogic_sha512'
6
+ :rememberable, :trackable, :validatable, :encryptable
7
7
  devise :confirmable if Spree::Auth::Config[:confirmable]
8
8
 
9
9
  acts_as_paranoid
@@ -38,6 +38,7 @@ Devise.setup do |config|
38
38
  # For bcrypt, this is the cost for hashing the password and defaults to 10. If
39
39
  # using other encryptors, it sets how many times you want the password re-encrypted.
40
40
  config.stretches = 20
41
+ config.encryptor = 'authlogic_sha512'
41
42
 
42
43
  # Setup a pepper to generate the encrypted password.
43
44
  config.pepper = Rails.configuration.secret_token
@@ -2,7 +2,7 @@
2
2
  Warden::Manager.after_set_user except: :fetch do |user, auth, opts|
3
3
  if auth.cookies.signed[:guest_token].present?
4
4
  if user.is_a?(Spree::User)
5
- Spree::Order.where(guest_token: auth.cookies.signed[:guest_token], user_id: nil).each do |order|
5
+ Spree::Order.incomplete.where(guest_token: auth.cookies.signed[:guest_token], user_id: nil).each do |order|
6
6
  order.associate_user!(user)
7
7
  end
8
8
  end
@@ -1,48 +1,58 @@
1
1
  Spree::Core::Engine.add_routes do
2
- devise_for :spree_user,
3
- :class_name => 'Spree::User',
4
- :controllers => { :sessions => 'spree/user_sessions',
5
- :registrations => 'spree/user_registrations',
6
- :passwords => 'spree/user_passwords',
7
- :confirmations => 'spree/user_confirmations' },
8
- :skip => [:unlocks, :omniauth_callbacks],
9
- :path_names => { :sign_out => 'logout' },
10
- :path_prefix => :user
2
+ if Spree::Auth::Engine.frontend_available?
3
+ devise_for(:spree_user, {
4
+ class_name: 'Spree::User',
5
+ controllers: {
6
+ sessions: 'spree/user_sessions',
7
+ registrations: 'spree/user_registrations',
8
+ passwords: 'spree/user_passwords',
9
+ confirmations: 'spree/user_confirmations'
10
+ },
11
+ skip: [:unlocks, :omniauth_callbacks],
12
+ path_names: { sign_out: 'logout' },
13
+ path_prefix: :user
14
+ })
11
15
 
12
- resources :users, :only => [:edit, :update]
16
+ resources :users, only: [:edit, :update]
13
17
 
14
- devise_scope :spree_user do
15
- get '/login' => 'user_sessions#new', :as => :login
16
- post '/login' => 'user_sessions#create', :as => :create_new_session
17
- get '/logout' => 'user_sessions#destroy', :as => :logout
18
- get '/signup' => 'user_registrations#new', :as => :signup
19
- post '/signup' => 'user_registrations#create', :as => :registration
20
- get '/password/recover' => 'user_passwords#new', :as => :recover_password
21
- post '/password/recover' => 'user_passwords#create', :as => :reset_password
22
- get '/password/change' => 'user_passwords#edit', :as => :edit_password
23
- put '/password/change' => 'user_passwords#update', :as => :update_password
24
- get '/confirm' => 'user_confirmations#show', :as => :confirmation if Spree::Auth::Config[:confirmable]
25
- end
18
+ devise_scope :spree_user do
19
+ get '/login', to: 'user_sessions#new', as: :login
20
+ post '/login', to: 'user_sessions#create', as: :create_new_session
21
+ get '/logout', to: 'user_sessions#destroy', as: :logout
22
+ get '/signup', to: 'user_registrations#new', as: :signup
23
+ post '/signup', to: 'user_registrations#create', as: :registration
24
+ get '/password/recover', to: 'user_passwords#new', as: :recover_password
25
+ post '/password/recover', to: 'user_passwords#create', as: :reset_password
26
+ get '/password/change', to: 'user_passwords#edit', as: :edit_password
27
+ put '/password/change', to: 'user_passwords#update', as: :update_password
28
+ get '/confirm', to: 'user_confirmations#show', as: :confirmation if Spree::Auth::Config[:confirmable]
29
+ end
26
30
 
27
- get '/checkout/registration' => 'checkout#registration', :as => :checkout_registration
28
- put '/checkout/registration' => 'checkout#update_registration', :as => :update_checkout_registration
31
+ get '/checkout/registration', to: 'checkout#registration', as: :checkout_registration
32
+ put '/checkout/registration', to: 'checkout#update_registration', as: :update_checkout_registration
29
33
 
30
- resource :account, :controller => 'users'
34
+ resource :account, controller: 'users'
35
+ end
31
36
 
32
- namespace :admin do
33
- devise_for :spree_user,
34
- :class_name => 'Spree::User',
35
- :controllers => { :sessions => 'spree/admin/user_sessions',
36
- :passwords => 'spree/admin/user_passwords' },
37
- :skip => [:unlocks, :omniauth_callbacks, :registrations],
38
- :path_names => { :sign_out => 'logout' },
39
- :path_prefix => :user
40
- devise_scope :spree_user do
41
- get '/authorization_failure', :to => 'user_sessions#authorization_failure', :as => :unauthorized
42
- get '/login' => 'user_sessions#new', :as => :login
43
- post '/login' => 'user_sessions#create', :as => :create_new_session
44
- get '/logout' => 'user_sessions#destroy', :as => :logout
45
- end
37
+ if Spree::Auth::Engine.backend_available?
38
+ namespace :admin do
39
+ devise_for(:spree_user, {
40
+ class_name: 'Spree::User',
41
+ controllers: {
42
+ sessions: 'spree/admin/user_sessions',
43
+ passwords: 'spree/admin/user_passwords'
44
+ },
45
+ skip: [:unlocks, :omniauth_callbacks, :registrations],
46
+ path_names: { sign_out: 'logout' },
47
+ path_prefix: :user
48
+ })
46
49
 
50
+ devise_scope :spree_user do
51
+ get '/authorization_failure', to: 'user_sessions#authorization_failure', as: :unauthorized
52
+ get '/login', to: 'user_sessions#new', as: :login
53
+ post '/login', to: 'user_sessions#create', as: :create_new_session
54
+ get '/logout', to: 'user_sessions#destroy', as: :logout
55
+ end
56
+ end
47
57
  end
48
58
  end
@@ -1,7 +1,8 @@
1
1
  require 'spree/core/validators/email'
2
2
  Spree::CheckoutController.class_eval do
3
- before_filter :check_authorization
4
- before_filter :check_registration, :except => [:registration, :update_registration]
3
+ prepend_before_filter :check_registration,
4
+ except: [:registration, :update_registration]
5
+ prepend_before_filter :check_authorization
5
6
 
6
7
  def registration
7
8
  @user = Spree::User.new
@@ -32,12 +33,25 @@ Spree::CheckoutController.class_eval do
32
33
 
33
34
  # Introduces a registration step whenever the +registration_step+ preference is true.
34
35
  def check_registration
35
- return unless Spree::Auth::Config[:registration_step]
36
- return if spree_current_user or current_order.email
36
+ return unless registration_required?
37
37
  store_location
38
38
  redirect_to spree.checkout_registration_path
39
39
  end
40
40
 
41
+ def registration_required?
42
+ Spree::Auth::Config[:registration_step] &&
43
+ !already_registered?
44
+ end
45
+
46
+ def already_registered?
47
+ spree_current_user || guest_authenticated?
48
+ end
49
+
50
+ def guest_authenticated?
51
+ current_order.try!(:email).present? &&
52
+ Spree::Config[:allow_guest_checkout]
53
+ end
54
+
41
55
  # Overrides the equivalent method defined in Spree::Core. This variation of the method will ensure that users
42
56
  # are redirected to the tokenized order url unless authenticated as a registered user.
43
57
  def completion_route
@@ -19,7 +19,6 @@ class Spree::UserRegistrationsController < Devise::RegistrationsController
19
19
  set_flash_message(:notice, :signed_up)
20
20
  sign_in(:spree_user, resource)
21
21
  session[:spree_user_signup] = true
22
- associate_user
23
22
  respond_with resource, location: after_sign_up_path_for(resource)
24
23
  else
25
24
  clean_up_passwords(resource)
@@ -3,7 +3,7 @@
3
3
  Gem::Specification.new do |s|
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.name = "solidus_auth_devise"
6
- s.version = "1.3.0"
6
+ s.version = "1.4.0"
7
7
  s.summary = "Provides authentication and authorization services for use with Solidus by using Devise and CanCan."
8
8
  s.description = s.summary
9
9
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.require_path = "lib"
19
19
  s.requirements << "none"
20
20
 
21
- solidus_version = [">= 1.1.0.alpha", "< 2"]
21
+ solidus_version = [">= 1.0.6", "< 2"]
22
22
 
23
23
  s.add_dependency "solidus_core", solidus_version
24
24
  s.add_dependency "devise", '~> 3.5.1'
@@ -25,12 +25,36 @@ RSpec.describe Spree::CheckoutController, type: :controller do
25
25
  end
26
26
  end
27
27
 
28
- context 'when authenticated as guest' do
28
+ context 'when not authenticated as guest' do
29
29
  it 'redirects to registration step' do
30
30
  spree_get :edit, { state: 'address' }
31
31
  expect(response).to redirect_to spree.checkout_registration_path
32
32
  end
33
33
  end
34
+
35
+ context 'when authenticated as guest' do
36
+ before { order.email = 'guest@solidus.io' }
37
+
38
+ it 'proceeds to the first checkout step' do
39
+ spree_get :edit, { state: 'address' }
40
+ expect(response).to render_template :edit
41
+ end
42
+
43
+ context 'when guest checkout not allowed' do
44
+ before do
45
+ Spree::Config.set(allow_guest_checkout: false)
46
+ end
47
+
48
+ after do
49
+ Spree::Config.set(allow_guest_checkout: true)
50
+ end
51
+
52
+ it 'redirects to registration step' do
53
+ spree_get :edit, { state: 'address' }
54
+ expect(response).to redirect_to spree.checkout_registration_path
55
+ end
56
+ end
57
+ end
34
58
  end
35
59
 
36
60
  context 'when registration step disabled' do
@@ -40,15 +40,40 @@ RSpec.describe Spree::UserRegistrationsController, type: :controller do
40
40
  expect(session[:spree_user_signup]).to be true
41
41
  end
42
42
 
43
- it 'tries to associate user with current_order' do
44
- expect(controller).to receive(:associate_user)
45
- subject
46
- end
47
-
48
43
  it 'redirects to after_sign_up path' do
49
44
  subject
50
45
  expect(response).to redirect_to spree.root_path(thing: 7)
51
46
  end
47
+
48
+ context 'with a guest token present' do
49
+ before do
50
+ request.cookie_jar.signed[:guest_token] = 'ABC'
51
+ end
52
+
53
+ it 'assigns orders with the correct token and no user present' do
54
+ order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil)
55
+ subject
56
+ user = Spree::User.find_by_email('foobar@example.com')
57
+
58
+ order.reload
59
+ expect(order.user_id).to eq user.id
60
+ expect(order.created_by_id).to eq user.id
61
+ end
62
+
63
+ it 'does not assign orders with an existing user' do
64
+ order = create(:order, guest_token: 'ABC', user_id: 200)
65
+ subject
66
+
67
+ expect(order.reload.user_id).to eq 200
68
+ end
69
+
70
+ it 'does not assign orders with a different token' do
71
+ order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil)
72
+ subject
73
+
74
+ expect(order.reload.user_id).to be_nil
75
+ end
76
+ end
52
77
  end
53
78
 
54
79
  context 'when user not valid' do
@@ -17,16 +17,53 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
17
17
  end
18
18
 
19
19
  context "when using correct login information" do
20
- it 'properly assigns orders user from guest_token' do
21
- order1 = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil)
22
- order2 = create(:order, guest_token: 'ABC', user_id: 200)
23
- request.cookie_jar.signed[:guest_token] = 'ABC'
20
+ context 'with a guest token present' do
21
+ before do
22
+ request.cookie_jar.signed[:guest_token] = 'ABC'
23
+ end
24
+
25
+ it 'assigns orders with the correct token and no user present' do
26
+ order = create(:order, email: user.email, guest_token: 'ABC', user_id: nil, created_by_id: nil)
27
+ subject
28
+
29
+ order.reload
30
+ expect(order.user_id).to eq user.id
31
+ expect(order.created_by_id).to eq user.id
32
+ end
24
33
 
25
- subject
34
+ it 'assigns orders with the correct token and no user or email present' do
35
+ order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil)
36
+ subject
37
+
38
+ order.reload
39
+ expect(order.user_id).to eq user.id
40
+ expect(order.created_by_id).to eq user.id
41
+ end
42
+
43
+ it 'does not assign completed orders' do
44
+ order = create(:order, email: user.email, guest_token: 'ABC',
45
+ user_id: nil, created_by_id: nil,
46
+ completed_at: 1.minute.ago)
47
+ subject
26
48
 
27
- expect(order1.reload.user_id).to eq user.id
28
- expect(order1.reload.created_by_id).to eq user.id
29
- expect(order2.reload.user_id).to eq 200
49
+ order.reload
50
+ expect(order.user_id).to be_nil
51
+ expect(order.created_by_id).to be_nil
52
+ end
53
+
54
+ it 'does not assign orders with an existing user' do
55
+ order = create(:order, guest_token: 'ABC', user_id: 200)
56
+ subject
57
+
58
+ expect(order.reload.user_id).to eq 200
59
+ end
60
+
61
+ it 'does not assign orders with a different token' do
62
+ order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil)
63
+ subject
64
+
65
+ expect(order.reload.user_id).to be_nil
66
+ end
30
67
  end
31
68
 
32
69
  context "when html format is requested" do
@@ -1,6 +1,7 @@
1
1
  RSpec.feature 'Admin orders', type: :feature do
2
2
 
3
3
  background do
4
+ create(:store)
4
5
  sign_in_as! create(:admin_user)
5
6
  end
6
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solidus_auth_devise
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Solidus Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-12 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: solidus_core
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.0.alpha
19
+ version: 1.0.6
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '2'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 1.1.0.alpha
29
+ version: 1.0.6
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2'
@@ -106,7 +106,7 @@ dependencies:
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 1.1.0.alpha
109
+ version: 1.0.6
110
110
  - - "<"
111
111
  - !ruby/object:Gem::Version
112
112
  version: '2'
@@ -116,7 +116,7 @@ dependencies:
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: 1.1.0.alpha
119
+ version: 1.0.6
120
120
  - - "<"
121
121
  - !ruby/object:Gem::Version
122
122
  version: '2'
@@ -126,7 +126,7 @@ dependencies:
126
126
  requirements:
127
127
  - - ">="
128
128
  - !ruby/object:Gem::Version
129
- version: 1.1.0.alpha
129
+ version: 1.0.6
130
130
  - - "<"
131
131
  - !ruby/object:Gem::Version
132
132
  version: '2'
@@ -136,7 +136,7 @@ dependencies:
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
- version: 1.1.0.alpha
139
+ version: 1.0.6
140
140
  - - "<"
141
141
  - !ruby/object:Gem::Version
142
142
  version: '2'
@@ -389,7 +389,6 @@ files:
389
389
  - spec/features/account_spec.rb
390
390
  - spec/features/admin/orders_spec.rb
391
391
  - spec/features/admin/password_reset_spec.rb
392
- - spec/features/admin/payment_methods_spec.rb
393
392
  - spec/features/admin/products_spec.rb
394
393
  - spec/features/admin/sign_in_spec.rb
395
394
  - spec/features/admin/sign_out_spec.rb
@@ -435,7 +434,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
435
434
  requirements:
436
435
  - none
437
436
  rubyforge_project:
438
- rubygems_version: 2.5.1
437
+ rubygems_version: 2.4.5.1
439
438
  signing_key:
440
439
  specification_version: 4
441
440
  summary: Provides authentication and authorization services for use with Solidus by
@@ -451,7 +450,6 @@ test_files:
451
450
  - spec/features/account_spec.rb
452
451
  - spec/features/admin/orders_spec.rb
453
452
  - spec/features/admin/password_reset_spec.rb
454
- - spec/features/admin/payment_methods_spec.rb
455
453
  - spec/features/admin/products_spec.rb
456
454
  - spec/features/admin/sign_in_spec.rb
457
455
  - spec/features/admin/sign_out_spec.rb
@@ -1,16 +0,0 @@
1
- RSpec.feature 'Payment methods', type: :feature do
2
-
3
- background do
4
- sign_in_as! create(:admin_user)
5
- visit spree.admin_path
6
- click_link 'Settings'
7
- end
8
-
9
- # Regression test for #5
10
- scenario 'can dismiss the banner' do
11
- allow_any_instance_of(Spree::User).to receive(:dismissed_banner?) { false }
12
- allow(Spree::PaymentMethod).to receive(:production).and_return(payment_methods = [double])
13
- allow(payment_methods).to receive(:where).and_return([])
14
- click_link 'Payment Methods'
15
- end
16
- end