tiddle 1.5.0 → 1.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +53 -0
  3. data/.rubocop.yml +67 -9
  4. data/CHANGELOG.md +26 -0
  5. data/CONTRIBUTING.md +1 -2
  6. data/README.md +2 -6
  7. data/Rakefile +1 -6
  8. data/gemfiles/rails5.2.gemfile +0 -3
  9. data/gemfiles/rails6.0.gemfile +0 -3
  10. data/gemfiles/rails6.1.gemfile +7 -0
  11. data/gemfiles/rails7.0.gemfile +7 -0
  12. data/lib/tiddle/model_name.rb +7 -1
  13. data/lib/tiddle/token_issuer.rb +9 -4
  14. data/lib/tiddle/version.rb +1 -1
  15. data/spec/rails_app_active_record/app/controllers/namespaced_users_controller.rb +7 -0
  16. data/spec/rails_app_active_record/app/models/namespace/namespaced_user.rb +9 -0
  17. data/spec/rails_app_active_record/config/application.rb +3 -2
  18. data/spec/rails_app_active_record/config/boot.rb +1 -1
  19. data/spec/rails_app_active_record/config/environment.rb +1 -1
  20. data/spec/rails_app_active_record/config/routes.rb +2 -0
  21. data/spec/rails_app_active_record/db/migrate/20150217000000_create_tables.rb +23 -7
  22. data/spec/rails_app_mongoid/app/controllers/namespaced_users_controller.rb +7 -0
  23. data/spec/rails_app_mongoid/app/models/authentication_token.rb +1 -0
  24. data/spec/rails_app_mongoid/app/models/namespace/namespaced_user.rb +4 -0
  25. data/spec/rails_app_mongoid/app/models/user.rb +1 -1
  26. data/spec/rails_app_mongoid/config/application.rb +2 -2
  27. data/spec/rails_app_mongoid/config/boot.rb +1 -1
  28. data/spec/rails_app_mongoid/config/environment.rb +1 -1
  29. data/spec/rails_app_mongoid/config/routes.rb +2 -0
  30. data/spec/spec_helper.rb +0 -5
  31. data/spec/strategy_spec.rb +33 -12
  32. data/spec/support/backend.rb +2 -7
  33. data/spec/support/fake_request.rb +1 -3
  34. data/spec/tiddle_spec.rb +5 -0
  35. data/tiddle.gemspec +5 -6
  36. metadata +22 -31
  37. data/.travis.yml +0 -27
  38. data/Appraisals +0 -17
  39. data/Gemfile +0 -6
  40. data/gemfiles/rails4.2.gemfile +0 -10
  41. data/spec/support/warningless_get.rb +0 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bd6e3feb1ccba22684e65085d74f245e894178246b8535c4ccc4d885984b154
4
- data.tar.gz: c12348cf95c0731af63b99b8804e825652791e7c166d35d8f539a172fbb78601
3
+ metadata.gz: a348d248985933eddf79f194679aa3c1ee6724006f3386a88d143efff7080b0d
4
+ data.tar.gz: 36f11c54b9cb1829fbbe07e200f404bb8958265582854dd71583a4f90565ef4b
5
5
  SHA512:
6
- metadata.gz: c8e9eaf42c24032583f36906d73950ebaab11252193629f5b82045a8d81f51b39ca98beefb58ccec234499458407f4cdf0406902a166a5232ff713678d704207
7
- data.tar.gz: d80bf9abe5d72446839eaab8f7dcb6d5c6521f8c15f0d646c564b8bb635c0d3475cf177cfbc917aab7a68b469613b3722657085a2a8599ffc5a394f087f0168e
6
+ metadata.gz: b2001e1d59b7fe3596dd7727477e3315f7bc91d4725653ace774bdce0804dd11dceded3908d8be15bf05f8bbcb30e29b90ea8e99366069e693e2eb1ed7526960
7
+ data.tar.gz: 34064918737c1c9d1da935488fee01b711823cedc9c5b7ccfd411b30a94390b241ca7a9f6106ecb8c9acb7a6847a475ad2f9930a431d39417a495e7a9a4df812
@@ -0,0 +1,53 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ gemfile:
15
+ - rails5.2
16
+ - rails6.0
17
+ - rails6.1
18
+ - rails7.0
19
+ ruby:
20
+ - "2.7"
21
+ - "3.0"
22
+ - "3.1"
23
+ backend:
24
+ - active_record
25
+ - mongoid
26
+ exclude:
27
+ - gemfile: rails5.2
28
+ ruby: "3.0"
29
+ - gemfile: rails5.2
30
+ ruby: "3.1"
31
+ - gemfile: rails6.0
32
+ ruby: "3.1"
33
+ - gemfile: rails6.1
34
+ ruby: "3.1"
35
+ name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }}, ${{ matrix.backend }}
36
+ runs-on: ubuntu-latest
37
+ env:
38
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
39
+ BACKEND: ${{ matrix.backend }}
40
+
41
+ steps:
42
+ - uses: actions/checkout@v2
43
+ - name: Set up Ruby
44
+ uses: ruby/setup-ruby@v1
45
+ with:
46
+ bundler-cache: true
47
+ ruby-version: ${{ matrix.ruby }}
48
+ - name: Start MongoDB
49
+ uses: supercharge/mongodb-github-action@1.3.0
50
+ if: ${{ matrix.backend == 'mongoid' }}
51
+ - name: Run tests
52
+ run: |
53
+ bundle exec rake spec
data/.rubocop.yml CHANGED
@@ -1,11 +1,13 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.6
3
3
  Include:
