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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjAyNzE3NzFhNWE4YzUxNzllZDI5YmYxYWQ5MDc0OTE4ZDE3ZGE0ZA==
4
+ OTI2MDhjNWJiYTUwMDUwN2RjMjk3OTE4ODAwMWJiNDAxMGE1NDU5ZA==
5
5
  data.tar.gz: !binary |-
6
- MjFkYjg0NDUyYTg1NjcwNzE1YWM2MjRhM2ZjY2VjMTc4MTZlNGYyZg==
6
+ YzJkMjIwNTczMjgxMmM4ZjljYTMzYmVkNWI1ZmU5MmViZDViNGFiYw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTg3ODA2YmM4YTFmNjIzMDIyMzE3MmI1NzIwNzQ3ODk0YTQ3YTFhMTQ1OTNl
10
- NDY4ZWIxNWEwNzk1NzViNDUzYjU5MGE3NDZhMjdhZDdlYjc3MTYxNGQ1ZTcw
11
- M2E4ZjA0NzQ4NDZjYjMyZTU0NjdlYmNlODljMjUzODNlZjVkNWI=
9
+ NzQ5MGVhMTJiMmM0ZWM0NzUzNmFhNTYwYmU1ZGZlNWI5NTc1NmY5NTdjYjEw
10
+ MGM1ZmJjMWZhNjE1ZGRhYmZiMTdmMzU2OGQ4ODdiOWVhZGMxOWI2MzI4MTZh
11
+ ZjhlZjM1YWU0MWU4OWQ5NTU0YWRiYzg4MWExOTU5ZmUyY2NjOWU=
12
12
  data.tar.gz: !binary |-
13
- NzQ2ZjY3MjM5ZTI3MGMyMWEwYzE1YzA5MTdhMGE5YTg0YWUwMTIyNzkyODJh
14
- YjBmZGY3MzIyODJjN2E1NjgzMTg5ZWEzZDBiY2NjNTUwMDcxZWJlNzE2ZDMy
15
- ZTliZjc2ZTVkNGM0N2Q2ZWM3NTBhNTMzYTcyNGZjMzEyNjg4MTM=
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
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in devise-async-stretch.gemspec
4
4
  gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/README.md CHANGED
@@ -1,26 +1,8 @@
1
1
  # Devise::Async::Stretch
2
2
 
3
- TODO: Write a gem description
3
+ Move password stretching into a background job for fast user creation but while maintaining difficult to crack storage.
4
4
 
5
- ## Installation
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.1.0"
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
@@ -3,7 +3,7 @@ module Devise
3
3
  module Stretch
4
4
  module Backend
5
5
  class Base
6
- def self.enqueue(*args)
6
+ def self.enqueue_job(*args)
7
7
  raise NotImplementedError, "Any Devise::Async::Stretch::Backend subclass should implement `self.enqueue`."
8
8
  end
9
9
 
@@ -7,7 +7,7 @@ module Devise
7
7
 
8
8
  sidekiq_options queue: Devise::Async::Stretch.queue
9
9
 
10
- def self.enqueue(klass, id, password)
10
+ def self.enqueue_job(klass, id, password)
11
11
  perform_async(klass, id, password)
12
12
  end
13
13
  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
 
@@ -1,7 +1,7 @@
1
1
  module Devise
2
2
  module Async
3
3
  module Stretch
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -4,7 +4,7 @@ module Devise
4
4
  class Worker
5
5
 
6
6
  def self.enqueue(klass, id, password)
7
- backend_klass.enqueue(klass, id, password)
7
+ backend_klass.enqueue_job(klass, id, password)
8
8
  end
9
9
 
10
10
  private
@@ -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
@@ -14,7 +14,7 @@ module Devise
14
14
 
15
15
  test "an error is raised with the built in enqueue" do
16
16
  assert_raises NotImplementedError do
17
- Base.enqueue
17
+ Base.enqueue_job
18
18
  end
19
19
  end
20
20
 
@@ -14,7 +14,7 @@ module Devise
14
14
 
15
15
  test "the job is queued" do
16
16
  assert_difference 'Devise::Async::Stretch::Backend::Sidekiq.jobs.size' do
17
- Sidekiq.enqueue("User", @user.id, "password")
17
+ Sidekiq.enqueue_job("User", @user.id, "password")
18
18
  end
19
19
  end
20
20
 
@@ -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.serve_static_assets = true
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
@@ -1,3 +1,6 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+
1
4
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
5
  require "devise/async/stretch"
3
6
 
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.1
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: 2014-12-29 00:00:00.000000000 Z
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.1.0
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.1.0
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