devise-drupal 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog.md ADDED
@@ -0,0 +1,4 @@
1
+ ## Changelog
2
+
3
+ ### 0.0.1
4
+ * Initial version
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2012-2014 Plataformatec (opensource@plataformatec.com.br)
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Devise Drupal
2
+
3
+ [![Build Status](https://travis-ci.org/jerbob92/devise-drupal.png?branch=master)](https://travis-ci.org/jerbob92/devise-drupal)
4
+
5
+ Drupal Hash implementation for Devise Encryptable.
6
+
7
+ ## Usage
8
+
9
+ Add it to your Gemfile
10
+
11
+ ```ruby
12
+ gem "devise-drupal"
13
+ ```
14
+
15
+ Follow the device-encryptable readme.
16
+
17
+ Add the `password_salt` methods to your model:
18
+
19
+ ```ruby
20
+ class User < ActiveRecord::Base
21
+ def password_salt
22
+ 'no salt'
23
+ end
24
+
25
+ def password_salt=(new_salt)
26
+ end
27
+ end
28
+ ```
29
+
30
+ Add the encryptor to your initializor
31
+
32
+ ```
33
+ # This on top of your file:
34
+ require Rails.root.join('lib', 'devise', 'encryptable', 'encryptors', 'drupal_hash')
35
+
36
+ # This inside your "Devise.setup do |config|"
37
+ config.encryptor = :drupal_hash
38
+ ```
39
+
40
+ Beware: updating your encryptor on a database will make the current passwords unusable!
41
+
42
+ And you're ready to go!
43
+
44
+ ## Contributing
45
+
46
+ * Fork it
47
+ * Write your changes
48
+ * Commit
49
+ * Send a pull request
50
+
51
+ ## License
52
+
53
+ Apache License version 2. Copyright 2012-2014 .VDMi/ http://www.vdmi.nl
54
+
@@ -0,0 +1,151 @@
1
+ module Devise
2
+ module Encryptable
3
+ module Encryptors
4
+ class DrupalHash < Base
5
+ DRUPAL_HASH_COUNT = 15
6
+ DRUPAL_MIN_HASH_COUNT = 7
7
+ DRUPAL_MAX_HASH_COUNT = 30
8
+ DRUPAL_HASH_LENGTH = 55
9
+ ITOA64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
10
+
11
+ HASH = Digest::SHA2.new(512)
12
+
13
+ def self.compare(hashed_password, password, stretches, salt, pepper)
14
+ return false if password.nil? or hashed_password.nil?
15
+
16
+ setting = hashed_password[0..11]
17
+ if setting[0] != '$' or setting[2] != '$'
18
+ # Wrong hash format
19
+ return false
20
+ end
21
+
22
+ count_log2 = ITOA64.index(setting[3])
23
+
24
+ if count_log2 < DRUPAL_MIN_HASH_COUNT or count_log2 > DRUPAL_MAX_HASH_COUNT
25
+ return false
26
+ end
27
+
28
+ salt = setting[4..4+7]
29
+
30
+ if salt.length != 8
31
+ return false
32
+ end
33
+
34
+ count = 2 ** count_log2
35
+
36
+ pass_hash = HASH.digest(salt + password)
37
+
38
+ 1.upto(count) do |i|
39
+ pass_hash = HASH.digest(pass_hash + password)
40
+ end
41
+
42
+ hash_length = pass_hash.length
43
+
44
+ output = setting + self._password_base64_encode(pass_hash, hash_length)
45
+
46
+ if output.length != 98
47
+ return false
48
+ end
49
+
50
+ return output[0..(DRUPAL_HASH_LENGTH-1)] == hashed_password
51
+ end
52
+
53
+ def self.digest(password, stretches, salt, pepper)
54
+ count_log2 = stretches
55
+ if stretches.nil?
56
+ count_log2 = DRUPAL_HASH_COUNT
57
+ end
58
+ return self._password_crypt(password, self._password_generate_salt(count_log2))
59
+ end
60
+
61
+ def self._password_crypt(password, hashed_password)
62
+ setting = hashed_password[0..11]
63
+ if setting[0] != '$' or setting[2] != '$'
64
+ # Wrong hash format
65
+ return false
66
+ end
67
+
68
+ count_log2 = ITOA64.index(setting[3])
69
+
70
+ if count_log2 < DRUPAL_MIN_HASH_COUNT or count_log2 > DRUPAL_MAX_HASH_COUNT
71
+ return false
72
+ end
73
+
74
+ salt = setting[4..4+7]
75
+
76
+ if salt.length != 8
77
+ return false
78
+ end
79
+
80
+ count = 2 ** count_log2
81
+
82
+ pass_hash = HASH.digest(salt + password)
83
+
84
+ 1.upto(count) do |i|
85
+ pass_hash = HASH.digest(pass_hash + password)
86
+ end
87
+
88
+ hash_length = pass_hash.length
89
+
90
+ output = setting + self._password_base64_encode(pass_hash, hash_length)
91
+
92
+ if output.length != 98
93
+ return false
94
+ end
95
+
96
+ return output[0..(DRUPAL_HASH_LENGTH-1)]
97
+ end
98
+
99
+ def self._password_generate_salt(count_log2)
100
+ output = '$S$'
101
+ output = output + ITOA64[count_log2];
102
+ prng = Random.new(1234 + count_log2)
103
+ output = output + self._password_base64_encode(prng.bytes(6), 6)
104
+ end
105
+
106
+ def self._password_base64_encode(to_encode, count)
107
+ output = ''
108
+ i = 0
109
+ while true
110
+ value = (to_encode[i]).ord
111
+
112
+ i += 1
113
+
114
+ output = output + ITOA64[value & 0x3f]
115
+ if i < count
116
+ value |= (to_encode[i].ord) << 8
117
+ end
118
+
119
+ output = output + ITOA64[(value >> 6) & 0x3f]
120
+
121
+ if i >= count
122
+ break
123
+ end
124
+
125
+ i += 1
126
+
127
+ if i < count
128
+ value |= (to_encode[i].ord) << 16
129
+ end
130
+
131
+ output = output + ITOA64[(value >> 12) & 0x3f]
132
+
133
+ if i >= count
134
+ break
135
+ end
136
+
137
+ i += 1
138
+
139
+ output = output + ITOA64[(value >> 18) & 0x3f]
140
+
141
+ if i >= count
142
+ break
143
+ end
144
+
145
+ end
146
+ return output
147
+ end
148
+ end
149
+ end
150
+ end
151
+ end
@@ -0,0 +1 @@
1
+ require "devise/encryptable/encryptors/drupal_hash"
@@ -0,0 +1,18 @@
1
+ require "test_helper"
2
+
3
+ class Encryptors < ActiveSupport::TestCase
4
+ include Support::Swappers
5
+
6
+ test 'should match a password created by devise-drupal' do
7
+ hash = Devise::Encryptable::Encryptors::DrupalHash.digest('admin', nil, nil, nil)
8
+ compare = Devise::Encryptable::Encryptors::DrupalHash.compare(hash, 'admin', nil, nil, nil)
9
+ assert_equal true, compare
10
+ end
11
+
12
+ test 'should match a password created by Drupal 7' do
13
+ hash = "$S$DSECOTv7C.aNnAAPVG.gOY718Xg5U3jFp11u76sqpKGDM3zm.f4O"
14
+ compare = Devise::Encryptable::Encryptors::DrupalHash.compare(hash, 'admin', nil, nil, nil)
15
+ assert_equal true, compare
16
+ end
17
+
18
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,10 @@
1
+ class Admin < ActiveRecord::Base
2
+ devise :database_authenticatable, :encryptable
3
+
4
+ def password_salt
5
+ 'no salt'
6
+ end
7
+
8
+ def password_salt=(new_salt)
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class User < ActiveRecord::Base
2
+ devise :database_authenticatable, :encryptable
3
+
4
+ def password_salt
5
+ 'no salt'
6
+ end
7
+
8
+ def password_salt=(new_salt)
9
+ end
10
+ end
11
+
@@ -0,0 +1,54 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ if defined?(Bundler)
6
+ # If you precompile assets before deploying to production, use this line
7
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
8
+ # If you want your assets lazily compiled in production, use this line
9
+ # Bundler.require(:default, :assets, Rails.env)
10
+ end
11
+
12
+ module RailsApp
13
+ class Application < Rails::Application
14
+ # Settings in config/environments/* take precedence over those specified here.
15
+ # Application configuration should go into files in config/initializers
16
+ # -- all .rb files in that directory are automatically loaded.
17
+
18
+ # Custom directories with classes and modules you want to be autoloadable.
19
+ # config.autoload_paths += %W(#{config.root}/extras)
20
+
21
+ # Only load the plugins named here, in the order given (default is alphabetical).
22
+ # :all can be used as a placeholder for all plugins not explicitly named.
23
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
+
25
+ # Activate observers that should always be running.
26
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27
+
28
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
29
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
30
+ # config.time_zone = 'Central Time (US & Canada)'
31
+
32
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
33
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
34
+ # config.i18n.default_locale = :de
35
+
36
+ # Configure the default encoding used in templates for Ruby 1.9.
37
+ config.encoding = "utf-8"
38
+
39
+ # Configure sensitive parameters which will be filtered from the log file.
40
+ config.filter_parameters += [:password]
41
+
42
+ # Use SQL instead of Active Record's schema dumper when creating the database.
43
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
44
+ # like if you have constraints or database-specific column types
45
+ # config.active_record.schema_format = :sql
46
+
47
+ # Enable the asset pipeline
48
+ config.assets.enabled = true
49
+
50
+ # Version of your assets, change this if you want to expire all your assets
51
+ config.assets.version = '1.0'
52
+ end
53
+ end
54
+
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
7
+
@@ -0,0 +1,6 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ RailsApp::Application.initialize!
6
+
@@ -0,0 +1,29 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+ config.eager_load = false
9
+
10
+ # Show full error reports and disable caching
11
+ config.consider_all_requests_local = true
12
+ config.action_controller.perform_caching = false
13
+
14
+ # Don't care if the mailer can't send
15
+ config.action_mailer.raise_delivery_errors = false
16
+
17
+ # Print deprecation notices to the Rails logger
18
+ config.active_support.deprecation = :log
19
+
20
+ # Only use best-standards-support built into browsers
21
+ config.action_dispatch.best_standards_support = :builtin
22
+
23
+ # Do not compress assets
24
+ config.assets.compress = false
25
+
26
+ # Expands the lines which load the assets
27
+ config.assets.debug = true
28
+ end
29
+
@@ -0,0 +1,68 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+
11
+ # Disable Rails's static asset server (Apache or nginx will already do this)
12
+ config.serve_static_assets = false
13
+
14
+ # Compress JavaScripts and CSS
15
+ config.assets.compress = true
16
+
17
+ # Don't fallback to assets pipeline if a precompiled asset is missed
18
+ config.assets.compile = false
19
+
20
+ # Generate digests for assets URLs
21
+ config.assets.digest = true
22
+
23
+ # Defaults to Rails.root.join("public/assets")
24
+ # config.assets.manifest = YOUR_PATH
25
+
26
+ # Specifies the header that your server uses for sending files
27
+ # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29
+
30
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
31
+ # config.force_ssl = true
32
+
33
+ # See everything in the log (default is :info)
34
+ # config.log_level = :debug
35
+
36
+ # Prepend all log lines with the following tags
37
+ # config.log_tags = [ :subdomain, :uuid ]
38
+
39
+ # Use a different logger for distributed setups
40
+ # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
41
+
42
+ # Use a different cache store in production
43
+ # config.cache_store = :mem_cache_store
44
+
45
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server
46
+ # config.action_controller.asset_host = "http://assets.example.com"
47
+
48
+ # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
49
+ # config.assets.precompile += %w( search.js )
50
+
51
+ # Disable delivery errors, bad email addresses will be ignored
52
+ # config.action_mailer.raise_delivery_errors = false
53
+
54
+ # Enable threaded mode
55
+ # config.threadsafe!
56
+
57
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
58
+ # the I18n.default_locale when a translation can not be found)
59
+ config.i18n.fallbacks = true
60
+
61
+ # Send deprecation notices to registered listeners
62
+ config.active_support.deprecation = :notify
63
+
64
+ # Log the query plan for queries taking more than this (works
65
+ # with SQLite, MySQL, and PostgreSQL)
66
+ # config.active_record.auto_explain_threshold_in_seconds = 0.5
67
+ end
68
+
@@ -0,0 +1,33 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+ config.eager_load = false
10
+
11
+ # Configure static asset server for tests with Cache-Control for performance
12
+ config.serve_static_assets = true
13
+ config.static_cache_control = "public, max-age=3600"
14
+
15
+ # Show full error reports and disable caching
16
+ config.consider_all_requests_local = true
17
+ config.action_controller.perform_caching = false
18
+
19
+ # Raise exceptions instead of rendering exception templates
20
+ config.action_dispatch.show_exceptions = false
21
+
22
+ # Disable request forgery protection in test environment
23
+ config.action_controller.allow_forgery_protection = false
24
+
25
+ # Tell Action Mailer not to deliver emails to the real world.
26
+ # The :test delivery method accumulates sent emails in the
27
+ # ActionMailer::Base.deliveries array.
28
+ config.action_mailer.delivery_method = :test
29
+
30
+ # Print deprecation notices to the stderr
31
+ config.active_support.deprecation = :stderr
32
+ end
33
+
@@ -0,0 +1,15 @@
1
+ Devise.setup do |config|
2
+ config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
3
+
4
+ require 'devise/orm/active_record'
5
+
6
+ config.case_insensitive_keys = [ :email ]
7
+
8
+ config.strip_whitespace_keys = [ :email ]
9
+ config.skip_session_storage = [:http_auth]
10
+
11
+ config.stretches = Rails.env.test? ? 1 : 10
12
+
13
+ config.encryptor = :drupal_hash
14
+ end
15
+
@@ -0,0 +1,78 @@
1
+ class CreateTables < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :users do |t|
4
+ t.string :username
5
+ t.string :facebook_token
6
+
7
+ ## Database authenticatable
8
+ t.string :email, :null => false, :default => ""
9
+ t.string :encrypted_password, :null => false, :default => ""
10
+
11
+ ## Recoverable
12
+ t.string :reset_password_token
13
+ t.datetime :reset_password_sent_at
14
+
15
+ ## Rememberable
16
+ t.datetime :remember_created_at
17
+
18
+ ## Trackable
19
+ t.integer :sign_in_count, :default => 0
20
+ t.datetime :current_sign_in_at
21
+ t.datetime :last_sign_in_at
22
+ t.string :current_sign_in_ip
23
+ t.string :last_sign_in_ip
24
+
25
+ ## Encryptable
26
+ # t.string :password_salt
27
+
28
+ ## Confirmable
29
+ t.string :confirmation_token
30
+ t.datetime :confirmed_at
31
+ t.datetime :confirmation_sent_at
32
+ # t.string :unconfirmed_email # Only if using reconfirmable
33
+
34
+ ## Lockable
35
+ t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
36
+ t.string :unlock_token # Only if unlock strategy is :email or :both
37
+ t.datetime :locked_at
38
+
39
+ ## Token authenticatable
40
+ t.string :authentication_token
41
+
42
+ t.timestamps
43
+ end
44
+
45
+ create_table :admins do |t|
46
+ ## Database authenticatable
47
+ t.string :email, :null => true
48
+ t.string :encrypted_password, :null => true
49
+
50
+ ## Recoverable
51
+ t.string :reset_password_token
52
+ t.datetime :reset_password_sent_at
53
+
54
+ ## Rememberable
55
+ t.datetime :remember_created_at
56
+
57
+ ## Confirmable
58
+ t.string :confirmation_token
59
+ t.datetime :confirmed_at
60
+ t.datetime :confirmation_sent_at
61
+ t.string :unconfirmed_email # Only if using reconfirmable
62
+
63
+ ## Encryptable
64
+ t.string :password_salt
65
+
66
+ ## Lockable
67
+ t.datetime :locked_at
68
+
69
+ t.timestamps
70
+ end
71
+ end
72
+
73
+ def self.down
74
+ drop_table :users
75
+ drop_table :admins
76
+ end
77
+ end
78
+
@@ -0,0 +1,14 @@
1
+ module Support
2
+ module Assertions
3
+ def assert_same_content(result, expected)
4
+ assert expected.size == result.size, "the arrays doesn't have the same size"
5
+ expected.each do |element|
6
+ assert result.include?(element), "The array doesn't include '#{element}'."
7
+ end
8
+ end
9
+
10
+ def assert_not(assertion)
11
+ assert !assertion
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ module Support
2
+ module Factories
3
+ def generate_unique_email
4
+ @@email_count ||= 0
5
+ @@email_count += 1
6
+ "test#{@@email_count}@example.com"
7
+ end
8
+
9
+ def valid_attributes(attributes={})
10
+ { :username => "usertest",
11
+ :email => generate_unique_email,
12
+ :password => '123456',
13
+ :password_confirmation => '123456' }.update(attributes)
14
+ end
15
+
16
+ def create_admin(attributes={})
17
+ valid_attributes = valid_attributes(attributes)
18
+ valid_attributes.delete(:username)
19
+ Admin.create!(valid_attributes)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ module Support
2
+ module Swappers
3
+ def swap_with_encryptor(klass, encryptor, options={})
4
+ klass.instance_variable_set(:@encryptor_class, nil)
5
+
6
+ swap klass, options.merge(:encryptor => encryptor) do
7
+ begin
8
+ yield
9
+ ensure
10
+ klass.instance_variable_set(:@encryptor_class, nil)
11
+ end
12
+ end
13
+ end
14
+
15
+ def swap(object, new_values)
16
+ old_values = {}
17
+ new_values.each do |key, value|
18
+ old_values[key] = object.send key
19
+ object.send :"#{key}=", value
20
+ end
21
+ yield
22
+ ensure
23
+ old_values.each do |key, value|
24
+ object.send :"#{key}=", value
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+ require "devise"
3
+ require "devise/version"
4
+ require "active_support/core_ext/module/attribute_accessors"
5
+
6
+ require "devise/encryptable/encryptable"
7
+ require "devise/encryptable/encryptors/drupal_hash"
8
+
9
+ require "minitest/autorun"
10
+ require "minitest/unit"
11
+
12
+ require "mocha/setup"
13
+
14
+ require "rails_app/config/environment"
15
+
16
+ require 'support/assertions'
17
+ require 'support/factories'
18
+ require 'support/swappers'
19
+
20
+ ActiveRecord::Migration.verbose = false
21
+ ActiveRecord::Base.logger = Logger.new(nil)
22
+
23
+ ActiveRecord::Migrator.migrate(File.expand_path("test/rails_app/db/migrate"))
24
+
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise-drupal
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeroen Bobbeldijk
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: devise-encryptable
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.2
30
+ description: Drupal Hash implementation for Devise Encryptable
31
+ email: jeroen@vdmi.nl
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - Changelog.md
37
+ - LICENSE
38
+ - README.md
39
+ - lib/devise/encryptable/encryptors/drupal_hash.rb
40
+ - lib/devise-drupal.rb
41
+ - test/support/factories.rb
42
+ - test/support/assertions.rb
43
+ - test/support/swappers.rb
44
+ - test/devise/encryptable/encryptors/drupal_hash_test.rb
45
+ - test/test_helper.rb
46
+ - test/rails_app/app/controllers/application_controller.rb
47
+ - test/rails_app/app/models/admin.rb
48
+ - test/rails_app/app/models/user.rb
49
+ - test/rails_app/db/migrate/20120508165529_create_tables.rb
50
+ - test/rails_app/config/environment.rb
51
+ - test/rails_app/config/environments/test.rb
52
+ - test/rails_app/config/environments/production.rb
53
+ - test/rails_app/config/environments/development.rb
54
+ - test/rails_app/config/application.rb
55
+ - test/rails_app/config/boot.rb
56
+ - test/rails_app/config/initializers/devise.rb
57
+ homepage: http://github.com/jerbob92/drupal
58
+ licenses:
59
+ - Apache 2.0
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.23
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Drupal Hash implementation for Devise Encryptable
82
+ test_files:
83
+ - test/support/factories.rb
84
+ - test/support/assertions.rb
85
+ - test/support/swappers.rb
86
+ - test/devise/encryptable/encryptors/drupal_hash_test.rb
87
+ - test/test_helper.rb
88
+ - test/rails_app/app/controllers/application_controller.rb
89
+ - test/rails_app/app/models/admin.rb
90
+ - test/rails_app/app/models/user.rb
91
+ - test/rails_app/db/migrate/20120508165529_create_tables.rb
92
+ - test/rails_app/config/environment.rb
93
+ - test/rails_app/config/environments/test.rb
94
+ - test/rails_app/config/environments/production.rb
95
+ - test/rails_app/config/environments/development.rb
96
+ - test/rails_app/config/application.rb
97
+ - test/rails_app/config/boot.rb
98
+ - test/rails_app/config/initializers/devise.rb