simple_auth 3.1.3 โ†’ 3.1.4

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
  SHA256:
3
- metadata.gz: b1d2a68a9455a5f601c57c8f98d70af46795e492f084815a9f2f1f929591d3b0
4
- data.tar.gz: 0f0cb2fec8e43e8d2c00970618bb120b9914d4c2ffe113b93038bacec2d8c4d4
3
+ metadata.gz: f49f3b991fd189a65c444c7fe0bbf4b6312ad268d15d09718554b17abede88de
4
+ data.tar.gz: 4b89cc2082720e7b13c778393cbd353737855e913417a55f520443cbcbbafd25
5
5
  SHA512:
6
- metadata.gz: 38930354c31b9b9b43970e0efc9d7ae0a71b643702fd8f37b46527a811e30174f32a31e339225d56f3c08175b7e96d24dc9baa764622bc2ad1b6bd27538d0e3d
7
- data.tar.gz: 80715edb98f53b659ca8a95cdda946863da7eb25e4310398621f0fffc24e4becbe0d78e2c9c412a06972a765bbc448a2ecfbf064abac0a10da7fe0b41bd607c1
6
+ metadata.gz: 3bc6961ef9d45a04f41988e5f1abaa47784edec75d74f49655fdc214285c16c63c2d0aca6d80aa669e7d21fad74434c5f0a570ba1a557a9c14e1d0822063154e
7
+ data.tar.gz: a23600ef945fb6675390133b84b6219edafa10a11ab524856a6535162ee8726ad007b5d0613af48706b461d8e4318a632170425533ebb8c2b6cd56af46145792
@@ -0,0 +1,4 @@
1
+ # You can read more about CODEOWNERS at
2
+ # https://help.github.com/github/creating-cloning-and-archiving-repositories/about-code-owners
3
+
4
+ * @fnando
@@ -0,0 +1,4 @@
1
+ # These are supported funding model platforms
2
+ ---
3
+ github: [fnando]
4
+ custom: ["https://paypal.me/nandovieira/๐Ÿ•"]
@@ -0,0 +1,41 @@
1
+ ---
2
+ name: "๐Ÿ› Bug Report"
3
+ about: Report a reproducible bug or regression.
4
+ title: 'Bug: '
5
+ labels: 'Status: Unconfirmed'
6
+
7
+ ---
8
+
9
+ <!--
10
+ - Please provide a clear and concise description of what the bug is.
11
+ - If possible, add an example reproducing your issue.
12
+ - Please test using the latest version of simple_auth
13
+ to make sure your issue has not already been fixed.
14
+ -->
15
+
16
+ ## Description
17
+
18
+ [Add bug description here]
19
+
20
+ ## How to reproduce
21
+
22
+ [Add steps on how to reproduce this issue]
23
+
24
+ ## What do you expect
25
+
26
+ [Describe what do you expect to happen]
27
+
28
+ ## What happened instead
29
+
30
+ [Describe the actual results]
31
+
32
+ ## Software:
33
+
34
+ - Gem version: [Add gem version here]
35
+ - Ruby version: [Add version here]
36
+
37
+ ## Full backtrace
38
+
39
+ ```text
40
+ [Paste full backtrace here]
41
+ ```
@@ -0,0 +1,5 @@
1
+ ---
2
+ contact_links:
3
+ - name: "๐Ÿคจ Q&A"
4
+ url: https://github.com/fnando/simple_auth/discussions/new?category=q-a
5
+ about: Have a question? Ask it away here!
@@ -0,0 +1,23 @@
1
+ ---
2
+ name: "๐Ÿ’ก Feature request"
3
+ about: Have an idea that may be useful? Make a suggestion!
4
+ title: 'Feature Request: '
5
+ labels: 'Feature request'
6
+
7
+ ---
8
+
9
+ ## Description
10
+
11
+ _A clear and concise description of what the problem is._
12
+
13
+ ## Describe the solution
14
+
15
+ _A clear and concise description of what you want to happen._
16
+
17
+ ## Alternatives you considered
18
+
19
+ _A clear and concise description of any alternative solutions or features you've considered._
20
+
21
+ ## Additional context
22
+
23
+ _Add any other context, screenshots, links, etc about the feature request here._
@@ -0,0 +1,38 @@
1
+ <!--
2
+ If you're making a doc PR or something tiny where the below is irrelevant,
3
+ delete this template and use a short description, but in your description aim to
4
+ include both what the change is, and why it is being made, with enough context
5
+ for anyone to understand.
6
+ -->
7
+
8
+ <details>
9
+ <summary>PR Checklist</summary>
10
+
11
+ ### PR Structure
12
+
13
+ - [ ] This PR has reasonably narrow scope (if not, break it down into smaller
14
+ PRs).
15
+ - [ ] This PR avoids mixing refactoring changes with feature changes (split into
16
+ two PRs otherwise).
17
+ - [ ] This PR's title starts is concise and descriptive.
18
+
19
+ ### Thoroughness
20
+
21
+ - [ ] This PR adds tests for the most critical parts of the new functionality or
22
+ fixes.
23
+ - [ ] I've updated any docs, `.md` files, etcโ€ฆ affected by this change.
24
+
25
+ </details>
26
+
27
+ ### What
28
+
29
+ [TODO: Short statement about what is changing.]
30
+
31
+ ### Why
32
+
33
+ [TODO: Why this change is being made. Include any context required to understand
34
+ the why.]
35
+
36
+ ### Known limitations
37
+
38
+ [TODO or N/A]
@@ -0,0 +1,15 @@
1
+ ---
2
+ # Documentation:
3
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
4
+
5
+ version: 2
6
+ updates:
7
+ - package-ecosystem: "github-actions"
8
+ directory: "/"
9
+ schedule:
10
+ interval: "daily"
11
+
12
+ - package-ecosystem: bundler
13
+ directory: "/"
14
+ schedule:
15
+ interval: "daily"
@@ -0,0 +1,74 @@
1
+ ---
2
+ name: ruby-tests
3
+
4
+ on:
5
+ pull_request_target:
6
+ push:
7
+ branches:
8
+ - main
9
+ workflow_dispatch:
10
+ inputs: {}
11
+
12
+ jobs:
13
+ build:
14
+ name: Tests with Ruby ${{ matrix.ruby }} and ${{ matrix.gemfile }}
15
+ runs-on: "ubuntu-latest"
16
+ if: |
17
+ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request_target' ||
18
+ github.actor != 'dependabot[bot]'
19
+ strategy:
20
+ fail-fast: false
21
+ matrix:
22
+ ruby: ["2.7", "3.0", "3.1"]
23
+ gemfile:
24
+ - Gemfile
25
+ - gemfiles/rails_7_0.gemfile
26
+ - gemfiles/rails_6_1.gemfile
27
+ - gemfiles/rails_6_0.gemfile
28
+
29
+ services:
30
+ postgres:
31
+ image: postgres:11.5
32
+ ports: ["5432:5432"]
33
+ options:
34
+ --health-cmd pg_isready --health-interval 10s --health-timeout 5s
35
+ --health-retries 5
36
+
37
+ steps:
38
+ - uses: actions/checkout@v3
39
+
40
+ - uses: actions/cache@v3
41
+ with:
42
+ path: vendor/bundle
43
+ key: >
44
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-${{
45
+ hashFiles(matrix.gemfile) }}
46
+
47
+ - name: Set up Ruby
48
+ uses: ruby/setup-ruby@v1
49
+ with:
50
+ ruby-version: ${{ matrix.ruby }}
51
+
52
+ - name: Install PostgreSQL client
53
+ env:
54
+ PGHOST: localhost
55
+ PGUSER: postgres
56
+ run: |
57
+ sudo apt-get -yqq install libpq-dev
58
+ psql -U postgres -c "create database test"
59
+
60
+ - name: Install gem dependencies
61
+ env:
62
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
63
+ run: |
64
+ gem install bundler
65
+ bundle config path vendor/bundle
66
+ bundle update --jobs 4 --retry 3
67
+
68
+ - name: Run Tests
69
+ env:
70
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
71
+ PGHOST: localhost
72
+ PGUSER: postgres
73
+ run: |
74
+ bundle exec rake
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@ inherit_gem:
3
3
  rubocop-fnando: .rubocop.yml
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.6
7
-
8
- Metrics/AbcSize:
9
- Enabled: false
6
+ TargetRubyVersion: 2.7
7
+ Exclude:
8
+ - gemfiles/**/*
9
+ - vendor/**/*
data/CHANGELOG.md CHANGED
@@ -1,45 +1,51 @@
1
- # v3.1.3
1
+ # Changelog
2
+
3
+ ## v3.1.4
4
+
5
+ - Add `authenticate(scope, condition, &block)`, so you can restrict routes
6
+ directly from the routes definition.
7
+
8
+ ## v3.1.3
2
9
 
