monban 0.0.11 → 0.0.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1cceb69d6f7307db5055ed206dae78583979907
4
- data.tar.gz: 3a922f46cd094d19defc0eaa17e518da87f63190
3
+ metadata.gz: aca082188020521eb26286f4329290137e03ee38
4
+ data.tar.gz: 9bfb518930ce8de955f38ebd44371645e1051324
5
5
  SHA512:
6
- metadata.gz: 2c14ee5a537e4d2dd9e003b46211e268bc49f22a62ef8218c6c36f917466d8a854de83f7b8196e10a9773a1c92610bdc0109a7e2fcc2cf6878e0d8ba205a7439
7
- data.tar.gz: a60bee9c220c98b5a78289e0b0b076ecdfeb5f56b6c7313ac587db30c918fee86e82a9f482ccebefa2ff18ec2c0c231a2266c10ff323843eb3d51e1de1d28f74
6
+ metadata.gz: 0e43239016ff07761fc2b870276033cbad7b16f4bb8dac62555f1bb5328be648d2ec74ec69c622d6ecec46bc8f9bbcc724f758b4f518ba10cafda1212bf6b3db
7
+ data.tar.gz: bccdc6fe8918d5b4ee34a9127fa591bb28617ff2b1cb786fe4ca8926746b72aa2800f73dd979d18677e4f96328a6145f41becccde90253266babf00760869db1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- monban (0.0.11)
4
+ monban (0.0.12)
5
5
  bcrypt
6
6
  rails
7
7
  warden
@@ -9,38 +9,35 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actionmailer (3.2.11)
13
- actionpack (= 3.2.11)
14
- mail (~> 2.4.4)
15
- actionpack (3.2.11)
16
- activemodel (= 3.2.11)
17
- activesupport (= 3.2.11)
18
- builder (~> 3.0.0)
12
+ actionmailer (0.6.1)
13
+ actionpack (>= 0.9.5)
14
+ actionpack (4.1.0)
15
+ actionview (= 4.1.0)
16
+ activesupport (= 4.1.0)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ actionview (4.1.0)
20
+ activesupport (= 4.1.0)
21
+ builder (~> 3.1)
19
22
  erubis (~> 2.7.0)
20
- journey (~> 1.0.4)
21
- rack (~> 1.4.0)
22
- rack-cache (~> 1.2)
23
- rack-test (~> 0.6.1)
24
- sprockets (~> 2.2.1)
25
23
  active_hash (0.9.13)
26
24
  activesupport (>= 2.2.2)
27
- activemodel (3.2.11)
28
- activesupport (= 3.2.11)
29
- builder (~> 3.0.0)
30
- activerecord (3.2.11)
31
- activemodel (= 3.2.11)
32
- activesupport (= 3.2.11)
33
- arel (~> 3.0.2)
34
- tzinfo (~> 0.3.29)
35
- activeresource (3.2.11)
36
- activemodel (= 3.2.11)
37
- activesupport (= 3.2.11)
38
- activesupport (3.2.11)
39
- i18n (~> 0.6)
40
- multi_json (~> 1.0)
41
- arel (3.0.3)
25
+ activemodel (4.1.0)
26
+ activesupport (= 4.1.0)
27
+ builder (~> 3.1)
28
+ activerecord (4.1.0)
29
+ activemodel (= 4.1.0)
30
+ activesupport (= 4.1.0)
31
+ arel (~> 5.0.0)
32
+ activesupport (4.1.0)
33
+ i18n (~> 0.6, >= 0.6.9)
34
+ json (~> 1.7, >= 1.7.7)
35
+ minitest (~> 5.1)
36
+ thread_safe (~> 0.1)
37
+ tzinfo (~> 1.1)
38
+ arel (5.0.1.20140414130214)
42
39
  bcrypt (3.1.7)
43
- builder (3.0.4)
40
+ builder (3.2.2)
44
41
  capybara (2.0.2)
45
42
  mime-types (>= 1.16)
46
43
  nokogiri (>= 1.3.3)
@@ -50,79 +47,56 @@ GEM
50
47
  xpath (~> 1.0.0)
51
48
  childprocess (0.3.7)
52
49
  ffi (~> 1.0, >= 1.0.6)
53
- diff-lcs (1.1.3)
50
+ diff-lcs (1.2.5)
54
51
  erubis (2.7.0)
55
52
  ffi (1.3.1)
56
- hike (1.2.1)
57
- i18n (0.6.1)
58
- journey (1.0.4)
59
- json (1.7.6)
60
- mail (2.4.4)
61
- i18n (>= 0.4.0)
62
- mime-types (~> 1.16)
63
- treetop (~> 1.4.8)
64
- mime-types (1.20.1)
65
- multi_json (1.5.0)
53
+ i18n (0.6.9)
54
+ json (1.8.1)
55
+ mime-types (2.2)
56
+ minitest (5.3.3)
57
+ multi_json (1.9.3)
66
58
  nokogiri (1.5.6)
