stn-simple_token_authentication 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +674 -0
- data/README.md +270 -0
- data/Rakefile +61 -0
- data/doc/README.md +18 -0
- data/lib/simple_token_authentication.rb +58 -0
- data/lib/simple_token_authentication/acts_as_token_authenticatable.rb +49 -0
- data/lib/simple_token_authentication/acts_as_token_authentication_handler.rb +22 -0
- data/lib/simple_token_authentication/adapter.rb +7 -0
- data/lib/simple_token_authentication/adapters/active_record_adapter.rb +14 -0
- data/lib/simple_token_authentication/adapters/mongoid_adapter.rb +14 -0
- data/lib/simple_token_authentication/adapters/rails_adapter.rb +14 -0
- data/lib/simple_token_authentication/adapters/rails_api_adapter.rb +18 -0
- data/lib/simple_token_authentication/configuration.rb +45 -0
- data/lib/simple_token_authentication/entities_manager.rb +10 -0
- data/lib/simple_token_authentication/entity.rb +64 -0
- data/lib/simple_token_authentication/fallback_authentication_handler.rb +11 -0
- data/lib/simple_token_authentication/sign_in_handler.rb +19 -0
- data/lib/simple_token_authentication/token_authentication_handler.rb +149 -0
- data/lib/simple_token_authentication/token_comparator.rb +20 -0
- data/lib/simple_token_authentication/token_generator.rb +9 -0
- data/lib/simple_token_authentication/version.rb +3 -0
- data/lib/tasks/simple_token_authentication_tasks.rake +4 -0
- data/spec/configuration/action_controller_callbacks_options_spec.rb +53 -0
- data/spec/configuration/fallback_to_devise_option_spec.rb +128 -0
- data/spec/configuration/header_names_option_spec.rb +463 -0
- data/spec/configuration/sign_in_token_option_spec.rb +92 -0
- data/spec/lib/simple_token_authentication/acts_as_token_authenticatable_spec.rb +108 -0
- data/spec/lib/simple_token_authentication/acts_as_token_authentication_handler_spec.rb +127 -0
- data/spec/lib/simple_token_authentication/adapter_spec.rb +19 -0
- data/spec/lib/simple_token_authentication/adapters/active_record_adapter_spec.rb +21 -0
- data/spec/lib/simple_token_authentication/adapters/mongoid_adapter_spec.rb +21 -0
- data/spec/lib/simple_token_authentication/adapters/rails_adapter_spec.rb +21 -0
- data/spec/lib/simple_token_authentication/adapters/rails_api_adapter_spec.rb +43 -0
- data/spec/lib/simple_token_authentication/configuration_spec.rb +133 -0
- data/spec/lib/simple_token_authentication/entities_manager_spec.rb +67 -0
- data/spec/lib/simple_token_authentication/entity_spec.rb +190 -0
- data/spec/lib/simple_token_authentication/errors_spec.rb +8 -0
- data/spec/lib/simple_token_authentication/fallback_authentication_handler_spec.rb +24 -0
- data/spec/lib/simple_token_authentication/sign_in_handler_spec.rb +43 -0
- data/spec/lib/simple_token_authentication/token_authentication_handler_spec.rb +351 -0
- data/spec/lib/simple_token_authentication/token_comparator_spec.rb +19 -0
- data/spec/lib/simple_token_authentication/token_generator_spec.rb +19 -0
- data/spec/lib/simple_token_authentication_spec.rb +181 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/dummy_classes_helper.rb +80 -0
- data/spec/support/spec_for_adapter.rb +10 -0
- data/spec/support/spec_for_authentication_handler_interface.rb +8 -0
- data/spec/support/spec_for_configuration_option_interface.rb +28 -0
- data/spec/support/spec_for_entities_manager_interface.rb +8 -0
- data/spec/support/spec_for_sign_in_handler_interface.rb +8 -0
- data/spec/support/spec_for_token_comparator_interface.rb +8 -0
- data/spec/support/spec_for_token_generator_interface.rb +8 -0
- data/spec/support/specs_for_token_authentication_handler_interface.rb +8 -0
- metadata +250 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'action_controller'
|
5
|
+
require 'active_record'
|
6
|
+
require 'mongoid'
|
7
|
+
require 'active_support'
|
8
|
+
|
9
|
+
require 'simple_token_authentication'
|
10
|
+
|
11
|
+
Dir["./spec/support/**/*.rb"].sort.each { |f| require f; puts f }
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.raise_errors_for_deprecations!
|
15
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# Create dummy classes to test modules with RSpec
|
2
|
+
#
|
3
|
+
# Usage:
|
4
|
+
#
|
5
|
+
# describe SimpleTokenAuthentication::ModuleUnderTest do
|
6
|
+
#
|
7
|
+
# after(:each) do
|
8
|
+
# ensure_examples_independence
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# before(:each) do
|
12
|
+
# define_test_subjects_for_inclusion_of(SimpleTokenAuthentication::ModuleUnderTest)
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # spec examples...
|
16
|
+
#
|
17
|
+
# end
|
18
|
+
##
|
19
|
+
|
20
|
+
|
21
|
+
# Returns a dummy class which includes the module under test.
|
22
|
+
def define_dummy_class_which_includes(module_under_test)
|
23
|
+
unless defined? SimpleTokenAuthentication::SomeClass
|
24
|
+
SimpleTokenAuthentication.const_set(:SomeClass, Class.new)
|
25
|
+
end
|
26
|
+
SimpleTokenAuthentication::SomeClass.send :include, module_under_test
|
27
|
+
SimpleTokenAuthentication::SomeClass
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns a dummy class which extends the module under test.
|
31
|
+
def define_dummy_class_which_extends(module_under_test)
|
32
|
+
unless defined? SimpleTokenAuthentication::SomeClass
|
33
|
+
SimpleTokenAuthentication.const_set(:SomeClass, Class.new)
|
34
|
+
end
|
35
|
+
SimpleTokenAuthentication::SomeClass.send :extend, module_under_test
|
36
|
+
SimpleTokenAuthentication::SomeClass
|
37
|
+
end
|
38
|
+
|
39
|
+
# Returns a dummy class which inherits from parent_class.
|
40
|
+
def define_dummy_class_child_of(parent_class)
|
41
|
+
unless defined? SimpleTokenAuthentication::SomeChildClass
|
42
|
+
SimpleTokenAuthentication.const_set(:SomeChildClass, Class.new(parent_class))
|
43
|
+
end
|
44
|
+
SimpleTokenAuthentication::SomeChildClass
|
45
|
+
end
|
46
|
+
|
47
|
+
def ensure_examples_independence
|
48
|
+
SimpleTokenAuthentication.send(:remove_const, :SomeClass)
|
49
|
+
SimpleTokenAuthentication.send(:remove_const, :SomeChildClass)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Must be used in coordination with ensure_examples_independence
|
53
|
+
def define_test_subjects_for_inclusion_of(module_under_test)
|
54
|
+
klass = define_dummy_class_which_includes(module_under_test)
|
55
|
+
child_klass = define_dummy_class_child_of(klass)
|
56
|
+
|
57
|
+
# all specs must apply to classes which include the module and their children
|
58
|
+
@subjects = [klass, child_klass]
|
59
|
+
end
|
60
|
+
|
61
|
+
# Must be used in coordination with ensure_examples_independence
|
62
|
+
def define_test_subjects_for_extension_of(module_under_test)
|
63
|
+
klass = define_dummy_class_which_extends(module_under_test)
|
64
|
+
child_klass = define_dummy_class_child_of(klass)
|
65
|
+
|
66
|
+
# all specs must apply to classes which extend the module and their children
|
67
|
+
@subjects = [klass, child_klass]
|
68
|
+
end
|
69
|
+
|
70
|
+
def double_user_model
|
71
|
+
user = double()
|
72
|
+
stub_const('User', user)
|
73
|
+
allow(user).to receive(:name).and_return('User')
|
74
|
+
end
|
75
|
+
|
76
|
+
def double_super_admin_model
|
77
|
+
super_admin = double()
|
78
|
+
stub_const('SuperAdmin', super_admin)
|
79
|
+
allow(super_admin).to receive(:name).and_return('SuperAdmin')
|
80
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
RSpec.shared_examples 'a configuration option' do |option_name|
|
2
|
+
|
3
|
+
before(:each) do
|
4
|
+
@get_option = option_name.to_sym # e.g. :sign_in_token
|
5
|
+
@set_option = option_name.+('=').to_sym # e.g. :sign_in_token=
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'is accessible', private: true do
|
9
|
+
expect(@subject).to respond_to @get_option
|
10
|
+
expect(@subject).to respond_to @set_option
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'once set' do
|
14
|
+
|
15
|
+
before(:each) do
|
16
|
+
@_original_value = @subject.send @get_option
|
17
|
+
@subject.send @set_option, 'custom header'
|
18
|
+
end
|
19
|
+
|
20
|
+
after(:each) do
|
21
|
+
@subject.send @set_option, @_original_value
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'can be retrieved', private: true do
|
25
|
+
expect(@subject.send @get_option).to eq 'custom header'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
RSpec.shared_examples 'a token authentication handler' do
|
2
|
+
|
3
|
+
let(:token_authentication_handler) { described_class }
|
4
|
+
|
5
|
+
it 'responds to :handle_token_authentication_for', private: true do
|
6
|
+
expect(token_authentication_handler).to respond_to :handle_token_authentication_for
|
7
|
+
end
|
8
|
+
end
|
metadata
ADDED
@@ -0,0 +1,250 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stn-simple_token_authentication
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.7.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gonzalo Bulnes Guilpain
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionmailer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.2.6
|
20
|
+
- - <
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.6
|
30
|
+
- - <
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: actionpack
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.2.6
|
40
|
+
- - <
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '5'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 3.2.6
|
50
|
+
- - <
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '5'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: devise
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '3.2'
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '3.2'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: rspec
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '3.0'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ~>
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '3.0'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: inch
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0.4'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0.4'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: activerecord
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 3.2.6
|
102
|
+
- - <
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '5'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 3.2.6
|
112
|
+
- - <
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '5'
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: mongoid
|
117
|
+
requirement: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 3.1.0
|
122
|
+
- - <
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5'
|
125
|
+
type: :development
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.1.0
|
132
|
+
- - <
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '5'
|
135
|
+
description:
|
136
|
+
email:
|
137
|
+
- gon.bulnes@gmail.com
|
138
|
+
executables: []
|
139
|
+
extensions: []
|
140
|
+
extra_rdoc_files: []
|
141
|
+
files:
|
142
|
+
- doc/README.md
|
143
|
+
- lib/simple_token_authentication/acts_as_token_authenticatable.rb
|
144
|
+
- lib/simple_token_authentication/acts_as_token_authentication_handler.rb
|
145
|
+
- lib/simple_token_authentication/adapter.rb
|
146
|
+
- lib/simple_token_authentication/adapters/active_record_adapter.rb
|
147
|
+
- lib/simple_token_authentication/adapters/mongoid_adapter.rb
|
148
|
+
- lib/simple_token_authentication/adapters/rails_adapter.rb
|
149
|
+
- lib/simple_token_authentication/adapters/rails_api_adapter.rb
|
150
|
+
- lib/simple_token_authentication/configuration.rb
|
151
|
+
- lib/simple_token_authentication/entities_manager.rb
|
152
|
+
- lib/simple_token_authentication/entity.rb
|
153
|
+
- lib/simple_token_authentication/fallback_authentication_handler.rb
|
154
|
+
- lib/simple_token_authentication/sign_in_handler.rb
|
155
|
+
- lib/simple_token_authentication/token_authentication_handler.rb
|
156
|
+
- lib/simple_token_authentication/token_comparator.rb
|
157
|
+
- lib/simple_token_authentication/token_generator.rb
|
158
|
+
- lib/simple_token_authentication/version.rb
|
159
|
+
- lib/simple_token_authentication.rb
|
160
|
+
- lib/tasks/simple_token_authentication_tasks.rake
|
161
|
+
- LICENSE
|
162
|
+
- Rakefile
|
163
|
+
- README.md
|
164
|
+
- spec/configuration/action_controller_callbacks_options_spec.rb
|
165
|
+
- spec/configuration/fallback_to_devise_option_spec.rb
|
166
|
+
- spec/configuration/header_names_option_spec.rb
|
167
|
+
- spec/configuration/sign_in_token_option_spec.rb
|
168
|
+
- spec/lib/simple_token_authentication/acts_as_token_authenticatable_spec.rb
|
169
|
+
- spec/lib/simple_token_authentication/acts_as_token_authentication_handler_spec.rb
|
170
|
+
- spec/lib/simple_token_authentication/adapter_spec.rb
|
171
|
+
- spec/lib/simple_token_authentication/adapters/active_record_adapter_spec.rb
|
172
|
+
- spec/lib/simple_token_authentication/adapters/mongoid_adapter_spec.rb
|
173
|
+
- spec/lib/simple_token_authentication/adapters/rails_adapter_spec.rb
|
174
|
+
- spec/lib/simple_token_authentication/adapters/rails_api_adapter_spec.rb
|
175
|
+
- spec/lib/simple_token_authentication/configuration_spec.rb
|
176
|
+
- spec/lib/simple_token_authentication/entities_manager_spec.rb
|
177
|
+
- spec/lib/simple_token_authentication/entity_spec.rb
|
178
|
+
- spec/lib/simple_token_authentication/errors_spec.rb
|
179
|
+
- spec/lib/simple_token_authentication/fallback_authentication_handler_spec.rb
|
180
|
+
- spec/lib/simple_token_authentication/sign_in_handler_spec.rb
|
181
|
+
- spec/lib/simple_token_authentication/token_authentication_handler_spec.rb
|
182
|
+
- spec/lib/simple_token_authentication/token_comparator_spec.rb
|
183
|
+
- spec/lib/simple_token_authentication/token_generator_spec.rb
|
184
|
+
- spec/lib/simple_token_authentication_spec.rb
|
185
|
+
- spec/spec_helper.rb
|
186
|
+
- spec/support/dummy_classes_helper.rb
|
187
|
+
- spec/support/spec_for_adapter.rb
|
188
|
+
- spec/support/spec_for_authentication_handler_interface.rb
|
189
|
+
- spec/support/spec_for_configuration_option_interface.rb
|
190
|
+
- spec/support/spec_for_entities_manager_interface.rb
|
191
|
+
- spec/support/spec_for_sign_in_handler_interface.rb
|
192
|
+
- spec/support/spec_for_token_comparator_interface.rb
|
193
|
+
- spec/support/spec_for_token_generator_interface.rb
|
194
|
+
- spec/support/specs_for_token_authentication_handler_interface.rb
|
195
|
+
homepage: https://github.com/gonzalo-bulnes/simple_token_authentication
|
196
|
+
licenses:
|
197
|
+
- GPLv3
|
198
|
+
metadata: {}
|
199
|
+
post_install_message:
|
200
|
+
rdoc_options: []
|
201
|
+
require_paths:
|
202
|
+
- lib
|
203
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - '>='
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - '>='
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
requirements: []
|
214
|
+
rubyforge_project:
|
215
|
+
rubygems_version: 2.0.14
|
216
|
+
signing_key:
|
217
|
+
specification_version: 4
|
218
|
+
summary: Simple (but safe) token authentication for Rails apps or API with Devise.
|
219
|
+
test_files:
|
220
|
+
- spec/configuration/action_controller_callbacks_options_spec.rb
|
221
|
+
- spec/configuration/fallback_to_devise_option_spec.rb
|
222
|
+
- spec/configuration/header_names_option_spec.rb
|
223
|
+
- spec/configuration/sign_in_token_option_spec.rb
|
224
|
+
- spec/lib/simple_token_authentication/acts_as_token_authenticatable_spec.rb
|
225
|
+
- spec/lib/simple_token_authentication/acts_as_token_authentication_handler_spec.rb
|
226
|
+
- spec/lib/simple_token_authentication/adapter_spec.rb
|
227
|
+
- spec/lib/simple_token_authentication/adapters/active_record_adapter_spec.rb
|
228
|
+
- spec/lib/simple_token_authentication/adapters/mongoid_adapter_spec.rb
|
229
|
+
- spec/lib/simple_token_authentication/adapters/rails_adapter_spec.rb
|
230
|
+
- spec/lib/simple_token_authentication/adapters/rails_api_adapter_spec.rb
|
231
|
+
- spec/lib/simple_token_authentication/configuration_spec.rb
|
232
|
+
- spec/lib/simple_token_authentication/entities_manager_spec.rb
|
233
|
+
- spec/lib/simple_token_authentication/entity_spec.rb
|
234
|
+
- spec/lib/simple_token_authentication/errors_spec.rb
|
235
|
+
- spec/lib/simple_token_authentication/fallback_authentication_handler_spec.rb
|
236
|
+
- spec/lib/simple_token_authentication/sign_in_handler_spec.rb
|
237
|
+
- spec/lib/simple_token_authentication/token_authentication_handler_spec.rb
|
238
|
+
- spec/lib/simple_token_authentication/token_comparator_spec.rb
|
239
|
+
- spec/lib/simple_token_authentication/token_generator_spec.rb
|
240
|
+
- spec/lib/simple_token_authentication_spec.rb
|
241
|
+
- spec/spec_helper.rb
|
242
|
+
- spec/support/dummy_classes_helper.rb
|
243
|
+
- spec/support/spec_for_adapter.rb
|
244
|
+
- spec/support/spec_for_authentication_handler_interface.rb
|
245
|
+
- spec/support/spec_for_configuration_option_interface.rb
|
246
|
+
- spec/support/spec_for_entities_manager_interface.rb
|
247
|
+
- spec/support/spec_for_sign_in_handler_interface.rb
|
248
|
+
- spec/support/spec_for_token_comparator_interface.rb
|
249
|
+
- spec/support/spec_for_token_generator_interface.rb
|
250
|
+
- spec/support/specs_for_token_authentication_handler_interface.rb
|