3
10
  - Remove session[:return_to] after using it.
4
11
 
5
- # v3.1.2
12
+ ## v3.1.2
6
13
 
7
14
  - Make flash message key configurable via
8
15
  `SimpleAuth::Config#flash_message_key`.
9
16
 
10
- # v3.1.1
17
+ ## v3.1.1
11
18
 
12
19
  - Catch exceptions related to record not found when session tries to load a
13
20
  record from session. You can customize the recognized exceptions by adding the
14
21
  error class to `SimpleAuth::Session.record_not_found_exceptions`.
15
22
 
16
- # v3.1.0
23
+ ## v3.1.0
17
24
 
18
25
  - SimpleAuth now uses [GlobalID](https://github.com/rails/globalid) as the
19
26
  identification that's saved on the session. This should be a seamless
20
27
  migration (users will only have to re-login). This allows using any objects
21
28
  that respond to `#to_gid`, including namespaced models and POROs.
22
29
 
23
- # v3.0.0
30
+ ## v3.0.0
24
31
 
25
32
  - Reimplemented library.
26
33
  - Add support for scoped authentication (e.g. user and admin).
27
34
 
28
- # v2.0.3
35
+ ## v2.0.3
29
36
 
30
37
  - Assign the raw password/confirmation, so we can apply validations on the raw
31
38
  value.
32
39
 
33
- # v2.0.2
40
+ ## v2.0.2
34
41
 
35
42
  - The compat wasn't validating fields correctly.
36
43
 
37
- # v2.0.1
44
+ ## v2.0.1
38
45
 
39
46
  - The compat mode wasn't generating the `password_digest`.
40
47
 
41
- # v2.0.0
48
+ ## v2.0.0
42
49
 
43
- - Released version 2.0.0. This version removes support for MongoDB
44
- and switches to `has_secure_password` encryption method. This
45
- change requires Rails 3.1.0+.
50
+ - Released version 2.0.0. This version removes support for MongoDB and switches
51
+ to `has_secure_password` encryption method. This change requires Rails 3.1.0+.
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at me@fnando.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2010 Nando Vieira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the 'Software'), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # Simple Auth
2
2
 