67
- polyglot (0.3.4)
68
- rack (1.4.4)
69
- rack-cache (1.2)
70
- rack (>= 0.4)
71
- rack-ssl (1.3.3)
72
- rack
59
+ rack (1.5.2)
73
60
  rack-test (0.6.2)
74
61
  rack (>= 1.0)
75
- rails (3.2.11)
76
- actionmailer (= 3.2.11)
77
- actionpack (= 3.2.11)
78
- activerecord (= 3.2.11)
79
- activeresource (= 3.2.11)
80
- activesupport (= 3.2.11)
81
- bundler (~> 1.0)
82
- railties (= 3.2.11)
83
- railties (3.2.11)
84
- actionpack (= 3.2.11)
85
- activesupport (= 3.2.11)
86
- rack-ssl (~> 1.3.2)
62
+ rails (0.9.5)
63
+ actionmailer (>= 0.6.1)
64
+ actionpack (>= 1.4.0)
65
+ activerecord (>= 1.6.0)
66
+ rake (>= 0.4.15)
67
+ railties (4.1.0)
68
+ actionpack (= 4.1.0)
69
+ activesupport (= 4.1.0)
87
70
  rake (>= 0.8.7)
88
- rdoc (~> 3.4)
89
- thor (>= 0.14.6, < 2.0)
90
- rake (10.1.1)
91
- rdoc (3.12.1)
92
- json (~> 1.4)
93
- rspec (2.12.0)
94
- rspec-core (~> 2.12.0)
95
- rspec-expectations (~> 2.12.0)
96
- rspec-mocks (~> 2.12.0)
97
- rspec-core (2.12.2)
98
- rspec-expectations (2.12.1)
99
- diff-lcs (~> 1.1.3)
100
- rspec-mocks (2.12.2)
101
- rspec-rails (2.12.0)
71
+ thor (>= 0.18.1, < 2.0)
72
+ rake (10.3.1)
73
+ rspec (2.14.1)
74
+ rspec-core (~> 2.14.0)
75
+ rspec-expectations (~> 2.14.0)
76
+ rspec-mocks (~> 2.14.0)
77
+ rspec-core (2.14.8)
78
+ rspec-expectations (2.14.5)
79
+ diff-lcs (>= 1.1.3, < 2.0)
80
+ rspec-mocks (2.14.6)
81
+ rspec-rails (2.14.2)
102
82
  actionpack (>= 3.0)
83
+ activemodel (>= 3.0)
103
84
  activesupport (>= 3.0)
104
85
  railties (>= 3.0)
105
- rspec-core (~> 2.12.0)
106
- rspec-expectations (~> 2.12.0)
107
- rspec-mocks (~> 2.12.0)
86
+ rspec-core (~> 2.14.0)
87
+ rspec-expectations (~> 2.14.0)
88
+ rspec-mocks (~> 2.14.0)
108
89
  rubyzip (0.9.9)
109
90
  selenium-webdriver (2.29.0)
110
91
  childprocess (>= 0.2.5)
111
92
  multi_json (~> 1.0)
112
93
  rubyzip
113
94
  websocket (~> 1.0.4)
114
- sprockets (2.2.2)
115
- hike (~> 1.2)
116
- multi_json (~> 1.0)
117
- rack (~> 1.0)
118
- tilt (~> 1.1, != 1.3.0)
119
95
  sqlite3 (1.3.7)
120
- thor (0.17.0)
121
- tilt (1.3.3)
122
- treetop (1.4.15)
123
- polyglot
124
- polyglot (>= 0.3.1)
125
- tzinfo (0.3.39)
96
+ thor (0.19.1)
97
+ thread_safe (0.3.3)
98
+ tzinfo (1.1.0)
99
+ thread_safe (~> 0.1)
126
100
  warden (1.2.3)
127
101
  rack (>= 1.0)
128
102
  websocket (1.0.7)
@@ -7,7 +7,7 @@ module Monban
7
7
  attr_accessor :sign_in_service, :sign_up_service, :sign_out_service
8
8
  attr_accessor :authentication_service, :password_reset_service
9
9
  attr_accessor :failure_app
10
- attr_accessor :creation_method
10
+ attr_accessor :creation_method, :find_method
11
11
 
12
12
  def initialize
13
13
  setup_class_defaults
@@ -25,6 +25,10 @@ module Monban
25
25
  ->(token) { BCrypt::Password.create(token) }