4
- - 'lib'
5
- - 'spec'
4
+ - 'lib/**/*.rb'
5
+ - 'spec/**/*.rb'
6
6
  Exclude:
7
7
  - 'spec/rails_app/**/*'
8
8
  - 'spec/spec_helper.rb'
9
+ - 'vendor/bundle/**/*'
10
+ SuggestExtensions: false
9
11
  Style/StringLiterals:
10
12
  Enabled: false
11
13
  Style/Documentation:
@@ -14,17 +16,73 @@ Style/FrozenStringLiteralComment:
14
16
  Enabled: false
15
17
  Style/SignalException:
16
18
  Enabled: false
17
- Metrics/LineLength:
19
+ Layout/LineLength:
18
20
  Max: 100
19
21
  Gemspec/OrderedDependencies:
20
22
  Enabled: false
21
- Naming/FileName:
22
- Exclude:
23
- - 'Rakefile'
24
- - 'Gemfile'
25
- - 'Appraisals'
26
23
  Metrics/BlockLength:
27
24
  Exclude:
28
25
  - 'spec/**/*'
29
26
  Metrics/MethodLength:
30
27
  Max: 15
28
+
29
+ Gemspec/DateAssignment:
30
+ Enabled: true
31
+ Layout/SpaceBeforeBrackets:
32
+ Enabled: true
33
+ Lint/AmbiguousAssignment:
34
+ Enabled: true
35
+ Lint/DeprecatedConstants:
36
+ Enabled: true
37
+ Lint/DuplicateBranch:
38
+ Enabled: true
39
+ Lint/DuplicateRegexpCharacterClassElement:
40
+ Enabled: true
41
+ Lint/EmptyBlock:
42
+ Enabled: true
43
+ Lint/EmptyClass:
44
+ Enabled: true
45
+ Lint/LambdaWithoutLiteralBlock:
46
+ Enabled: true
47
+ Lint/NoReturnInBeginEndBlocks:
48
+ Enabled: true
49
+ Lint/NumberedParameterAssignment:
50
+ Enabled: true
51
+ Lint/OrAssignmentToConstant:
52
+ Enabled: true
53
+ Lint/RedundantDirGlobSort:
54
+ Enabled: true
55
+ Lint/SymbolConversion:
56
+ Enabled: true
57
+ Lint/ToEnumArguments:
58
+ Enabled: true
59
+ Lint/TripleQuotes:
60
+ Enabled: true
61
+ Lint/UnexpectedBlockArity:
62
+ Enabled: true
63
+ Lint/UnmodifiedReduceAccumulator:
64
+ Enabled: true
65
+ Style/ArgumentsForwarding:
66
+ Enabled: true
67
+ Style/CollectionCompact:
68
+ Enabled: true
69
+ Style/DocumentDynamicEvalDefinition:
70
+ Enabled: true
71
+ Style/EndlessMethod:
72
+ Enabled: true
73
+ Style/HashConversion:
74
+ Enabled: true
75
+ Style/HashExcept:
76
+ Enabled: true
77
+ Style/IfWithBooleanLiteralBranches:
78
+ Enabled: true
79
+ Style/NegatedIfElseCondition:
80
+ Enabled: true
81
+ Style/NilLambda:
82
+ Enabled: true
83
+ Style/RedundantArgument:
84
+ Enabled: true
85
+ Style/StringChars:
86
+ Enabled: true
87
+ Style/SwapValues:
88
+ Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ### 1.7.1
2
+
3
+ Fix invalid headers generated when model is namespaced (Ariel Agne da Silveira)
4
+
5
+ Add Rails 7.0 support
6
+
7
+ Add Ruby 3.1 support
8
+
9
+ Remove Ruby 2.6 support
10
+
11
+ ### 1.7.0
12
+
13
+ Add ability to track additional info in tokens (Marcelo Silveira)
14
+
15
+ Remove Ruby 2.5 support
16
+
17
+ ### 1.6.0
18
+
19
+ Add Rails 6.1 support
20
+
21
+ Add Ruby 3.0 support
22
+
23
+ Remove Rails 4.2 support
24
+
25
+ Remove Ruby 2.4 support
26
+
1
27
  ### 1.5.0
2
28
 
3
29
  Add Rails 6 support
data/CONTRIBUTING.md CHANGED
@@ -4,8 +4,7 @@
4
4
  2. Run the tests:
5
5
 
6
6
  ```
7
- appraisal install
8
- rake
7
+ BUNDLE_GEMFILE=gemfiles/<PICK YOUR FAVOURITE>.gemfile rake
9
8
  ```
10
9
  3. Introduce your change. If it's a new feature then write a test for it as well.
11
10
  4. Make sure that tests are passing.
data/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # Tiddle
2
2
 
