devise-async-stretch 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/README.md +2 -20
- data/devise-async-stretch.gemspec +2 -1
- data/lib/devise/async/stretch/backend/active_job.rb +23 -0
- data/lib/devise/async/stretch/backend/base.rb +1 -1
- data/lib/devise/async/stretch/backend/sidekiq.rb +1 -1
- data/lib/devise/async/stretch/model.rb +1 -1
- data/lib/devise/async/stretch/version.rb +1 -1
- data/lib/devise/async/stretch/worker.rb +1 -1
- data/lib/devise/async/stretch.rb +7 -0
- data/test/devise/async/stretch/backend/active_job_test.rb +50 -0
- data/test/devise/async/stretch/backend/base_test.rb +1 -1
- data/test/devise/async/stretch/backend/sidekiq_test.rb +1 -1
- data/test/rails_app/config/environments/test.rb +6 -1
- data/test/test_helper.rb +3 -0
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTI2MDhjNWJiYTUwMDUwN2RjMjk3OTE4ODAwMWJiNDAxMGE1NDU5ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzJkMjIwNTczMjgxMmM4ZjljYTMzYmVkNWI1ZmU5MmViZDViNGFiYw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzQ5MGVhMTJiMmM0ZWM0NzUzNmFhNTYwYmU1ZGZlNWI5NTc1NmY5NTdjYjEw
|
10
|
+
MGM1ZmJjMWZhNjE1ZGRhYmZiMTdmMzU2OGQ4ODdiOWVhZGMxOWI2MzI4MTZh
|
11
|
+
ZjhlZjM1YWU0MWU4OWQ5NTU0YWRiYzg4MWExOTU5ZmUyY2NjOWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTVhZTc0YmUyNjIxM2E3ZTBlMDgwMzE4OTQ0YTQ4NjNmYTJmOTM1YTY3NDA0
|
14
|
+
ZDk4YzZmZjRkNWVlYTJmNTljODFkZGMxYjYzYTk4MWNmODM1NTdjZmRlNzYy
|
15
|
+
M2ZlMGJmNDUwNmFjNzE0NGE4OGU0MmRhOGNjZTFjNDI4YzQ0YTA=
|
data/.travis.yml
CHANGED
@@ -7,3 +7,6 @@ deploy:
|
|
7
7
|
provider: rubygems
|
8
8
|
api_key:
|
9
9
|
secure: F1Drh/pkUEDBvn0l6ZpFJeCeJk0FGReu98Ce3PMiIHjHngGsC3xDOTbkQ7+TUQHlfc0g3Hpc4pYmHxL3w/6TJwbx9csRX0Np4yaNfJZJdHR8uzAi7mpY32APXeLCJkV5En3h1B/G1V3qQ+AhH0Ez6nlOiSEhocJ+MVq9jFXagM4=
|
10
|
+
addons:
|
11
|
+
code_climate:
|
12
|
+
repo_token: e1fe9dfcd049fee242692f3589fef93579fe012c3874f31ae2afc82013a194b0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,26 +1,8 @@
|
|
1
1
|
# Devise::Async::Stretch
|
2
2
|
|
3
|
-
|
3
|
+
Move password stretching into a background job for fast user creation but while maintaining difficult to crack storage.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'devise-async-stretch'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install devise-async-stretch
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
TODO: Write usage instructions here
|
5
|
+
Who, why, and how? See the [website](http://devise-async-stretch.onsimplybuilt.com/).
|
24
6
|
|
25
7
|
## Contributing
|
26
8
|
|
@@ -22,7 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
-
spec.add_development_dependency "rails", "~> 4.
|
25
|
+
spec.add_development_dependency "rails", "~> 4.2.0"
|
26
|
+
spec.add_development_dependency "activejob"
|
26
27
|
spec.add_development_dependency "mocha", "~> 0.11"
|
27
28
|
spec.add_development_dependency "sqlite3"
|
28
29
|
spec.add_development_dependency "sidekiq"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Devise
|
2
|
+
module Async
|
3
|
+
module Stretch
|
4
|
+
module Backend
|
5
|
+
class ActiveJob < Base
|
6
|
+
class Job < ::ActiveJob::Base
|
7
|
+
queue_as Devise::Async::Stretch.queue
|
8
|
+
|
9
|
+
def perform(resource, password)
|
10
|
+
encrypted_password = resource.bcrypt(password, resource.class.stretches)
|
11
|
+
resource.update(encrypted_password: encrypted_password)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.enqueue_job(klass, id, password)
|
16
|
+
resource = klass.constantize.to_adapter.get!(id)
|
17
|
+
Job.perform_later(resource, password)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -25,7 +25,7 @@ module Devise
|
|
25
25
|
protected
|
26
26
|
|
27
27
|
def enqueue_stretch_worker
|
28
|
-
Devise::Async::Stretch::Worker.enqueue(self.class, id, @password) unless @password.nil?
|
28
|
+
Devise::Async::Stretch::Worker.enqueue(self.class.name, id, @password) unless @password.nil?
|
29
29
|
@password = nil
|
30
30
|
end
|
31
31
|
|
data/lib/devise/async/stretch.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# Copyright (c) 2014 Daniel Westendorf
|
2
|
+
#
|
3
|
+
# Much credit and thanks goes to Marcelo Silveira's wonderfull devise-async gem
|
4
|
+
# https://github.com/mhfs/devise-async for inspiration on the backend
|
5
|
+
# queuing support.
|
6
|
+
|
1
7
|
require "active_support/dependencies"
|
2
8
|
require "devise"
|
3
9
|
require "devise/async/stretch/version"
|
@@ -13,6 +19,7 @@ module Devise
|
|
13
19
|
module Backend
|
14
20
|
autoload :Base, "devise/async/stretch/backend/base"
|
15
21
|
autoload :Sidekiq, "devise/async/stretch/backend/sidekiq"
|
22
|
+
autoload :ActiveJob, "devise/async/stretch/backend/active_job"
|
16
23
|
end
|
17
24
|
|
18
25
|
# Defines the queue backend to be used. Sidekiq by default.
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
# require 'active_job/test_helper'
|
3
|
+
|
4
|
+
module Devise
|
5
|
+
module Async
|
6
|
+
module Stretch
|
7
|
+
module Backend
|
8
|
+
class ActiveJobTest < ActiveSupport::TestCase
|
9
|
+
include ::ActiveJob::TestHelper
|
10
|
+
|
11
|
+
setup do
|
12
|
+
@user = users(:bob)
|
13
|
+
Devise::Async::Stretch.enabled = true
|
14
|
+
Devise::Async::Stretch.backend = :active_job
|
15
|
+
|
16
|
+
clear_enqueued_jobs
|
17
|
+
end
|
18
|
+
|
19
|
+
test "the job is queued" do
|
20
|
+
Rails.application.config.active_job.queue_adapter = :sidekiq
|
21
|
+
|
22
|
+
ActiveJob.enqueue_job("User", @user.id, 'password')
|
23
|
+
assert_enqueued_jobs 1
|
24
|
+
end
|
25
|
+
|
26
|
+
test "the password gets updated when peformed" do
|
27
|
+
perform_enqueued_jobs do
|
28
|
+
ActiveJob.enqueue_job("User", @user.id, 'password')
|
29
|
+
end
|
30
|
+
assert_not_empty @user.reload.encrypted_password
|
31
|
+
end
|
32
|
+
|
33
|
+
test "the stretch_mark gets updated" do
|
34
|
+
User.stretches = 2
|
35
|
+
|
36
|
+
user = User.new(email: 'ed@example.com', password: 'password1')
|
37
|
+
encrypted_password = user.encrypted_password
|
38
|
+
|
39
|
+
perform_enqueued_jobs do
|
40
|
+
user.save # Should trigger the ActiveJob job
|
41
|
+
end
|
42
|
+
|
43
|
+
refute_equal encrypted_password, user.reload.encrypted_password
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -13,7 +13,7 @@ Rails.application.configure do
|
|
13
13
|
config.eager_load = false
|
14
14
|
|
15
15
|
# Configure static asset server for tests with Cache-Control for performance.
|
16
|
-
config.
|
16
|
+
config.serve_static_files = true
|
17
17
|
config.static_cache_control = 'public, max-age=3600'
|
18
18
|
|
19
19
|
# Show full error reports and disable caching.
|
@@ -34,6 +34,11 @@ Rails.application.configure do
|
|
34
34
|
# Print deprecation notices to the stderr.
|
35
35
|
config.active_support.deprecation = :stderr
|
36
36
|
|
37
|
+
config.active_support.test_order = :random
|
38
|
+
|
39
|
+
# Active Job config
|
40
|
+
config.active_job.queue_adapter = :sidekiq
|
41
|
+
|
37
42
|
# Raises error for missing translations
|
38
43
|
# config.action_view.raise_on_missing_translations = true
|
39
44
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise-async-stretch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Westendorf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -58,14 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 4.
|
61
|
+
version: 4.2.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 4.
|
68
|
+
version: 4.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activejob
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: mocha
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,6 +139,7 @@ files:
|
|
125
139
|
- devise-async-stretch.gemspec
|
126
140
|
- lib/devise/async/stretch.rb
|
127
141
|
- lib/devise/async/stretch/backend.rb
|
142
|
+
- lib/devise/async/stretch/backend/active_job.rb
|
128
143
|
- lib/devise/async/stretch/backend/base.rb
|
129
144
|
- lib/devise/async/stretch/backend/sidekiq.rb
|
130
145
|
- lib/devise/async/stretch/model.rb
|
@@ -133,6 +148,7 @@ files:
|
|
133
148
|
- lib/generators/devise/async/stretch/install_generator.rb
|
134
149
|
- lib/generators/templates/devise_async_stretch.rb
|
135
150
|
- log/test.log
|
151
|
+
- test/devise/async/stretch/backend/active_job_test.rb
|
136
152
|
- test/devise/async/stretch/backend/base_test.rb
|
137
153
|
- test/devise/async/stretch/backend/sidekiq_test.rb
|
138
154
|
- test/devise/async/stretch/backend_test.rb
|
@@ -227,6 +243,7 @@ signing_key:
|
|
227
243
|
specification_version: 4
|
228
244
|
summary: Move password stretching into a background job for fast user creation.
|
229
245
|
test_files:
|
246
|
+
- test/devise/async/stretch/backend/active_job_test.rb
|
230
247
|
- test/devise/async/stretch/backend/base_test.rb
|
231
248
|
- test/devise/async/stretch/backend/sidekiq_test.rb
|
232
249
|
- test/devise/async/stretch/backend_test.rb
|