has_protected_token 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eab02b7662c9a1411f7e12d6ba5b847ed6abed6ae0c9320f872d889344647087
4
- data.tar.gz: 6c97a89ebc3c9b0b937d074bfbb034c1bb23e8a0df2f4855788b32bdac0e57b8
3
+ metadata.gz: 363aabd71ffa00d3aea3fc45ea5c75459d73eb7ad5f5ed3f4534746b9de42885
4
+ data.tar.gz: 9bf9566a560122891e76206ee6b719df3037af9ce7f308bff42b3fa787228cff
5
5
  SHA512:
6
- metadata.gz: 1ad8401ee713aacc57e39d64a41088d249b14deedd83cc0b95d368e13f6997a220a41781ec8a34cb7fead5a787c0ef24cfbb77cd388e2058071d06582f219eaa
7
- data.tar.gz: 6322d1b090e322b1064c3c3306f737a6e801ca87b9c9a26678f9f2e8d09f5d36aba3bbf8e8dea1ce88b67f3731e0a7ab66775eaacc100350dd562276ee7edce4
6
+ metadata.gz: 583fac5f9054fe9a9c6f40bc9814f6f76ddb03214bbfa3d4e1f43374822662f94fa737e04ca80e9e79d87cd07f978b86a9d85985fa1559e1d1b0761ac1b7af99
7
+ data.tar.gz: 6a01174335793e1548dc280af4ec1ca52a7b66d532c5a34ebeb94de51fca13ed2dfb7a55129189f2dfd013906c27b8e213c1d64bf2e3b4cfb601731f3f8e245b
@@ -0,0 +1,45 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at 1337dallen@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
44
+
45
+ For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq
@@ -0,0 +1,33 @@
1
+ # Contributing
2
+
3
+ Improvements, bug-fixes, suggestions, etc are very welcome. If it's your first time contributing to open-source, so much the better.
4
+
5
+ ## Opening an issue
6
+
7
+ If you've found a bug or have a feature request, please [open an issue](https://github.com/StaphSynth/has_protected_token/issues) on the github project page.
8
+
9
+ If you're reporting a bug, please provide the steps required to reproduce it and include your Ruby and ActiveRecord versions.
10
+
11
+ ## Contributing code/documentation
12
+
13
+ All contributions are welcome, even if you're fixing a typo!
14
+
15
+ 1. Fork the repository and run `$ bundle install`.
16
+ 2. Checkout a new branch and make your changes.
17
+ 3. [Open a pull request](https://github.com/StaphSynth/has_protected_token/pulls) on the github project page. Describe the the issue you're addressing and how your changes resolve it.
18
+
19
+ For those who are unfamiliar with the above workflow, or it's your first time contributing to open-source, there are some great [guides](https://github.com/collections/choosing-projects) available to help [get you started](https://github.com/FreeCodeCamp/how-to-contribute-to-open-source).
20
+
21
+ ### Running the test suite
22
+
23
+ All code changes must include test coverage.
24
+
25
+ While working on changes, the simplest way of running the test suite is:
26
+
27
+ `$ rake test`
28
+
29
+ However, that command only runs the suite against your current version of Ruby and ActiveRecord. Before opening a pull request, you may wish to run the full Travis-CI test suite which tests your code against all supported versions of Ruby and ActiveRecord. To do this, run:
30
+
31
+ `$ rake ci`
32
+
33
+ You'll need to make sure you have Ruby 2.3, 2.4, 2.5 and 2.6 installed first, though. (If you don't know how to do this, [here](https://syntheta.se/coding/2018/12/09/getting-started-with-ruby.html) is a quick guide on setting up Ruby version management.)
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- has_protected_token (0.1.0)
4
+ has_protected_token (0.1.1)
5
5
  activerecord (>= 4.2)
6
6
  bcrypt (~> 3.1.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (6.0.0)
12
- activesupport (= 6.0.0)
13
- activerecord (6.0.0)
14
- activemodel (= 6.0.0)
15
- activesupport (= 6.0.0)
16
- activesupport (6.0.0)
11
+ activemodel (6.0.1)
12
+ activesupport (= 6.0.1)
13
+ activerecord (6.0.1)
14
+ activemodel (= 6.0.1)
15
+ activesupport (= 6.0.1)
16
+ activesupport (6.0.1)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
18
  i18n (>= 0.7, < 2)
19
19
  minitest (~> 5.1)
20
20
  tzinfo (~> 1.1)
21
- zeitwerk (~> 2.1, >= 2.1.8)
21
+ zeitwerk (~> 2.2)
22
22
  appraisal (2.2.0)
23
23
  bundler
24
24
  rake
@@ -32,7 +32,7 @@ GEM
32
32
  diff-lcs (1.3)
33
33
  i18n (1.7.0)
34
34
  concurrent-ruby (~> 1.0)
35
- jaro_winkler (1.5.3)
35
+ jaro_winkler (1.5.4)
36
36
  minitest (5.13.0)
37
37
  parallel (1.18.0)
38
38
  parser (2.6.5.0)
@@ -52,7 +52,7 @@ GEM
52
52
  diff-lcs (>= 1.2.0, < 2.0)
53
53
  rspec-support (~> 3.9.0)
54
54
  rspec-support (3.9.0)
55
- rubocop (0.69.0)
55
+ rubocop (0.76.0)
56
56
  jaro_winkler (~> 1.5.1)
57
57
  parallel (~> 1.10)
58
58
  parser (>= 2.6)
@@ -67,7 +67,7 @@ GEM
67
67
  thread_safe (~> 0.1)
68
68
  unicode-display_width (1.6.0)
69
69
  wwtd (1.4.0)
70
- zeitwerk (2.2.0)
70
+ zeitwerk (2.2.2)
71
71
 
72
72
  PLATFORMS
73
73
  ruby
File without changes
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- # has_protected_token
1
+ [![Build Status](https://api.travis-ci.com/StaphSynth/has_protected_token.svg?branch=master)](https://travis-ci.com/StaphSynth/has_protected_token)
2
+ [![Gem Version](https://badge.fury.io/rb/has_protected_token.svg)](https://badge.fury.io/rb/has_protected_token)
2
3
 
3
- Current version: _0.0.0beta_. This gem is currently in pre-release beta and a stable release will be made _real soon now_.
4
+ # has_protected_token
4
5
 
5
6
  ## What?
6
7
 
@@ -8,7 +9,7 @@ Abstracts away generating, storing and validating user auth tokens. Use it if yo
8
9
 
9
10
  ## Installation
10
11
 
11
- Requirements: Ruby >= 2.2, ActiveRecord >= 4.2
12
+ Requirements: Ruby >= 2.3, ActiveRecord >= 4.2
12
13
 
13
14
  From the command line:
14
15
 
@@ -19,7 +20,7 @@ $ gem install has_protected_token
19
20
  In your project gemfile:
20
21
 
21
22
  ```ruby
22
- gem 'has_protected_token'
23
+ gem 'has_protected_token'
23
24
  ```
24
25
 
25
26
  ## Usage
@@ -82,3 +83,7 @@ user.validate_token('incorrect value')
82
83
  ```ruby
83
84
  has_protected_token cost: 16
84
85
  ```
86
+
87
+ ## Contributing
88
+
89
+ Contributions are very welcome. Please see the [documentation](https://github.com/StaphSynth/has_protected_token/blob/master/CONTRIBUTING.md) for help on geting started.
@@ -2,16 +2,18 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'has_protected_token'
5
- s.version = '0.1.0'
5
+ s.version = '0.1.1'
6
6
  s.date = '2019-10-06'
7
7
  s.summary = 'Easily generate random tokens for any ActiveRecord model and store them securely in the database.'
8
8
  s.description = 'Generate random tokens (or use your own) for any ActiveRecord model. Hashes and salts the token before storage in the database using the same methodology as has_secure_password.'
9
9
  s.author = 'David Allen'
10
10
  s.email = '1337dallen@gmail.com' # yes, I know it's a terrible email address...
11
- s.files = `git ls-files`.split("\n")
12
11
  s.homepage = 'https://github.com/StaphSynth/has_protected_token'
13
12
  s.license = 'MIT'
14
13
  s.required_ruby_version = '>= 2.3'
14
+ s.files = Dir.chdir(File.expand_path(__dir__)) do
15
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
16
+ end
15
17
 
16
18
  s.add_dependency 'activerecord', '>= 4.2'
17
19
  s.add_dependency 'bcrypt', '~> 3.1.1'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_protected_token
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Allen
@@ -192,9 +192,11 @@ files:
192
192
  - ".ruby-version"
193
193
  - ".travis.yml"
194
194
  - Appraisals
195
+ - CODE_OF_CONDUCT.md
196
+ - CONTRIBUTING.md
195
197
  - Gemfile
196
198
  - Gemfile.lock
197
- - LICENSE.txt
199
+ - LICENSE.md
198
200
  - README.md
199
201
  - Rakefile
200
202
  - gemfiles/.bundle/config
@@ -205,11 +207,6 @@ files:
205
207
  - gemfiles/AR_6.0.gemfile
206
208
  - has_protected_token.gemspec
207
209
  - lib/has_protected_token.rb
208
- - spec/features/token_authentication_spec.rb
209
- - spec/lib/has_protected_token_spec.rb
210
- - spec/spec_helper.rb
211
- - spec/support/model.rb
212
- - spec/support/schema.rb
213
210
  homepage: https://github.com/StaphSynth/has_protected_token
214
211
  licenses:
215
212
  - MIT
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe 'token authentication' do
6
- let(:user) { User.create }
7
-
8
- describe 'for locally generated tokens' do
9
- describe 'when presented with the correct secret value' do
10
- it 'returns true' do
11
- secret = user.regenerate_token
12
-
13
- expect(user.authenticate_token(secret)).to eq(true)
14
- end
15
- end
16
-
17
- describe 'when presented with the incorrect secret value' do
18
- it 'returns false' do
19
- user.regenerate_token
20
-
21
- expect(user.authenticate_token('derp derp')).to eq(false)
22
- end
23
- end
24
- end
25
-
26
- describe 'for user-supplied tokens' do
27
- before do
28
- user.token = 'trains'
29
- end
30
-
31
- describe 'when presented with the correct secret value' do
32
- it 'returns true' do
33
- expect(user.authenticate_token('trains')).to eq(true)
34
- end
35
- end
36
-
37
- describe 'when presented with the incorrect secret value' do
38
- it 'returns false' do
39
- expect(user.authenticate_token('buses')).to eq(false)
40
- end
41
- end
42
- end
43
- end
@@ -1,140 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- describe ActiveRecord::ProtectedToken do
6
- let(:user) { User.create }
7
- let(:raw_token) { 'raw_token' }
8
- let(:hashed_token) { '$hashed_token$' }
9
-
10
- describe 'options hash' do
11
- describe 'column_name' do
12
- context 'when no value is provided' do
13
- it 'defaults to "token"' do
14
- expect(user.respond_to?(:regenerate_token)).to be(true)
15
- end
16
- end
17
-
18
- context 'when a symbol is passed' do
19
- let(:user) { SpecialUser.create }
20
-
21
- it 'uses it as an attribute name' do
22
- expect(user.respond_to?(:regenerate_shared_secret)).to be(true)
23
- expect(user.respond_to?(:regenerate_token)).to be(false)
24
- end
25
- end
26
- end
27
-
28
- describe 'cost' do
29
- context 'when no value provided' do
30
- it 'defaults to BCrypt::Engine::DEFAULT_COST' do
31
- expect(BCrypt::Password).to receive(:create).with(
32
- raw_token,
33
- cost: BCrypt::Engine::DEFAULT_COST
34
- )
35
-
36
- user.token = raw_token
37
- end
38
- end
39
-
40
- context 'when an integer is provided' do
41
- let(:user) { LowCostUser.new }
42
-
43
- it 'accepts that instead' do
44
- expect(BCrypt::Password).to receive(:create).with(
45
- raw_token,
46
- cost: 4
47
- )
48
-
49
- user.token = raw_token
50
- end
51
- end
52
- end
53
- end
54
-
55
- context 'instance methods' do
56
- before do
57
- allow(User).to receive(:generate_token).and_return(raw_token)
58
- allow(BCrypt::Password).to receive(:create).and_return(hashed_token)
59
- allow(BCrypt::Password).to(
60
- receive(:new).with(hashed_token).and_return(raw_token)
61
- )
62
- end
63
-
64
- describe '#regenerate_token' do
65
- it 'returns a new token' do
66
- expect(user.regenerate_token).to eq(raw_token)
67
- end
68
-
69
- it 'hashes the new token and stores it in the database' do
70
- user.regenerate_token
71
-
72
- expect(user.reload.token).to eq(hashed_token)
73
- end
74
- end
75
-
76
- describe '#authenticate_token' do
77
- before do
78
- user.regenerate_token
79
- end
80
-
81
- context 'when passed a plain text token' do
82
- it 'returns true if it matches the stored value' do
83
- expect(user.authenticate_token(raw_token)).to eq(true)
84
- end
85
-
86
- it 'returns false if it does not match the stored value' do
87
- expect(user.authenticate_token('derp derp')).to eq(false)
88
- end
89
- end
90
-
91
- context 'when passed bad data' do
92
- before do
93
- allow(BCrypt::Password).to receive(:new).and_raise(BCrypt::Error)
94
- end
95
-
96
- it 'returns false' do
97
- expect(user.authenticate_token(bad: 'data')).to eq(false)
98
- end
99
- end
100
- end
101
-
102
- describe '#token=' do
103
- context 'when passed a value' do
104
- it 'hashes it and stores the hashed value in the model instance' do
105
- user.token = raw_token
106
-
107
- expect(user.token).to eq(hashed_token)
108
- expect(User.find(user.id).token).to be_nil
109
- end
110
-
111
- it 'returns the original value' do
112
- expect(user.token = raw_token).to eq(raw_token)
113
- end
114
- end
115
- end
116
- end
117
-
118
- describe 'class methods' do
119
- describe '.generate_token' do
120
- let(:random_token) { 'abc123' }
121
-
122
- context 'with no arguments' do
123
- it 'returns a token 24 chars in length' do
124
- expect(User.generate_token.size).to eq(24)
125
- end
126
- end
127
-
128
- context 'when passing a length' do
129
- it 'validates the length is coercable to an integer' do
130
- expect { User.generate_token(12) }.not_to raise_error
131
- expect { User.generate_token(false) }.to raise_error(ArgumentError)
132
- end
133
-
134
- it 'returns a token of that length' do
135
- expect(User.generate_token(20).size).to eq(20)
136
- end
137
- end
138
- end
139
- end
140
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'byebug'
4
- require 'database_cleaner'
5
- require 'has_protected_token'
6
- require_relative './support/model'
7
-
8
- RSpec.configure do |config|
9
- config.shared_context_metadata_behavior = :apply_to_host_groups
10
-
11
- config.expect_with :rspec do |expectations|
12
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
13
- end
14
-
15
- config.mock_with :rspec do |mocks|
16
- mocks.verify_partial_doubles = true
17
- end
18
-
19
- config.before :suite do
20
- ActiveRecord::Base.establish_connection(
21
- adapter: 'sqlite3',
22
- database: ':memory:'
23
- )
24
- ActiveRecord::Migration.suppress_messages do
25
- load 'support/schema.rb'
26
- end
27
- end
28
-
29
- config.before :each do
30
- DatabaseCleaner.strategy = :transaction
31
- DatabaseCleaner.start
32
- end
33
-
34
- config.after :each do
35
- DatabaseCleaner.clean
36
- end
37
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class Model < ActiveRecord::Base; end
4
-
5
- class User < Model
6
- has_protected_token
7
- end
8
-
9
- class SpecialUser < Model
10
- has_protected_token column_name: :shared_secret
11
- end
12
-
13
- class LowCostUser < Model
14
- has_protected_token cost: 4
15
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ActiveRecord::Schema.define(version: 1) do
4
- create_table :models do |t|
5
- t.string :shared_secret
6
- t.string :token
7
- end
8
- end