3
- [![Build Status](https://travis-ci.org/adamniedzielski/tiddle.svg?branch=master)](https://travis-ci.org/adamniedzielski/tiddle)
4
- [![Coverage Status](https://coveralls.io/repos/adamniedzielski/tiddle/badge.svg?branch=master)](https://coveralls.io/r/adamniedzielski/tiddle?branch=master)
5
- [![Code Climate](https://codeclimate.com/github/adamniedzielski/tiddle/badges/gpa.svg)](https://codeclimate.com/github/adamniedzielski/tiddle)
6
-
7
3
  Tiddle provides Devise strategy for token authentication in API-only Ruby on Rails applications. Its main feature is **support for multiple tokens per user**.
8
4
 
9
5
  Tiddle is lightweight and non-configurable. It does what it has to do and leaves some manual implementation to you.
@@ -85,7 +81,7 @@ end
85
81
 
86
82
  5) Send ```X-USER-EMAIL``` and ```X-USER-TOKEN``` as headers of every request which requires authentication.
87
83
 
88
- You can read more in a blog post dedicated to Tiddle - http://adamniedzielski.github.io/blog/2015/04/04/token-authentication-with-tiddle/
84
+ You can read more in a blog post dedicated to Tiddle - https://blog.sundaycoding.com/blog/2015/04/04/token-authentication-with-tiddle/
89
85
 
90
86
  ## Note on Rails session
91
87
 
@@ -95,7 +91,7 @@ The safest solution in API-only application is not to rely on Rails session at a
95
91
  config.middleware.delete ActionDispatch::Session::CookieStore
96
92
  ```
97
93
 
98
- More: http://adamniedzielski.github.io/blog/2015/04/04/token-authentication-with-tiddle/#rails-session
94
+ More: https://blog.sundaycoding.com/blog/2015/04/04/token-authentication-with-tiddle/#rails-session
99
95
 
100
96
  ## Using field other than email
101
97
 
data/Rakefile CHANGED
@@ -1,13 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require 'rspec/core/rake_task'
3
3
  require 'rubocop/rake_task'
4
- require 'appraisal'
5
4
 
6
5
  RSpec::Core::RakeTask.new(spec: :rubocop)
7
6
  RuboCop::RakeTask.new(:rubocop)
8
7
 
9
- if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
10
- task default: :appraisal
11
- else
12
- task default: :spec
13
- end
8
+ task default: :spec
@@ -1,8 +1,5 @@
1
- # This file was generated by Appraisal
2
-
3
1
  source "https://rubygems.org"
4
2
 
5
- gem "rubocop", "~> 0.52.0"
6
3
  gem "rails", "~> 5.2.1"
7
4
  gem "mongoid", "~> 6"
8
5
  gem "sqlite3", "~> 1.3.13"
@@ -1,8 +1,5 @@
1
- # This file was generated by Appraisal
2
-
3
1
  source "https://rubygems.org"
4
2
 
5
- gem "rubocop", "~> 0.52.0"
6
3
  gem "rails", "~> 6.0.0"
7
4
  gem "mongoid", "~> 7"
8
5
  gem "sqlite3"
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 6.1.0"
4
+ gem "mongoid"
5
+ gem "sqlite3"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 7.0.2"
4
+ gem "mongoid"
5
+ gem "sqlite3"
6
+
7
+ gemspec path: "../"
@@ -1,11 +1,17 @@
1
1
  module Tiddle
2
2
  class ModelName
3
3
  def with_underscores(model)
4
- model.model_name.to_s.underscore.upcase
4
+ colon_to_underscore(model).underscore.upcase
5
5
  end
6
6
 
7
7
  def with_dashes(model)
8
8
  with_underscores(model).dasherize
9
9
  end
10
+
11
+ private
12
+
13
+ def colon_to_underscore(model)
14
+ model.model_name.to_s.tr(':', '_')
15
+ end
10
16
  end
11
17
  end
@@ -12,12 +12,17 @@ module Tiddle
12
12
  self.maximum_tokens_per_user = maximum_tokens_per_user
13
13
  end
14
14
 
15
- def create_and_return_token(resource, request, expires_in: nil)
15
+ def create_and_return_token(resource, request, expires_in: nil, metadata: {})
16
16
  token_class = authentication_token_class(resource)
17
17
  token, token_body = Devise.token_generator.generate(token_class, :body)
18
18
 
19
19
  resource.authentication_tokens.create!(
20
- token_attributes(token_body, request, expires_in)
20
+ token_attributes(
21
+ token_body: token_body,
22
+ request: request,
23
+ expires_in: expires_in,
24
+ metadata: metadata
25
+ )
21
26
  )
22
27
 
23
28
  token
@@ -56,13 +61,13 @@ module Tiddle
56
61
  end
57
62
  end
58
63
 
59
- def token_attributes(token_body, request, expires_in)
64
+ def token_attributes(token_body:, request:, expires_in:, metadata: {})
60
65
  attributes = {
61
66
  body: token_body,
62
67
  last_used_at: Time.current,
63
68
  ip_address: request.remote_ip,
64
69
  user_agent: request.user_agent
65
- }
70
+ }.merge(metadata)
66
71
 
67
72
  if expires_in
68
73
  attributes.merge(expires_in: expires_in)
@@ -1,3 +1,3 @@
1
1
  module Tiddle
2
- VERSION = "1.5.0".freeze
2
+ VERSION = "1.7.1".freeze
3
3
  end
@@ -0,0 +1,7 @@
1
+ class NamespacedUsersController < ApplicationController
2
+ before_action :authenticate_namespaced_user!
3
+
4
+ def index
5
+ head :ok
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module Namespace
2
+ class NamespacedUser < ActiveRecord::Base
3
+ devise :database_authenticatable, :registerable,
4
+ :recoverable, :trackable, :validatable,
5
+ :token_authenticatable
6
+
7
+ has_many :authentication_tokens, as: :authenticatable
8
+ end
9
+ end
@@ -1,14 +1,15 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require File.expand_path('boot', __dir__)
2
2
 
3
3
  require "active_model/railtie"
4
4
  require "active_record/railtie"
5
5
  require "action_controller/railtie"
6
6
  require "action_view/railtie"
7
+ require "action_mailer/railtie"
7
8
 
8
9
  module RailsApp
9
10
  class Application < Rails::Application
10
11
  config.eager_load = true
11
- config.root = File.expand_path('../../.', __FILE__)
12
+ config.root = File.expand_path('..', __dir__)
12
13
  config.consider_all_requests_local = true
13
14
  config.active_record.sqlite3.represent_boolean_as_integer = true if config.active_record.sqlite3
14
15
  end
@@ -1,2 +1,2 @@
1
- ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../../Gemfile', __FILE__)
1
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../Gemfile', __dir__)
2
2
  require 'bundler/setup'
@@ -1,5 +1,5 @@
1
1
  # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
2
+ require File.expand_path('application', __dir__)
3
3
 
4
4
  # Initialize the Rails application.
5
5
  Rails.application.initialize!
@@ -1,6 +1,8 @@
1
1
  Rails.application.routes.draw do
2
2
  devise_for :users
3
3
  devise_for :admin_users
4
+ devise_for :namespaced_user, class_name: 'Namespace::NamespacedUser'
4
5
  resources :secrets, only: [:index], defaults: { format: 'json' }
5
6
  resources :long_secrets, only: [:index], defaults: { format: 'json' }
7
+ resources :namespaced_users, only: [:index], defaults: { format: 'json' }
6
8
  end
@@ -1,10 +1,4 @@
1
- migration_class = if Rails::VERSION::MAJOR > 4
2
- ActiveRecord::Migration[4.2]
3
- else
4
- ActiveRecord::Migration
5
- end
6
-
7
- class CreateTables < migration_class
1
+ class CreateTables < ActiveRecord::Migration[4.2]
8
2
  # rubocop:disable Metrics/AbcSize
9
3
  # rubocop:disable Metrics/MethodLength
10
4
  def change
@@ -61,6 +55,28 @@ class CreateTables < migration_class
61
55
  t.integer :expires_in, null: false, default: 0
62
56
  t.string :ip_address
63
57
  t.string :user_agent
58
+ t.string :metadata_attr1
59
+
60
+ t.timestamps null: false
61
+ end
62
+
63
+ create_table(:namespaced_users) do |t|
64
+ ## Database authenticatable
65
+ t.string :email, null: false, default: ""
66
+ t.string :encrypted_password, null: false, default: ""
67
+
68
+ ## Recoverable
69
+ t.string :reset_password_token
70
+ t.datetime :reset_password_sent_at
71
+
72
+ ## Trackable
73
+ t.integer :sign_in_count, default: 0, null: false
74
+ t.datetime :current_sign_in_at
75
+ t.datetime :last_sign_in_at
76
+ t.string :current_sign_in_ip
77
+ t.string :last_sign_in_ip
78
+
79
+ t.string :nick_name
64
80
 
65
81
  t.timestamps null: false
66
82
  end
@@ -0,0 +1,7 @@
1
+ class NamespacedUsersController < ApplicationController
2
+ before_action :authenticate_namespaced_user!
3
+
4
+ def index
5
+ head :ok
6
+ end
7
+ end
@@ -8,4 +8,5 @@ class AuthenticationToken
8
8
  field :ip_address, type: String
9
9
  field :user_agent, type: String
10
10
  field :expires_in, type: Integer, default: 0
11
+ field :metadata_attr1, type: String
11
12
  end
@@ -0,0 +1,4 @@
1
+ module Namespace
2
+ class NamespacedUser < User
3
+ end
4
+ end
@@ -5,7 +5,7 @@ class User
5
5
  :registerable,
6
6
  :recoverable,
7
7
  :trackable,
8
- #:validatable Triggers callback to will_save_change_to_email?, fails with mongoid
8
+ :validatable,
9
9
  :token_authenticatable
10
10
 
11
11
  has_many :authentication_tokens
@@ -1,4 +1,4 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require File.expand_path('boot', __dir__)
2
2
 
3
3
  require "active_model/railtie"
4
4
  require "active_job/railtie"
@@ -9,7 +9,7 @@ require "action_view/railtie"
9
9
  module RailsApp
10
10
  class Application < Rails::Application
11
11
  config.eager_load = true
12
- config.root = File.expand_path('../../.', __FILE__)
12
+ config.root = File.expand_path('..', __dir__)
13
13
  config.consider_all_requests_local = true
14
14
  end
15
15
  end
@@ -1,2 +1,2 @@
1
- ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../../Gemfile', __FILE__)
1
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../../../Gemfile', __dir__)
2
2
  require 'bundler/setup'
@@ -1,5 +1,5 @@
1
1
  # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
2
+ require File.expand_path('application', __dir__)
3
3
 
4
4
  # Initialize the Rails application.
5
5
  Rails.application.initialize!
@@ -1,6 +1,8 @@
1
1
  Rails.application.routes.draw do
2
2
  devise_for :users
3
3
  devise_for :admin_users
4
+ devise_for :namespaced_user, class_name: 'Namespace::NamespacedUser'
4
5
  resources :secrets, only: [:index], defaults: { format: 'json' }
5
6
  resources :long_secrets, only: [:index], defaults: { format: 'json' }
7
+ resources :namespaced_users, only: [:index], defaults: { format: 'json' }
6
8
  end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,6 @@
1
1
  require 'bundler/setup'
2
2
  require 'simplecov'
3
- require 'coveralls'
4
3
 
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
6
- SimpleCov::Formatter::HTMLFormatter,
7
- Coveralls::SimpleCov::Formatter
8
- ])
9
4
  SimpleCov.start do
10
5
  add_filter "/spec/"
11
6
  end
@@ -6,7 +6,7 @@ describe "Authentication using Tiddle strategy", type: :request do
6
6
  end
7
7
 
8
8
  it "allows to access endpoints which require authentication" do
9
- warningless_get(
9
+ get(
10
10
  secrets_path,
11
11
  headers: {
12
12
  "X-USER-EMAIL" => "test@example.com",
@@ -25,7 +25,7 @@ describe "Authentication using Tiddle strategy", type: :request do
25
25
 
26
26
  it "updates last_used_at field" do
27
27
  expect do
28
- warningless_get(
28
+ get(
29
29
  secrets_path,
30
30
  headers: {
31
31
  "X-USER-EMAIL" => "test@example.com",
@@ -43,7 +43,7 @@ describe "Authentication using Tiddle strategy", type: :request do
43
43
 
44
44
  it "does not update last_used_at field" do
45
45
  expect do
46
- warningless_get(
46
+ get(
47
47
  secrets_path,
48
48
  headers: {
49
49
  "X-USER-EMAIL" => "test@example.com",
@@ -57,7 +57,7 @@ describe "Authentication using Tiddle strategy", type: :request do
57
57
 
58
58
  context "when email contains uppercase letters" do
59
59
  it "converts email to lower case and authenticates user" do
60
- warningless_get(
60
+ get(
61
61
  secrets_path,
62
62
  headers: {
63
63
  "X-USER-EMAIL" => "TEST@example.com",
@@ -76,7 +76,7 @@ describe "Authentication using Tiddle strategy", type: :request do
76
76
  end
77
77
 
78
78
  it "does not allow to access endpoints which require authentication" do
79
- warningless_get(
79
+ get(
80
80
  secrets_path,
81
81
  headers: {
82
82
  "X-USER-EMAIL" => "wrong@example.com",
@@ -94,7 +94,7 @@ describe "Authentication using Tiddle strategy", type: :request do
94
94
  end
95
95
 
96
96
  it "does not allow to access endpoints which require authentication" do
97
- warningless_get(
97
+ get(
98
98
  secrets_path,
99
99
  headers: {
100
100
  "X-USER-EMAIL" => "test@example.com",
@@ -107,7 +107,7 @@ describe "Authentication using Tiddle strategy", type: :request do
107
107
 
108
108
  context "when no headers are passed" do
109
109
  it "does not allow to access endpoints which require authentication" do
110
- warningless_get secrets_path, headers: {}
110
+ get secrets_path, headers: {}
111
111
  expect(response.status).to eq 401
112
112
  end
113
113
  end
@@ -119,7 +119,7 @@ describe "Authentication using Tiddle strategy", type: :request do
119
119
  end
120
120
 
121
121
  it "allows to access endpoints which require authentication" do
122
- warningless_get(
122
+ get(
123
123
  long_secrets_path,
124
124
  headers: {
125
125
  "X-ADMIN-USER-EMAIL" => "test@example.com",
@@ -130,6 +130,27 @@ describe "Authentication using Tiddle strategy", type: :request do
130
130
  end
131
131
  end
132
132
 
133
+ context "when the model name is composed of a namespace" do
134
+ before do
135
+ @user = Namespace::NamespacedUser.create!(
136
+ email: "test@example.com",
137
+ password: "12345678"
138
+ )
139
+ @token = Tiddle.create_and_return_token(@user, FakeRequest.new)
140
+ end
141
+
142
+ it "allows to access endpoints which require authentication" do
143
+ get(
144
+ namespaced_users_path,
145
+ headers: {
146
+ "X-NAMESPACE--NAMESPACED-USER-EMAIL" => "test@example.com",
147
+ "X-NAMESPACE--NAMESPACED-USER-TOKEN" => @token
148
+ }
149
+ )
150
+ expect(response.status).to eq 200
151
+ end
152
+ end
153
+
133
154
  describe "using field other than email" do
134
155
  before do
135
156
  Devise.setup do |config|
@@ -152,7 +173,7 @@ describe "Authentication using Tiddle strategy", type: :request do
152
173
 
153
174
  it "allows to access endpoints which require authentication with valid \
154
175
  nick name and token" do
155
- warningless_get(
176
+ get(
156
177
  secrets_path,
157
178
  headers: { "X-USER-NICK-NAME" => "test", "X-USER-TOKEN" => @token }
158
179
  )
@@ -168,7 +189,7 @@ describe "Authentication using Tiddle strategy", type: :request do
168
189
 
169
190
  describe "token is not expired" do
170
191
  it "does allow to access endpoints which require authentication" do
171
- warningless_get(
192
+ get(
172
193
  secrets_path,
173
194
  headers: {
174
195
  "X-USER-EMAIL" => "test@example.com",
@@ -181,12 +202,12 @@ describe "Authentication using Tiddle strategy", type: :request do
181
202
 
182
203
  describe "token is expired" do
183
204
  before do
184
- token = @user.authentication_tokens.sort_by(&:id).last
205
+ token = @user.authentication_tokens.max_by(&:id)
185
206
  token.update_attribute(:last_used_at, 1.month.ago)
186
207
  end
187
208
 
188
209
  it "does not allow to access endpoints which require authentication" do
189
- warningless_get(
210
+ get(
190
211
  secrets_path,
191
212
  headers: {
192
213
  "X-USER-EMAIL" => "test@example.com",
@@ -23,18 +23,14 @@ module Backend
23
23
  # Do initial migration
24
24
  path = File.expand_path("../rails_app_active_record/db/migrate/", File.dirname(__FILE__))
25
25
 
26
- # rubocop:disable Performance/RegexpMatch
27
26
  if Gem::Requirement.new(">= 6.0.0") =~ Rails.gem_version
28
27
  ActiveRecord::MigrationContext.new(
29
28
  path,
30
29
  ActiveRecord::SchemaMigration
31
30
  ).migrate
32
- elsif Gem::Requirement.new(">= 5.2.0") =~ Rails.gem_version
33
- ActiveRecord::MigrationContext.new(path).migrate
34
31
  else
35
- ActiveRecord::Migrator.migrate(path)
32
+ ActiveRecord::MigrationContext.new(path).migrate
36
33
  end
37
- # rubocop:enable Performance/RegexpMatch
38
34
  end
39
35
  end
40
36
 
@@ -43,12 +39,11 @@ module Backend
43
39
  require 'mongoid'
44
40
  require 'devise/orm/mongoid'
45
41
  require 'rails_app_mongoid/config/environment'
46
- require 'database_cleaner'
42
+ require 'database_cleaner-mongoid'
47
43
  end
48
44
 
49
45
  def setup_database_cleaner
50
46
  DatabaseCleaner.allow_remote_database_url = true
51
- DatabaseCleaner[:mongoid].strategy = :truncation
52
47
  end
53
48
 
54
49
  def migrate!
@@ -9,7 +9,5 @@ class FakeRequest
9
9
  self.headers = headers
10
10
  end
11
11
 
12
- attr_accessor :remote_ip
13
- attr_accessor :user_agent
14
- attr_accessor :headers
12
+ attr_accessor :remote_ip, :user_agent, :headers
15
13
  end
data/spec/tiddle_spec.rb CHANGED
@@ -38,6 +38,11 @@ describe Tiddle do
38
38
  FakeRequest.new(user_agent: "Internet Explorer 4.0")
39
39
  expect(@user.authentication_tokens.last.user_agent).to eq "Internet Explorer 4.0"
40
40
  end
41
+
42
+ it "saves additional metadata" do
43
+ Tiddle.create_and_return_token @user, FakeRequest.new, metadata: { metadata_attr1: "abc" }
44
+ expect(@user.authentication_tokens.last.metadata_attr1).to eq "abc"
45
+ end
41
46
  end
42
47
 
43
48
  describe "find_token" do
data/tiddle.gemspec CHANGED
@@ -16,15 +16,14 @@ Gem::Specification.new do |spec|
16
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.required_ruby_version = '>= 2.4.0'
19
+ spec.required_ruby_version = '>= 2.7.0'
20
20
 
21
21
  spec.add_dependency "devise", ">= 4.0.0.rc1", "< 5"
22
- spec.add_dependency "activerecord", ">= 4.2.0"
23
- spec.add_development_dependency "rake", "~> 12.0"
22
+ spec.add_dependency "activerecord", ">= 5.2.0"
23
+ spec.add_development_dependency "rake"
24
24
  spec.add_development_dependency "rspec-rails"
25
- spec.add_development_dependency "appraisal"
26
- spec.add_development_dependency "coveralls"
27
25
  spec.add_development_dependency "simplecov"
28
26
  spec.add_development_dependency "rubocop"
29
- spec.add_development_dependency "database_cleaner"
27
+ spec.add_development_dependency "database_cleaner-active_record"
28
+ spec.add_development_dependency "database_cleaner-mongoid"
30
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiddle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Niedzielski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-18 00:00:00.000000000 Z
11
+ date: 2022-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: devise
@@ -36,30 +36,16 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: 4.2.0
39
+ version: 5.2.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: 4.2.0
46
+ version: 5.2.0
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '12.0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '12.0'
61
- - !ruby/object:Gem::Dependency
62
- name: rspec-rails
63
49
  requirement: !ruby/object:Gem::Requirement
64
50
  requirements:
65
51
  - - ">="
@@ -73,7 +59,7 @@ dependencies:
73
59
  - !ruby/object:Gem::Version
74
60
  version: '0'
75
61
  - !ruby/object:Gem::Dependency
76
- name: appraisal
62
+ name: rspec-rails
77
63
  requirement: !ruby/object:Gem::Requirement
78
64
  requirements:
79
65
  - - ">="
@@ -87,7 +73,7 @@ dependencies:
87
73
  - !ruby/object:Gem::Version
88
74
  version: '0'
89
75
  - !ruby/object:Gem::Dependency
90
- name: coveralls
76
+ name: simplecov
91
77
  requirement: !ruby/object:Gem::Requirement
92
78
  requirements:
93
79
  - - ">="
@@ -101,7 +87,7 @@ dependencies:
101
87
  - !ruby/object:Gem::Version
102
88
  version: '0'
103
89
  - !ruby/object:Gem::Dependency
104
- name: simplecov
90
+ name: rubocop
105
91
  requirement: !ruby/object:Gem::Requirement
106
92
  requirements:
107
93
  - - ">="
@@ -115,7 +101,7 @@ dependencies:
115
101
  - !ruby/object:Gem::Version
116
102
  version: '0'
117
103
  - !ruby/object:Gem::Dependency
118
- name: rubocop
104
+ name: database_cleaner-active_record
119
105
  requirement: !ruby/object:Gem::Requirement
120
106
  requirements:
121
107
  - - ">="
@@ -129,7 +115,7 @@ dependencies:
129
115
  - !ruby/object:Gem::Version
130
116
  version: '0'
131
117
  - !ruby/object:Gem::Dependency
132
- name: database_cleaner
118
+ name: database_cleaner-mongoid
133
119
  requirement: !ruby/object:Gem::Requirement
134
120
  requirements:
135
121
  - - ">="
@@ -149,21 +135,20 @@ executables: []
149
135
  extensions: []
150
136
  extra_rdoc_files: []
151
137
  files:
138
+ - ".github/workflows/ruby.yml"
152
139
  - ".gitignore"
153
140
  - ".rspec"
154
141
  - ".rubocop.yml"
155
- - ".travis.yml"
156
- - Appraisals
157
142
  - CHANGELOG.md
158
143
  - CONTRIBUTING.md
159
- - Gemfile
160
144
  - LICENSE.txt
161
145
  - README.md
162
146
  - Rakefile
163
147
  - config/locales/en.yml
164
- - gemfiles/rails4.2.gemfile
165
148
  - gemfiles/rails5.2.gemfile
166
149
  - gemfiles/rails6.0.gemfile
150
+ - gemfiles/rails6.1.gemfile
151
+ - gemfiles/rails7.0.gemfile
167
152
  - lib/tiddle.rb
168
153
  - lib/tiddle/model.rb
169
154
  - lib/tiddle/model_name.rb
@@ -173,9 +158,11 @@ files:
173
158
  - lib/tiddle/version.rb
174
159
  - spec/rails_app_active_record/app/controllers/application_controller.rb
175
160
  - spec/rails_app_active_record/app/controllers/long_secrets_controller.rb
161
+ - spec/rails_app_active_record/app/controllers/namespaced_users_controller.rb
176
162
  - spec/rails_app_active_record/app/controllers/secrets_controller.rb
177
163
  - spec/rails_app_active_record/app/models/admin_user.rb
178
164
  - spec/rails_app_active_record/app/models/authentication_token.rb
165
+ - spec/rails_app_active_record/app/models/namespace/namespaced_user.rb
179
166
  - spec/rails_app_active_record/app/models/user.rb
180
167
  - spec/rails_app_active_record/config/application.rb
181
168
  - spec/rails_app_active_record/config/boot.rb
@@ -185,9 +172,11 @@ files:
185
172
  - spec/rails_app_active_record/db/migrate/20150217000000_create_tables.rb
186
173
  - spec/rails_app_mongoid/app/controllers/application_controller.rb
187
174
  - spec/rails_app_mongoid/app/controllers/long_secrets_controller.rb
175
+ - spec/rails_app_mongoid/app/controllers/namespaced_users_controller.rb
188
176
  - spec/rails_app_mongoid/app/controllers/secrets_controller.rb
189
177
  - spec/rails_app_mongoid/app/models/admin_user.rb
190
178
  - spec/rails_app_mongoid/app/models/authentication_token.rb
179
+ - spec/rails_app_mongoid/app/models/namespace/namespaced_user.rb
191
180
  - spec/rails_app_mongoid/app/models/user.rb
192
181
  - spec/rails_app_mongoid/config/application.rb
193
182
  - spec/rails_app_mongoid/config/boot.rb
@@ -199,7 +188,6 @@ files:
199
188
  - spec/strategy_spec.rb
200
189
  - spec/support/backend.rb
201
190
  - spec/support/fake_request.rb
202
- - spec/support/warningless_get.rb
203
191
  - spec/tiddle_spec.rb
204
192
  - tiddle.gemspec
205
193
  homepage: ''
@@ -214,23 +202,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
214
202
  requirements:
215
203
  - - ">="
216
204
  - !ruby/object:Gem::Version
217
- version: 2.4.0
205
+ version: 2.7.0
218
206
  required_rubygems_version: !ruby/object:Gem::Requirement
219
207
  requirements:
220
208
  - - ">="
221
209
  - !ruby/object:Gem::Version
222
210
  version: '0'
223
211
  requirements: []
224
- rubygems_version: 3.1.2
212
+ rubygems_version: 3.1.6
225
213
  signing_key:
226
214
  specification_version: 4
227
215
  summary: Token authentication for Devise which supports multiple tokens per model
228
216
  test_files:
229
217
  - spec/rails_app_active_record/app/controllers/application_controller.rb
230
218
  - spec/rails_app_active_record/app/controllers/long_secrets_controller.rb
219
+ - spec/rails_app_active_record/app/controllers/namespaced_users_controller.rb
231
220
  - spec/rails_app_active_record/app/controllers/secrets_controller.rb
232
221
  - spec/rails_app_active_record/app/models/admin_user.rb
233
222
  - spec/rails_app_active_record/app/models/authentication_token.rb
223
+ - spec/rails_app_active_record/app/models/namespace/namespaced_user.rb
234
224
  - spec/rails_app_active_record/app/models/user.rb
235
225
  - spec/rails_app_active_record/config/application.rb
236
226
  - spec/rails_app_active_record/config/boot.rb
@@ -240,9 +230,11 @@ test_files:
240
230
  - spec/rails_app_active_record/db/migrate/20150217000000_create_tables.rb
241
231
  - spec/rails_app_mongoid/app/controllers/application_controller.rb
242
232
  - spec/rails_app_mongoid/app/controllers/long_secrets_controller.rb
233
+ - spec/rails_app_mongoid/app/controllers/namespaced_users_controller.rb
243
234
  - spec/rails_app_mongoid/app/controllers/secrets_controller.rb
244
235
  - spec/rails_app_mongoid/app/models/admin_user.rb
245
236
  - spec/rails_app_mongoid/app/models/authentication_token.rb
237
+ - spec/rails_app_mongoid/app/models/namespace/namespaced_user.rb
246
238
  - spec/rails_app_mongoid/app/models/user.rb
247
239
  - spec/rails_app_mongoid/config/application.rb
248
240
  - spec/rails_app_mongoid/config/boot.rb
@@ -254,5 +246,4 @@ test_files:
254
246
  - spec/strategy_spec.rb
255
247
  - spec/support/backend.rb
256
248
  - spec/support/fake_request.rb
257
- - spec/support/warningless_get.rb
258
249
  - spec/tiddle_spec.rb
data/.travis.yml DELETED
@@ -1,27 +0,0 @@
1
- language: ruby
2
- branches:
3
- only:
4
- - master
5
- before_install:
6
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
7
- - gem install bundler -v '< 2'
8
- services:
9
- - mongodb
10
- rvm:
11
- - "2.4.6"
12
- - "2.5.5"
13
- - "2.6.3"
14
- - "2.7.1"
15
- gemfile:
16
- - gemfiles/rails4.2.gemfile
17
- - gemfiles/rails5.2.gemfile
18
- - gemfiles/rails6.0.gemfile
19
- env:
20
- - BACKEND=mongoid
21
- - BACKEND=active_record
22
- jobs:
23
- exclude:
24
- - rvm: "2.4.6"
25
- gemfile: gemfiles/rails6.0.gemfile
26
- - rvm: "2.7.1"
27
- gemfile: gemfiles/rails4.2.gemfile
data/Appraisals DELETED
@@ -1,17 +0,0 @@
1
- appraise "rails4.2" do
2
- gem "rails", "~> 4.2.0"
3
- gem "mongoid", "~> 5"
4
- gem "sqlite3", "~> 1.3.13"
5
- end
6
-
7
- appraise "rails5.2" do
8
- gem "rails", "~> 5.2.1"
9
- gem "mongoid", "~> 6"
10
- gem "sqlite3", "~> 1.3.13"
11
- end
12
-
13
- appraise "rails6.0" do
14
- gem "rails", "~> 6.0.0"
15
- gem "mongoid", "~> 7"
16
- gem "sqlite3"
17
- end
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem "rubocop", "~> 0.52.0"
4
-
5
- # Specify your gem's dependencies in tiddle.gemspec
6
- gemspec
@@ -1,10 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "rubocop", "~> 0.52.0"
6
- gem "rails", "~> 4.2.0"
7
- gem "mongoid", "~> 5"
8
- gem "sqlite3", "~> 1.3.13"
9
-
10
- gemspec path: "../"
@@ -1,9 +0,0 @@
1
- def warningless_get(path, headers:)
2
- # rubocop:disable Performance/RegexpMatch
3
- if Gem::Requirement.new(">= 5") =~ Rails.gem_version
4
- get path, headers: headers
5
- else
6
- get path, {}, headers
7
- end
8
- # rubocop:enable Performance/RegexpMatch
9
- end