3
- [![Travis-CI](https://travis-ci.org/fnando/simple_auth.svg)](https://travis-ci.org/fnando/simple_auth)
4
- [![Code Climate](https://codeclimate.com/github/fnando/simple_auth/badges/gpa.svg)](https://codeclimate.com/github/fnando/simple_auth)
5
- [![Test Coverage](https://codeclimate.com/github/fnando/simple_auth/badges/coverage.svg)](https://codeclimate.com/github/fnando/simple_auth/coverage)
3
+ [![Tests](https://github.com/fnando/simple_auth/workflows/ruby-tests/badge.svg)](https://github.com/fnando/simple_auth)
6
4
  [![Gem](https://img.shields.io/gem/v/simple_auth.svg)](https://rubygems.org/gems/simple_auth)
7
5
  [![Gem](https://img.shields.io/gem/dt/simple_auth.svg)](https://rubygems.org/gems/simple_auth)
6
+ [![MIT License](https://img.shields.io/:License-MIT-blue.svg)](https://tldrlegal.com/license/mit-license)
8
7
 
9
8
  SimpleAuth is an authentication library to be used when everything else is just
10
9
  too complicated.
@@ -136,11 +135,27 @@ current_#{scope} # e.g. current_user (available in controller & views)
136
135
  #{scope}_session # e.g. user_session (available in controller & views)
137
136
  ```
138
137
 
138
+ #### From your routes file
139
+
140
+ You can also restrict routes directly from your routes:
141
+
142
+ ```ruby
143
+ Rails.application.routes.draw do
144
+ authenticate :admin, ->(user) { user.admin? } do
145
+ mount Sidekiq::Web, at: "sidekiq"
146
+ end
147
+ end
148
+ ```
149
+
150
+ In this case, `:admin` is the scope and the lambda will only be called whenever
151
+ there's a valid record associated with that record.
152
+
139
153
  ### Translations
140
154
 
141
155
  These are the translations you'll need:
142
156
 
143
157
  ```yaml
158
+ ---
144
159
  en:
145
160
  simple_auth:
146
161
  user:
@@ -154,6 +169,7 @@ To display the error message, use something like `<%= flash[:alert] %>`. If you
154
169
  want to use a custom key, say `:error`, use the configuration file
155
170
  `config/initializers/simple_auth.rb` to define the new key:
156
171
 
172
+ ```ruby
157
173
  # config/initializers/simple_auth.rb
158
174
  SimpleAuth.setup do |config|
159
175
  # ...
@@ -166,27 +182,25 @@ end
166
182
 
167
183
  ## Maintainer
168
184
 
169
- * Nando Vieira (<http://nandovieira.com>)
185
+ - [Nando Vieira](https://github.com/fnando)
186
+
187
+ ## Contributors
188
+
189
+ - https://github.com/fnando/simple_auth/contributors
190
+
191
+ ## Contributing
170
192
 
171
- ## License:
193
+ For more details about how to contribute, please read
194
+ https://github.com/fnando/simple_auth/blob/main/CONTRIBUTING.md.
172
195
 
173
- (The MIT License)
196
+ ## License
174
197
 
175
- Permission is hereby granted, free of charge, to any person obtaining
176
- a copy of this software and associated documentation files (the
177
- 'Software'), to deal in the Software without restriction, including
178
- without limitation the rights to use, copy, modify, merge, publish,
179
- distribute, sublicense, and/or sell copies of the Software, and to
180
- permit persons to whom the Software is furnished to do so, subject to
181
- the following conditions:
198
+ The gem is available as open source under the terms of the
199
+ [MIT License](https://opensource.org/licenses/MIT). A copy of the license can be
200
+ found at https://github.com/fnando/simple_auth/blob/main/LICENSE.md.
182
201
 
183
- The above copyright notice and this permission notice shall be
184
- included in all copies or substantial portions of the Software.
202
+ ## Code of Conduct
185
203
 
186
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
187
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
188
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
189
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
190
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
191
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
192
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
204
+ Everyone interacting in the simple_auth project's codebases, issue trackers,
205
+ chat rooms and mailing lists is expected to follow the
206
+ [code of conduct](https://github.com/fnando/simple_auth/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+
6
+ gem "rails", "~> 6.1.0"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec path: ".."
5
+
6
+ gem "rails", "~> 7.0.0"
@@ -16,16 +16,25 @@ module SimpleAuth
16
16
  end
17
17
  end
18
18
 
19
- def install_simple_auth_scope(scope) # rubocop:disable Metrics/MethodLength
19
+ def install_simple_auth_scope(scope)
20
20
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
21
+ # def user_session
22
+ # @user_session ||= Session.create(scope: :user, session: session)
23
+ # end
21
24
  def #{scope}_session
22
25
  @#{scope}_session ||= Session.create(scope: :#{scope}, session: session)
23
26
  end
24
27
 
28
+ # def current_user
29
+ # user_session.record
30
+ # end
25
31
  def current_#{scope}
26
32
  #{scope}_session.record
27
33
  end
28
34
 
35
+ # def user_logged_in?
36
+ # current_user.present?
37
+ # end
29
38
  def #{scope}_logged_in?
30
39
  current_#{scope}.present?
31
40
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SimpleAuth
4
+ module RoutingMapper
5
+ class Matcher
6
+ attr_reader :scope, :condition
7
+
8
+ def initialize(scope:, condition:)
9
+ @scope = scope
10
+ @condition = condition
11
+ end
12
+
13
+ def call(request)
14
+ session = Session.create(scope: scope, session: request.session)
15
+ record = session.record
16
+
17
+ record && condition.call(record)
18
+ end
19
+ end
20
+
21
+ def authenticate(scope, condition, &block)
22
+ with_options(
23
+ constraints: Matcher.new(scope: scope, condition: condition)
24
+ ) do
25
+ instance_eval(&block)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleAuth
4
- VERSION = "3.1.3"
4
+ VERSION = "3.1.4"
5
5
  end
data/lib/simple_auth.rb CHANGED
@@ -4,15 +4,19 @@ module SimpleAuth
4
4
  require "rails/railtie"
5
5
  require "global_id/railtie"
6
6
  require "active_support/concern"
7
+ require "action_dispatch/routing/mapper"
7
8
 
8
9
  require "simple_auth/version"
9
10
  require "simple_auth/config"
10
11
  require "simple_auth/railtie"
11
12
  require "simple_auth/action_controller"
13
+ require "simple_auth/routing_mapper"
12
14
  require "simple_auth/action_controller/require_login_action"
13
15
  require "simple_auth/session"
14
16
  require "simple_auth/generator"
15
17
 
18
+ ::ActionDispatch::Routing::Mapper.prepend SimpleAuth::RoutingMapper
19
+
16
20
  def self.setup
17
21
  yield config
18
22
  end
data/simple_auth.gemspec CHANGED
@@ -11,6 +11,18 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "http://rubygems.org/gems/simple_auth"
12
12
  s.summary = "A simple authentication system for Rails apps"
13
13
  s.description = s.summary
14
+ s.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
15
+
16
+ github_url = "https://github.com/fnando/simple_auth"
17
+ github_tree_url = "#{github_url}/tree/v#{s.version}"
18
+
19
+ s.metadata["homepage_uri"] = s.homepage
20
+ s.metadata["bug_tracker_uri"] = "#{github_url}/issues"
21
+ s.metadata["source_code_uri"] = github_tree_url
22
+ s.metadata["changelog_uri"] = "#{github_tree_url}/CHANGELOG.md"
23
+ s.metadata["documentation_uri"] = "#{github_tree_url}/README.md"
24
+ s.metadata["license_uri"] = "#{github_tree_url}/LICENSE.md"
25
+ s.metadata["rubygems_mfa_required"] = "true"
14
26
 
15
27
  s.files = `git ls-files`.split("\n")
16
28
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class AdminTest < ActionDispatch::IntegrationTest
6
+ setup do
7
+ User.delete_all
8
+ end
9
+
10
+ def create_records
11
+ admin = User.create!(
12
+ password: "test",
13
+ email: "admin@example.com",
14
+ admin: true
15
+ )
16
+ user = User.create!(
17
+ password: "test",
18
+ email: "john@example.com",
19
+ admin: false
20
+ )
21
+
22
+ [admin, user]
23
+ end
24
+
25
+ test "allows users with admin flag to access page" do
26
+ admin, _ = *create_records
27
+
28
+ get "/only/admins"
29
+ assert_equal 404, response.status
30
+
31
+ get "/only/admins-by-email"
32
+ assert_equal 404, response.status
33
+
34
+ post "/start-session", params: {scope: "admin", id: admin.id}
35
+ assert_equal 200, response.status
36
+
37
+ get "/only/admins"
38
+ assert_equal 200, response.status
39
+
40
+ get "/only/admins-by-email"
41
+ assert_equal 404, response.status
42
+ end
43
+
44
+ test "allows users with admin email to access page" do
45
+ admin, _ = *create_records
46
+
47
+ get "/only/admins"
48
+ assert_equal 404, response.status
49
+
50
+ get "/only/admins-by-email"
51
+ assert_equal 404, response.status
52
+
53
+ post "/start-session", params: {scope: "user", id: admin.id}
54
+ assert_equal 200, response.status
55
+
56
+ get "/only/admins"
57
+ assert_equal 404, response.status
58
+
59
+ get "/only/admins-by-email"
60
+ assert_equal 200, response.status
61
+ end
62
+
63
+ test "rejects users with non admin email" do
64
+ _, user = *create_records
65
+
66
+ get "/only/admins"
67
+ assert_equal 404, response.status
68
+
69
+ get "/only/admins-by-email"
70
+ assert_equal 404, response.status
71
+
72
+ post "/start-session", params: {scope: "user", id: user.id}
73
+ assert_equal 200, response.status
74
+
75
+ get "/only/admins"
76
+ assert_equal 404, response.status
77
+
78
+ get "/only/admins-by-email"
79
+ assert_equal 404, response.status
80
+ end
81
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SessionsController < ApplicationController
4
+ def create_session
5
+ session["#{params[:scope]}_id"] = User.find(params[:id]).to_gid.to_s
6
+ render plain: "", status: 200
7
+ end
8
+
9
+ def terminate_session
10
+ reset_session
11
+ render plain: "", status: 200
12
+ end
13
+ end
@@ -5,6 +5,17 @@ Rails.application.routes.draw do
5
5
  get "/admin/dashboard", to: "admin/dashboard#index"
6
6
  get "/login", to: "sessions#new"
7
7
 
8
+ post "/start-session", to: "sessions#create_session"
9
+ post "/terminate-session", to: "sessions#terminate_session"
10
+
11
+ authenticate :admin, ->(u) { u.admin? } do
12
+ get "/only/admins", to: ->(_env) { [200, {}, ["OK"]] }
13
+ end
14
+
15
+ authenticate :user, ->(u) { u.email == "admin@example.com" } do
16
+ get "only/admins-by-email", to: ->(_env) { [200, {}, ["OK"]] }
17
+ end
18
+
8
19
  controller :dashboard do
9
20
  get :log_in
10
21
  get :not_logged
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: 3.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-21 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: globalid
@@ -172,23 +172,35 @@ executables:
172
172
  extensions: []
173
173
  extra_rdoc_files: []
174
174
  files:
175
+ - ".github/CODEOWNERS"
176
+ - ".github/FUNDING.yml"
177
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
178
+ - ".github/ISSUE_TEMPLATE/config.yml"
179
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
180
+ - ".github/PULL_REQUEST_TEMPLATE.md"
181
+ - ".github/dependabot.yml"
182
+ - ".github/workflows/ruby-tests.yml"
175
183
  - ".gitignore"
176
184
  - ".rubocop.yml"
177
- - ".travis.yml"
178
185
  - CHANGELOG.md
186
+ - CODE_OF_CONDUCT.md
179
187
  - Gemfile
188
+ - LICENSE.md
180
189
  - MIGRATE.md
181
190
  - README.md
182
191
  - Rakefile
183
192
  - bin/console
184
193
  - gemfiles/rails_5_2.gemfile
185
194
  - gemfiles/rails_6_0.gemfile
195
+ - gemfiles/rails_6_1.gemfile
196
+ - gemfiles/rails_7_0.gemfile
186
197
  - lib/simple_auth.rb
187
198
  - lib/simple_auth/action_controller.rb
188
199
  - lib/simple_auth/action_controller/require_login_action.rb
189
200
  - lib/simple_auth/config.rb
190
201
  - lib/simple_auth/generator.rb
191
202
  - lib/simple_auth/railtie.rb
203
+ - lib/simple_auth/routing_mapper.rb
192
204
  - lib/simple_auth/session.rb
193
205
  - lib/simple_auth/templates/install/initializer.rb
194
206
  - lib/simple_auth/version.rb
@@ -197,10 +209,12 @@ files:
197
209
  - test/controllers/dashboard_controller_test.rb
198
210
  - test/controllers/pages_controller_test.rb
199
211
  - test/generators/install_test.rb
212
+ - test/requests/admin_test.rb
200
213
  - test/support/dummy/app/controllers/admin/dashboard_controller.rb
201
214
  - test/support/dummy/app/controllers/application_controller.rb
202
215
  - test/support/dummy/app/controllers/dashboard_controller.rb
203
216
  - test/support/dummy/app/controllers/pages_controller.rb
217
+ - test/support/dummy/app/controllers/sessions_controller.rb
204
218
  - test/support/dummy/app/models/user.rb
205
219
  - test/support/dummy/config/application.rb
206
220
  - test/support/dummy/config/initializers/simple_auth.rb
@@ -210,8 +224,15 @@ files:
210
224
  - test/unit/session_test.rb
211
225
  homepage: http://rubygems.org/gems/simple_auth
212
226
  licenses: []
213
- metadata: {}
214
- post_install_message:
227
+ metadata:
228
+ homepage_uri: http://rubygems.org/gems/simple_auth
229
+ bug_tracker_uri: https://github.com/fnando/simple_auth/issues
230
+ source_code_uri: https://github.com/fnando/simple_auth/tree/v3.1.4
231
+ changelog_uri: https://github.com/fnando/simple_auth/tree/v3.1.4/CHANGELOG.md
232
+ documentation_uri: https://github.com/fnando/simple_auth/tree/v3.1.4/README.md
233
+ license_uri: https://github.com/fnando/simple_auth/tree/v3.1.4/LICENSE.md
234
+ rubygems_mfa_required: 'true'
235
+ post_install_message:
215
236
  rdoc_options: []
216
237
  require_paths:
217
238
  - lib
@@ -219,15 +240,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
240
  requirements:
220
241
  - - ">="
221
242
  - !ruby/object:Gem::Version
222
- version: '0'
243
+ version: 2.7.0
223
244
  required_rubygems_version: !ruby/object:Gem::Requirement
224
245
  requirements:
225
246
  - - ">="
226
247
  - !ruby/object:Gem::Version
227
248
  version: '0'
228
249
  requirements: []
229
- rubygems_version: 3.1.2
230
- signing_key:
250
+ rubygems_version: 3.4.1
251
+ signing_key:
231
252
  specification_version: 4
232
253
  summary: A simple authentication system for Rails apps
233
254
  test_files:
@@ -235,10 +256,12 @@ test_files:
235
256
  - test/controllers/dashboard_controller_test.rb
236
257
  - test/controllers/pages_controller_test.rb
237
258
  - test/generators/install_test.rb
259
+ - test/requests/admin_test.rb
238
260
  - test/support/dummy/app/controllers/admin/dashboard_controller.rb
239
261
  - test/support/dummy/app/controllers/application_controller.rb
240
262
  - test/support/dummy/app/controllers/dashboard_controller.rb
241
263
  - test/support/dummy/app/controllers/pages_controller.rb
264
+ - test/support/dummy/app/controllers/sessions_controller.rb
242
265
  - test/support/dummy/app/models/user.rb
243
266
  - test/support/dummy/config/application.rb
244
267
  - test/support/dummy/config/initializers/simple_auth.rb
data/.travis.yml DELETED
@@ -1,22 +0,0 @@
1
- ---
2
- sudo: false
3
- cache: bundler
4
- rvm:
5
- - 2.7.0
6
- - 2.6.5
7
- - 2.5.7
8
- script: bundle exec rake
9
- before_script:
10
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11
- - chmod +x ./cc-test-reporter
12
- - "./cc-test-reporter before-build"
13
- after_script:
14
- - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
15
- notifications:
16
- email: false
17
- gemfile:
18
- - gemfiles/rails_6_0.gemfile
19
- - gemfiles/rails_5_2.gemfile
20
- env:
21
- global:
22
- secure: LglasZ2QJLCE2tSKyZ9wIZNNwDNQ/gi+QNSHlpK2olgBOYMKV1idJPZjUlSTAac7+QHTYRRGCoUVMYHWxJgLfcuo7YpXVAgqPwjVl5nbHKfh/oP/FLriELKZbqMo0TtuqZNdnqPdO8RE7zK0om37jYNoUPJ4j2mUVLC8PMZpbiM=