clearance 2.7.1 → 2.8.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
2
  SHA256:
3
- metadata.gz: f0877a789add508c0031bbccf949369fa360271e2f42d9bfb32f16259b9135a3
4
- data.tar.gz: 9ca1d73291bd91c1811edbfc69f3acef51d35edad753743badfb38341687d20b
3
+ metadata.gz: e5f7f15515653096a81f567271c72a5bc138dac396acb3d7727fb7eb95b89540
4
+ data.tar.gz: 61b53d47ef673fe4f171aa32c6239c80fca531c4edaa239446bb0f3d8478df18
5
5
  SHA512:
6
- metadata.gz: 67e231abb3b4ee087b0da4c258fab6ba07190945a365b7c3ac37577a9e84a2982fedfccb6578d6d661e8301fb293d061ddcad67af17da1faf8254e31bc336f3e
7
- data.tar.gz: 4bede194d2b6adc4cab0caaf4297435440df9967075a167aca064a3dd9dfa4ebc648f5fdc0588a2c1364f3c43c29aeefcff882e031d02c65e9cf5f0e517eb934
6
+ metadata.gz: a695e60bfb14845d6bb5a1481766f2104f68fc92149fc0de3191af403bc7719803013cb8cb4a93fa74c1d334d1190e7206ba017502d40f109d0e96fb381fb3e0
7
+ data.tar.gz: cc12e0563b4106d22e4d4c23a8d2f50621cc1f2a61f905ea82ea697369e1e916bc5e5d69b65900d8b146244fe9a8dbf50e54e752c9b0cbd9243c53c285011226
@@ -0,0 +1,15 @@
1
+ version: 2
2
+
3
+ updates:
4
+ - package-ecosystem: bundler
5
+ directory: "/"
6
+ schedule:
7
+ interval: daily
8
+ open-pull-requests-limit: 5
9
+
10
+ - package-ecosystem: github-actions
11
+ directory: "/"
12
+ schedule:
13
+ interval: weekly
14
+ time: "02:00"
15
+ timezone: "Etc/UTC"
@@ -0,0 +1,19 @@
1
+ name: update-security
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ paths:
8
+ - SECURITY.md
9
+ workflow_dispatch:
10
+
11
+ jobs:
12
+ update-security:
13
+ permissions:
14
+ contents: write
15
+ pull-requests: write
16
+ pages: write
17
+ uses: thoughtbot/templates/.github/workflows/dynamic-security.yaml@main
18
+ secrets:
19
+ token: ${{ secrets.GITHUB_TOKEN }}
data/CHANGELOG.md CHANGED
@@ -5,9 +5,27 @@ complete changelog, see the git history for each version via the version links.
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
- [Unreleased]: https://github.com/thoughtbot/clearance/compare/v2.7.1...main
8
+ [Unreleased]: https://github.com/thoughtbot/clearance/compare/v2.8.0...main
9
9
 