26
26
  end
27
27
 
28
+ def default_find_method
29
+ ->(params) { Monban.user_class.find_by(params) }
30
+ end
31
+
28
32
  def default_password_comparison
29
33
  ->(digest, unencrypted_token) do
30
34
  BCrypt::Password.new(digest) == unencrypted_token
@@ -48,6 +52,7 @@ module Monban
48
52
  @user_token_store_field = :password_digest
49
53
  @user_lookup_field = :email
50
54
  @creation_method = default_creation_method
55
+ @find_method = default_find_method
51
56
  end
52
57
 
53
58
  def setup_services
@@ -0,0 +1,10 @@
1
+ module Monban
2
+ module Constraints
3
+ class SignedIn
4
+ def matches?(request)
5
+ warden = request.env["warden"]
6
+ warden && warden.authenticated?
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,9 +1,10 @@
1
1
  module Monban
2
2
  class SignUp
3
3
  def initialize user_params
4
- unencrypted_token = user_params[token_field]
5
- token_digest = Monban.encrypt_token(unencrypted_token)
6
- @user_params = user_params.except(token_field).merge(token_store_field.to_sym => token_digest)
4
+ encrypted_token = token_digest(user_params)
5
+ @user_params = user_params.
6
+ except(token_field).
7
+ merge(token_store_field.to_sym => encrypted_token)
7
8
  end
8
9
 
9
10
  def perform
@@ -12,6 +13,13 @@ module Monban
12
13
 
13
14
  private
14
15
 
16
+ def token_digest(user_params)
17
+ unencrypted_token = user_params[token_field]
18
+ unless unencrypted_token.empty?
19
+ Monban.encrypt_token(unencrypted_token)
20
+ end
21
+ end
22
+
15
23
  def token_store_field
16
24
  Monban.config.user_token_store_field
17
25
  end
@@ -1,3 +1,3 @@
1
1
  module Monban
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
data/lib/monban.rb CHANGED
@@ -37,7 +37,8 @@ module Monban
37
37
 
38
38
  def self.lookup(params, field_map)
39
39
  fields = FieldMap.new(params, field_map).to_fields
40
- user_class.where(fields).first
40
+ default_fields = { Monban.config.user_lookup_field => nil }
41
+ self.config.find_method.call(default_fields.merge(fields))
41
42
  end
42
43
 
43
44
  def self.test_mode!
@@ -50,7 +51,7 @@ module Monban
50
51
  end
51
52
 
52
53
  def self.configure(&block)
53
- self.config = Monban::Configuration.new
54
+ self.config ||= Monban::Configuration.new
54
55
  yield self.config
55
56
  end
56
57
 
@@ -5,6 +5,6 @@ feature 'Visitor signs up' do
5
5
  visit sign_up_path
6
6
  click_on 'go'
7
7
 
8
- expect(page).not_to have_content("Sign out")
8
+ page.should_not have_content("Sign out")
9
9
  end
10
10
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ feature 'Visitor signs in with invalid form' do
4
+ scenario 'is not signed in' do
5
+ Monban::SignUp.new(email: 'email@example.com', password: 'password').perform
6
+ visit invalid_sign_in_path
7
+ fill_in "session_password", with: 'password'
8
+ click_button 'go'
9
+ expect(page).to have_content("Sign in")
10
+ end
11
+ end
@@ -22,7 +22,28 @@ describe Monban::SignUp, '#perform' do
22
22
  end
23
23
 
24
24
  user_params = { email: 'email@example.com', password: 'password' }
25
- Monban.config.creation_method = user_create_double
25
+ swap_creation_method user_create_double do
26
+ Monban::SignUp.new(user_params).perform
27
+ end
28
+ end
29
+
30
+ def swap_creation_method(new_creation_method, &block)
31
+ old_creation_method = Monban.config.creation_method
32
+ Monban.config.creation_method = new_creation_method
33
+ yield
34
+ ensure
35
+ Monban.config.creation_method = old_creation_method
36
+ end
37
+
38
+ it 'does not create a user with an empty password' do
39
+ create = double
40
+ stub_const('User', create)
41
+ user_params = { email: 'email@example.com', password: '' }
42
+
43
+ create.should_receive(:create) do |args|
44
+ args[:password_digest].should be_nil
45
+ end
46
+
26
47
  Monban::SignUp.new(user_params).perform
27
48
  end
28
49
  end
@@ -0,0 +1,2 @@
1
+ class InvalidSessionsController < SessionsController
2
+ end
@@ -3,4 +3,8 @@ class User < ActiveHash::Base
3
3
  include ActiveModel::Validations
4
4
  attr_accessor :email, :password_digest, :password
5
5
  validates :email, presence: true
6
+
7
+ def self.find_by(params)
8
+ where(params).first
9
+ end
6
10
  end
@@ -0,0 +1,4 @@
1
+ <%= form_for :session do |f| %>
2
+ <%= f.text_field :password %>
3
+ <%= f.submit 'go' %>
4
+ <% end %>
@@ -9,6 +9,8 @@
9
9
  <body>
10
10
  <% if signed_in? %>
11
11
  <%= link_to "Sign out", sign_out_path, method: :delete %>
12
+ <% else %>
13
+ <%= link_to "Sign in", sign_in_path %>
12
14
  <% end %>
13
15
  <%= yield %>
14
16
 
@@ -7,4 +7,6 @@ RailsApp::Application.routes.draw do
7
7
  post "sign_in" => "sessions#create"
8
8
  delete "sign_out" => "sessions#destroy"
9
9
  get "sign_up" => "users#new"
10
+ get "invalid_sign_in" => "invalid_sessions#new"
11
+ post "invalid_sign_in" => "invalid_sessions#create"
10
12
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - halogenandtoast
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-28 00:00:00.000000000 Z
12
+ date: 2014-05-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -161,6 +161,7 @@ files:
161
161
  - lib/monban.rb
162
162
  - lib/monban/back_door.rb
163
163
  - lib/monban/configuration.rb
164
+ - lib/monban/constraints/signed_in.rb
164
165
  - lib/monban/controller_helpers.rb
165
166
  - lib/monban/field_map.rb
166
167
  - lib/monban/railtie.rb
@@ -178,6 +179,7 @@ files:
178
179
  - monban.gemspec
179
180
  - spec/features/visitor/visitor_fails_to_sign_up_spec.rb
180
181
  - spec/features/visitor/visitor_is_unauthorized_spec.rb
182
+ - spec/features/visitor/visitor_signs_in_via_invalid_form_spec.rb
181
183
  - spec/features/visitor/visitor_signs_up_spec.rb
182
184
  - spec/features/visitor/visitor_uses_remember_token_spec.rb
183
185
  - spec/monban/controller_helpers_spec.rb
@@ -196,11 +198,13 @@ files:
196
198
  - spec/rails_app/app/assets/stylesheets/application.css
197
199
  - spec/rails_app/app/controllers/application_controller.rb
198
200
  - spec/rails_app/app/controllers/failures_controller.rb
201
+ - spec/rails_app/app/controllers/invalid_sessions_controller.rb
199
202
  - spec/rails_app/app/controllers/posts_controller.rb
200
203
  - spec/rails_app/app/controllers/sessions_controller.rb
201
204
  - spec/rails_app/app/controllers/users_controller.rb
202
205
  - spec/rails_app/app/helpers/application_helper.rb
203
206
  - spec/rails_app/app/models/user.rb
207
+ - spec/rails_app/app/views/invalid_sessions/new.html.erb
204
208
  - spec/rails_app/app/views/layouts/application.html.erb
205
209
  - spec/rails_app/app/views/posts/index.html.erb
206
210
  - spec/rails_app/app/views/sessions/new.html.erb
@@ -251,6 +255,7 @@ summary: Making rails authentication as simple as possible
251
255
  test_files:
252
256
  - spec/features/visitor/visitor_fails_to_sign_up_spec.rb
253
257
  - spec/features/visitor/visitor_is_unauthorized_spec.rb
258
+ - spec/features/visitor/visitor_signs_in_via_invalid_form_spec.rb
254
259
  - spec/features/visitor/visitor_signs_up_spec.rb
255
260
  - spec/features/visitor/visitor_uses_remember_token_spec.rb
256
261
  - spec/monban/controller_helpers_spec.rb
@@ -269,11 +274,13 @@ test_files:
269
274
  - spec/rails_app/app/assets/stylesheets/application.css
270
275
  - spec/rails_app/app/controllers/application_controller.rb
271
276
  - spec/rails_app/app/controllers/failures_controller.rb
277
+ - spec/rails_app/app/controllers/invalid_sessions_controller.rb
272
278
  - spec/rails_app/app/controllers/posts_controller.rb
273
279
  - spec/rails_app/app/controllers/sessions_controller.rb
274
280
  - spec/rails_app/app/controllers/users_controller.rb
275
281
  - spec/rails_app/app/helpers/application_helper.rb
276
282
  - spec/rails_app/app/models/user.rb
283
+ - spec/rails_app/app/views/invalid_sessions/new.html.erb
277
284
  - spec/rails_app/app/views/layouts/application.html.erb
278
285
  - spec/rails_app/app/views/posts/index.html.erb
279
286
  - spec/rails_app/app/views/sessions/new.html.erb