10
- ## [2.7.1] May 8, 2024
10
+ ## [2.8.0] - August 9, 2024
11
+ - Feature: Added allow_password_resets config option (#1019) Jos O'shea
12
+ - Added dependabot (#1028) Karine Vieira
13
+ - Fixed some deprecation warnings (#1018)
14
+ - Added a dynamic workflow to update SECURITY.md
15
+
16
+ [2.8.0]: https://github.com/thoughtbot/clearance/compare/v2.7.2...v2.8.0
17
+
18
+ ## [2.7.2] - June 28, 2024
19
+ - Fix method redefinition and circular require issues (#1027)
20
+ - Add specs for email validator strict mode (#1001)
21
+ - Create SECURITY.md (#972)
22
+ - Fix validating email in strict mode (#976)
23
+ - Update the example config in README.md (#977)
24
+ - Remove Hound README badge (#1020)
25
+
26
+ [2.7.2]: https://github.com/thoughtbot/clearance/compare/v2.7.1...v2.7.2
27
+
28
+ ## [2.7.1] - May 8, 2024
11
29
  - Update sqlite3 and erb_lint gems (#1017) Jos O'shea
12
30
 
13
31
  [2.7.1]: https://github.com/thoughtbot/clearance/compare/v2.7.0...v2.7.1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clearance (2.7.0)
4
+ clearance (2.8.0)
5
5
  actionmailer (>= 5.0)
6
6
  activemodel (>= 5.0)
7
7
  activerecord (>= 5.0)
@@ -107,7 +107,7 @@ GEM
107
107
  factory_bot_rails (6.2.0)
108
108
  factory_bot (~> 6.2.0)
109
109
  railties (>= 5.0.0)
110
- ffi (1.16.3)
110
+ ffi (1.17.0)
111
111
  ffi-compiler (1.3.2)
112
112
  ffi (>= 1.15.5)
113
113
  rake
@@ -130,7 +130,7 @@ GEM
130
130
  mini_mime (1.1.2)
131
131
  mini_portile2 (2.8.6)
132
132
  minitest (5.22.3)
133
- net-imap (0.4.10)
133
+ net-imap (0.4.14)
134
134
  date
135
135
  net-protocol
136
136
  net-pop (0.1.2)
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  [![Build Status](https://github.com/thoughtbot/clearance/actions/workflows/tests.yml/badge.svg)]( https://github.com/thoughtbot/clearance/actions/workflows/tests.yml?query=branch%3Amain)
4
4
  [![Code Climate](https://codeclimate.com/github/thoughtbot/clearance.svg)](https://codeclimate.com/github/thoughtbot/clearance)
5
5
  [![Documentation Quality](https://inch-ci.org/github/thoughtbot/clearance.svg?branch=main)](https://inch-ci.org/github/thoughtbot/clearance)
6
- [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
7
6
 
8
7
  Rails authentication with email & password.
9
8
 
@@ -50,6 +49,7 @@ Override any of these defaults in `config/initializers/clearance.rb`:
50
49
  ```ruby
51
50
  Clearance.configure do |config|
52
51
  config.allow_sign_up = true
52
+ config.allow_password_reset = true
53
53
  config.cookie_domain = ".example.com"
54
54
  config.cookie_expiration = lambda { |cookies| 1.year.from_now.utc }
55
55
  config.cookie_name = "remember_token"
@@ -63,7 +63,7 @@ Clearance.configure do |config|
63
63
  config.url_after_denied_access_when_signed_out = nil
64
64
  config.rotate_csrf_on_sign_in = true
65
65
  config.same_site = nil
66
- config.secure_cookie = false
66
+ config.secure_cookie = Rails.configuration.force_ssl
67
67
  config.signed_cookie = false
68
68
  config.sign_in_guards = []
69
69
  config.user_model = "User"
@@ -497,4 +497,19 @@ redistributed under the terms specified in the [`LICENSE`] file.
497
497
  [`LICENSE`]: /LICENSE
498
498
 
499
499
  <!-- START /templates/footer.md -->
500
+ ## About thoughtbot
501
+
502
+ ![thoughtbot](https://thoughtbot.com/thoughtbot-logo-for-readmes.svg)
503
+
504
+ This repo is maintained and funded by thoughtbot, inc.
505
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
506
+
507
+ We love open source software!
508
+ See [our other projects][community].
509
+ We are [available for hire][hire].
510
+
511
+ [community]: https://thoughtbot.com/community?utm_source=github
512
+ [hire]: https://thoughtbot.com/hire-us?utm_source=github
513
+
514
+
500
515
  <!-- END /templates/footer.md -->
data/SECURITY.md ADDED
@@ -0,0 +1,20 @@
1
+ <!-- START /templates/security.md -->
2
+ # Security Policy
3
+
4
+ ## Supported Versions
5
+
6
+ Only the the latest version of this project is supported at a given time. If
7
+ you find a security issue with an older version, please try updating to the
8
+ latest version first.
9
+
10
+ If for some reason you can't update to the latest version, please let us know
11
+ your reasons so that we can have a better understanding of your situation.
12
+
13
+ ## Reporting a Vulnerability
14
+
15
+ For security inquiries or vulnerability reports, visit
16
+ <https://thoughtbot.com/security>.
17
+
18
+ If you have any suggestions to improve this policy, visit <https://thoughtbot.com/security>.
19
+
20
+ <!-- END /templates/security.md -->
@@ -17,6 +17,8 @@
17
17
  <% if Clearance.configuration.allow_sign_up? %>
18
18
  <%= link_to t(".sign_up"), sign_up_path %>
19
19
  <% end %>
20
- <%= link_to t(".forgot_password"), new_password_path %>
20
+ <% if Clearance.configuration.allow_password_reset? %>
21
+ <%= link_to t(".forgot_password"), new_password_path %>
22
+ <% end %>
21
23
  </div>
22
24
  <% end %>
data/clearance.gemspec CHANGED
@@ -28,7 +28,8 @@ Gem::Specification.new do |s|
28
28
  'Jason Morrison',
29
29
  'Galen Frechette',
30
30
  'Josh Steiner',
31
- 'Dorian Marié'
31
+ 'Dorian Marié',
32
+ 'Sara Jackson'
32
33
  ]
33
34
  s.description = <<-DESCRIPTION
34
35
  Clearance is built to support authentication and authorization via an
data/config/routes.rb CHANGED
@@ -11,9 +11,11 @@ if Clearance.configuration.routes_enabled?
11
11
  resources :users,
12
12
  controller: 'clearance/users',
13
13
  only: Clearance.configuration.user_actions do
14
- resource :password,
15
- controller: 'clearance/passwords',
16
- only: [:edit, :update]
14
+ if Clearance.configuration.allow_password_reset?
15
+ resource :password,
16
+ controller: 'clearance/passwords',
17
+ only: [:edit, :update]
18
+ end
17
19
  end
18
20
 
19
21
  get '/sign_in' => 'clearance/sessions#new', as: 'sign_in'
@@ -7,6 +7,13 @@ module Clearance
7
7
  # @return [Boolean]
8
8
  attr_writer :allow_sign_up
9
9
 
10
+ # Controls whether the password reset routes are enabled
11
+ # Defaults to `true`. Set to False to disable password reset routes
12
+ # The setting is ignored if routes are disabled.
13
+ # @param [Boolean] value
14
+ # @return [Boolean]
15
+ attr_writer :allow_password_reset
16
+
10
17
  # The domain to use for the clearance remember token cookie.
11
18
  # Defaults to `nil`, which causes the cookie domain to default to the
12
19
  # domain of the request. For more, see
@@ -135,7 +142,7 @@ module Clearance
135
142
  # The parameter for user routes. By default this is derived from the user
136
143
  # model.
137
144
  # @return [Symbol]
138
- attr_accessor :user_parameter
145
+ attr_writer :user_parameter
139
146
 
140
147
  # Controls wether users are automatically signed in after successfully
141
148
  # resetting their password.
@@ -145,6 +152,7 @@ module Clearance
145
152
 
146
153
  def initialize
147
154
  @allow_sign_up = true
155
+ @allow_password_reset = true
148
156
  @allowed_backdoor_environments = ["test", "ci", "development"]
149
157
  @cookie_domain = nil
150
158
  @cookie_expiration = ->(cookies) { 1.year.from_now.utc }
@@ -195,6 +203,12 @@ module Clearance
195
203
  @allow_sign_up
196
204
  end
197
205
 
206
+ # Are the password reset routes enabled?
207
+ # @return [Boolean]
208
+ def allow_password_reset?
209
+ @allow_password_reset
210
+ end
211
+
198
212
  # Specifies which controller actions are allowed for user resources.
199
213
  # This will be `[:create]` is `allow_sign_up` is true (the default), and
200
214
  # empty otherwise.
@@ -1,4 +1,3 @@
1
- require "clearance"
2
1
  require "rails/engine"
3
2
 
4
3
  module Clearance
@@ -150,7 +150,7 @@ module Clearance
150
150
 
151
151
  included do
152
152
  validates :email,
153
- email: { strict_mode: true },
153
+ email: { mode: :strict },
154
154
  presence: true,
155
155
  uniqueness: { allow_blank: true, case_sensitive: true },
156
156
  unless: :email_optional?
@@ -1,3 +1,3 @@
1
1
  module Clearance
2
- VERSION = "2.7.1".freeze
2
+ VERSION = "2.8.0".freeze
3
3
  end
data/lib/clearance.rb CHANGED
@@ -5,9 +5,9 @@ require 'clearance/rack_session'
5
5
  require 'clearance/back_door'
6
6
  require 'clearance/controller'
7
7
  require 'clearance/user'
8
- require 'clearance/engine'
9
8
  require 'clearance/password_strategies'
10
9
  require 'clearance/constraints'
10
+ require 'clearance/engine'
11
11
 
12
12
  module Clearance
13
13
  end
@@ -179,6 +179,21 @@ describe Clearance::Configuration do
179
179
  end
180
180
  end
181
181
 
182
+ describe "#allow_password_reset?" do
183
+ context "when allow_password_reset is configured to false" do
184
+ it "returns false" do
185
+ Clearance.configure { |config| config.allow_password_reset = false }
186
+ expect(Clearance.configuration.allow_password_reset?).to eq false
187
+ end
188
+ end
189
+
190
+ context "when allow_sign_up has not been configured" do
191
+ it "returns true" do
192
+ expect(Clearance.configuration.allow_password_reset?).to eq true
193
+ end
194
+ end
195
+ end
196
+
182
197
  describe "#user_actions" do
183
198
  context "when allow_sign_up is configured to false" do
184
199
  it "returns empty array" do
@@ -9,6 +9,9 @@ module Dummy
9
9
  config.action_controller.perform_caching = false
10
10
  config.action_mailer.default_url_options = { host: "dummy.example.com" }
11
11
  config.action_mailer.delivery_method = :test
12
+ if Rails.version.match?(/(6.1|7.0)/)
13
+ config.active_record.legacy_connection_handling = false
14
+ end
12
15
  config.active_support.deprecation = :stderr
13
16
  config.eager_load = false
14
17
 
@@ -2,6 +2,10 @@ require "spec_helper"
2
2
  require "generators/clearance/install/install_generator"
3
3
 
4
4
  describe Clearance::Generators::InstallGenerator, :generator do
5
+ def get_migration(path)
6
+ Pathname.new(migration_file(path))
7
+ end
8
+
5
9
  describe "initializer" do
6
10
  it "is copied to the application" do
7
11
  provide_existing_application_controller
@@ -66,7 +70,7 @@ describe Clearance::Generators::InstallGenerator, :generator do
66
70
  table_does_not_exist(:users)
67
71
 
68
72
  run_generator
69
- migration = migration_file("db/migrate/create_users.rb")
73
+ migration = get_migration("db/migrate/create_users.rb")
70
74
 
71
75
  expect(migration).to exist
72
76
  expect(migration).to have_correct_syntax
@@ -88,7 +92,7 @@ describe Clearance::Generators::InstallGenerator, :generator do
88
92
  table_does_not_exist(:users)
89
93
 
90
94
  run_generator
91
- migration = migration_file("db/migrate/create_users.rb")
95
+ migration = get_migration("db/migrate/create_users.rb")
92
96
 
93
97
  expect(migration).to exist
94
98
  expect(migration).to have_correct_syntax
@@ -102,8 +106,8 @@ describe Clearance::Generators::InstallGenerator, :generator do
102
106
  provide_existing_application_controller
103
107
 
104
108
  run_generator
105
- create_migration = migration_file("db/migrate/create_users.rb")
106
- add_migration = migration_file("db/migrate/add_clearance_to_users.rb")
109
+ create_migration = get_migration("db/migrate/create_users.rb")
110
+ add_migration = get_migration("db/migrate/add_clearance_to_users.rb")
107
111
 
108
112
  expect(create_migration).not_to exist
109
113
  expect(add_migration).not_to exist
@@ -126,7 +130,7 @@ describe Clearance::Generators::InstallGenerator, :generator do
126
130
  and_return(existing_indexes)
127
131
 
128
132
  run_generator
129
- migration = migration_file("db/migrate/add_clearance_to_users.rb")
133
+ migration = get_migration("db/migrate/add_clearance_to_users.rb")
130
134
 
131
135
  expect(migration).to exist
132
136
  expect(migration).to have_correct_syntax
@@ -5,15 +5,16 @@ describe User do
5
5
  it { is_expected.to have_db_index(:remember_token) }
6
6
  it { is_expected.to validate_presence_of(:email) }
7
7
  it { is_expected.to validate_presence_of(:password) }
8
- it { is_expected.to allow_value("foo;@example.com").for(:email) }
9
- it { is_expected.to allow_value("foo@.example.com").for(:email) }
10
- it { is_expected.to allow_value("foo@example..com").for(:email) }
11
8
  it { is_expected.to allow_value("foo@example.co.uk").for(:email) }
12
9
  it { is_expected.to allow_value("foo@example.com").for(:email) }
13
10
  it { is_expected.to allow_value("foo+bar@example.com").for(:email) }
14
11
  it { is_expected.not_to allow_value("example.com").for(:email) }
15
12
  it { is_expected.not_to allow_value("foo").for(:email) }
16
13
  it { is_expected.not_to allow_value("foo@").for(:email) }
14
+ it { is_expected.not_to allow_value("foo@bar").for(:email) }
15
+ it { is_expected.not_to allow_value("foo;@example.com").for(:email) }
16
+ it { is_expected.not_to allow_value("foo@.example.com").for(:email) }
17
+ it { is_expected.not_to allow_value("foo@example..com").for(:email) }
17
18
 
18
19
  describe "#email" do
19
20
  it "stores email in down case and removes whitespace" do
@@ -62,4 +62,36 @@ describe 'routes for Clearance' do
62
62
  expect(post: 'users').to be_routable
63
63
  end
64
64
  end
65
+
66
+ context 'password reset disabled' do
67
+ around do |example|
68
+ Clearance.configure { |config| config.allow_password_reset = false }
69
+ Rails.application.reload_routes!
70
+ example.run
71
+ Clearance.configuration = Clearance::Configuration.new
72
+ Rails.application.reload_routes!
73
+ end
74
+
75
+ it 'does not route password edit' do
76
+ user = create(:user)
77
+ expect(get: "users/#{user.id}/password/edit").not_to be_routable
78
+ end
79
+
80
+ it 'does not route to clearance/passwords#update' do
81
+ user = create(:user)
82
+ expect(patch: "/users/#{user.id}/password").not_to be_routable
83
+ end
84
+ end
85
+
86
+ context 'reset enabled' do
87
+ it 'does route password edit' do
88
+ user = create(:user)
89
+ expect(get: "users/#{user.id}/password/edit").to be_routable
90
+ end
91
+
92
+ it 'does route to clearance/passwords#update' do
93
+ user = create(:user)
94
+ expect(patch: "/users/#{user.id}/password").to be_routable
95
+ end
96
+ end
65
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clearance
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.1
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Croak
@@ -23,10 +23,11 @@ authors:
23
23
  - Galen Frechette
24
24
  - Josh Steiner
25
25
  - Dorian Marié
26
+ - Sara Jackson
26
27
  autorequire:
27
28
  bindir: bin
28
29
  cert_chain: []
29
- date: 2024-05-08 00:00:00.000000000 Z
30
+ date: 2024-08-09 00:00:00.000000000 Z
30
31
  dependencies:
31
32
  - !ruby/object:Gem::Dependency
32
33
  name: bcrypt
@@ -146,7 +147,9 @@ extra_rdoc_files:
146
147
  - README.md
147
148
  files:
148
149
  - ".erb-lint.yml"
150
+ - ".github/dependabot.yml"
149
151
  - ".github/workflows/dynamic-readme.yml"
152
+ - ".github/workflows/dynamic-security.yml"
150
153
  - ".github/workflows/tests.yml"
151
154
  - ".gitignore"
152
155
  - ".yardopts"
@@ -160,6 +163,7 @@ files:
160
163
  - README.md
161
164
  - RELEASING.md
162
165
  - Rakefile
166
+ - SECURITY.md
163
167
  - app/controllers/clearance/base_controller.rb
164
168
  - app/controllers/clearance/passwords_controller.rb
165
169
  - app/controllers/clearance/sessions_controller.rb
@@ -314,7 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
314
318
  - !ruby/object:Gem::Version
315
319
  version: '0'
316
320
  requirements: []
317
- rubygems_version: 3.3.7
321
+ rubygems_version: 3.5.15
318
322
  signing_key:
319
323
  specification_version: 4
320
324
  summary: Rails authentication & authorization with email & password.