jwt_claims 0.0.2 → 0.1.0

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
  SHA1:
3
- metadata.gz: 2dc7d84bde89e7a58ef9a97e0956b3f2df05de92
4
- data.tar.gz: fee164d4bda3ce9961ff6f925fc31ffbbc4cd228
3
+ metadata.gz: e299cbb40a060543123ca93063ed868a34c53d61
4
+ data.tar.gz: bac421ac14a1f22190da5d455bcb2f6d85a7c942
5
5
  SHA512:
6
- metadata.gz: b104d535a45f2769cb204750364945bb36ac28ac68c4bc6ce80e98a513de21622367cc7df8513fa2a24409545b3a79c76d13da95471d0cbc0ecc08da7ed9fea8
7
- data.tar.gz: 29a5c2cf243aa90c09e03dca4480d24bd1247ace4ed86529046224789e117af17f3c38b7786adca455743165dc0bafc94473f4024115a4f6147065f30160f7c3
6
+ metadata.gz: 807dacbb355c17f817a6059b4d1321c96e01be67da3d14eaa298e1db3b0fad5006368b113bd465d34f84f008ef8be306355ee349fbfe5958f2d09cd1916f2aae
7
+ data.tar.gz: 4028c94c59c3373865a4c3e62d29760e6310fc4c32344ec9a8feb2c15fbf247b55ba659052c84e73c0ccc0e53235f9d1eb6653698593d78a71e72d06682e5800
data/.rspec CHANGED
@@ -1,2 +1 @@
1
1
  --color
2
- --require spec_helper
data/.travis.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.2
4
- - 2.1.6
5
- - 2.0.0
6
- # uncomment this line if your project needs to run something other than `rake`:
7
- script: bundle exec rspec spec
3
+ - 2.0.0-p648
4
+ - 2.1.10
5
+ - 2.2.5
6
+ - 2.3.1
7
+ before_install: gem install bundler -v 1.13.2
data/CHANGELOG.md CHANGED
@@ -1,10 +1,19 @@
1
1
  ## Changelog
2
2
 
3
+ ### v0.1.0 (2016-10-09)
4
+
5
+ * Bug Fixes
6
+ * Added requires to reference the claims and util modules
7
+
8
+ * Enhancements
9
+ * Modernized the dev environment
10
+ * Added a README example that includes a claim and a working token
11
+
3
12
  ### v0.0.2 (2015-08-30)
4
13
 
5
- * enhancements
6
- * support leeway for 'Expiration time' and 'Not before' claims
14
+ * Enhancements
15
+ * Support leeway for 'Expiration time' and 'Not before' claims
7
16
 
8
17
  ### v0.0.1 (2015-08-29)
9
18
 
10
- * initial
19
+ * Initial
data/Gemfile CHANGED
@@ -1,7 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ # Specify your gem's dependencies in jwt_claims.gemspec
3
4
  gemspec
4
-
5
- gem 'pry-byebug', '~> 3.1', require: false
6
- gem 'simplecov', '~> 0.10', require: false
7
- gem 'yard', '~> 0.8', require: false
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Gary Fleshman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -31,12 +31,14 @@ Please refer to the [JSON Web Token][json_web_token] gem for additional guidance
31
31
  Example
32
32
 
33
33
  ```ruby
34
-
35
- secure_jwt_example = 'eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leGFt.cGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk'
36
-
37
- # verify with default algorithm, HMAC SHA256
38
- {:ok, verified_claims} = JwtClaims.verify(secure_jwt_example, key: 'gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C')
39
-
34
+ # An example using the 'Expires' `exp` claim (10 years for this example).
35
+ > jwt = JsonWebToken.sign({foo: 'bar', exp: Time.now.to_i + 315360000}, key: 'gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C')
36
+ #=> "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJleHAiOjE3OTEyMjc1MTl9.7cT7PzsT8Jv0VQIxokjk3sUqzJCxBR4h3W2uACQ-tW0"
37
+
38
+ # Verify with default algorithm, HMAC SHA256
39
+ # Returns a hash of `{:ok, verified_claims}`
40
+ > JwtClaims.verify(jwt, key: 'gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C')
41
+ #=> {:ok=>{:foo=>"bar", :exp=>1475870843}}
40
42
  ```
41
43
 
42
44
  ### Supported registered claims
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+ require 'wwtd/tasks'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ YARD::Rake::YardocTask.new
9
+
10
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'jwt_claims'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'pry'
10
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/jwt_claims.gemspec CHANGED
@@ -1,21 +1,36 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
  require 'jwt_claims/version'
4
5
 
5
6
  Gem::Specification.new do |s|
6
- s.author = 'Gary Fleshman'
7
- s.email = 'gfleshman@newforge-tech.com'
8
- s.files = `git ls-files`.split("\n")
9
- s.homepage = 'https://github.com/garyf/jwt_claims'
10
- s.name = 'jwt_claims'
7
+ s.name = 'jwt_claims'
8
+ s.version = JwtClaims::VERSION
9
+ s.authors = ['Gary Fleshman']
10
+ s.email = ['gfleshman@newforge-tech.com']
11
+
12
+ s.summary = 'JSON Web Token (JWT) Claims for Ruby'
13
+ s.description = 'Modular implementation of JSON Web Token (JWT) Claims'
14
+ s.homepage = 'https://github.com/garyf/jwt_claims'
15
+ s.license = 'MIT'
16
+
17
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ s.require_paths = ['lib']
22
+
11
23
  s.platform = Gem::Platform::RUBY
12
- s.summary = 'JSON Web Token (JWT) Claims for Ruby'
13
- s.version = JwtClaims::VERSION
14
- # recommended
15
- s.license = 'MIT'
16
- # optional
17
- s.add_runtime_dependency('json_web_token', '~> 0.3')
18
- s.add_development_dependency('rspec', '~> 3.3')
19
- s.description = 'Modular implementation of JSON Web Token (JWT) Claims'
20
24
  s.required_ruby_version = '>= 2.0.0'
25
+
26
+ s.add_runtime_dependency('json_web_token', '~> 0.3')
27
+
28
+ s.add_development_dependency 'bundler', '~> 1.13'
29
+ s.add_development_dependency 'rake', '~> 10.0'
30
+ s.add_development_dependency 'rspec', '~> 3.0'
31
+ s.add_development_dependency 'pry', '~> 0.10'
32
+ s.add_development_dependency 'pry-byebug', '~> 3.4'
33
+ s.add_development_dependency 'simplecov', '~> 0.12'
34
+ s.add_development_dependency 'yard', '~> 0.9'
35
+ s.add_development_dependency 'wwtd', '~> 1.3'
21
36
  end
@@ -1,3 +1,5 @@
1
+ require 'jwt_claims/util'
2
+
1
3
  module JwtClaims
2
4
  module Claim
3
5
  # Expiration time
@@ -1,3 +1,5 @@
1
+ require 'jwt_claims/util'
2
+
1
3
  module JwtClaims
2
4
  module Claim
3
5
  # Not before
@@ -1,3 +1,11 @@
1
+ require 'jwt_claims/claim/aud'
2
+ require 'jwt_claims/claim/exp'
3
+ require 'jwt_claims/claim/iat'
4
+ require 'jwt_claims/claim/iss'
5
+ require 'jwt_claims/claim/jti'
6
+ require 'jwt_claims/claim/nbf'
7
+ require 'jwt_claims/claim/sub'
8
+
1
9
  module JwtClaims
2
10
  # Validate registered claims
3
11
  # @see http://tools.ietf.org/html/rfc7519#section-4.1
@@ -1,3 +1,3 @@
1
1
  module JwtClaims
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt_claims
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary Fleshman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-30 00:00:00.000000000 Z
11
+ date: 2016-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_web_token
@@ -24,22 +24,121 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rspec
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
59
  - - "~>"
32
60
  - !ruby/object:Gem::Version
33
- version: '3.3'
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.12'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.12'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: wwtd
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.3'
34
132
  type: :development
35
133
  prerelease: false
36
134
  version_requirements: !ruby/object:Gem::Requirement
37
135
  requirements:
38
136
  - - "~>"
39
137
  - !ruby/object:Gem::Version
40
- version: '3.3'
138
+ version: '1.3'
41
139
  description: Modular implementation of JSON Web Token (JWT) Claims
42
- email: gfleshman@newforge-tech.com
140
+ email:
141
+ - gfleshman@newforge-tech.com
43
142
  executables: []
44
143
  extensions: []
45
144
  extra_rdoc_files: []
@@ -49,8 +148,11 @@ files:
49
148
  - ".travis.yml"
50
149
  - CHANGELOG.md
51
150
  - Gemfile
52
- - LICENSE
151
+ - LICENSE.md
53
152
  - README.md
153
+ - Rakefile
154
+ - bin/console
155
+ - bin/setup
54
156
  - jwt_claims.gemspec
55
157
  - lib/jwt_claims.rb
56
158
  - lib/jwt_claims/claim/aud.rb
@@ -64,18 +166,6 @@ files:
64
166
  - lib/jwt_claims/util.rb
65
167
  - lib/jwt_claims/validation.rb
66
168
  - lib/jwt_claims/version.rb
67
- - spec/jwt_claims/claim/aud_spec.rb
68
- - spec/jwt_claims/claim/exp_spec.rb
69
- - spec/jwt_claims/claim/iat_spec.rb
70
- - spec/jwt_claims/claim/iss_spec.rb
71
- - spec/jwt_claims/claim/jti_spec.rb
72
- - spec/jwt_claims/claim/nbf_spec.rb
73
- - spec/jwt_claims/claim/sub_spec.rb
74
- - spec/jwt_claims/string_or_uri_spec.rb
75
- - spec/jwt_claims/util_spec.rb
76
- - spec/jwt_claims/validation_spec.rb
77
- - spec/jwt_claims_spec.rb
78
- - spec/spec_helper.rb
79
169
  homepage: https://github.com/garyf/jwt_claims
80
170
  licenses:
81
171
  - MIT
@@ -96,9 +186,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
186
  version: '0'
97
187
  requirements: []
98
188
  rubyforge_project:
99
- rubygems_version: 2.4.8
189
+ rubygems_version: 2.6.7
100
190
  signing_key:
101
191
  specification_version: 4
102
192
  summary: JSON Web Token (JWT) Claims for Ruby
103
193
  test_files: []
104
- has_rdoc:
data/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 Gary Fleshman
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,79 +0,0 @@
1
- require 'jwt_claims/claim/aud'
2
-
3
- module JwtClaims
4
- module Claim
5
- describe Aud do
6
- context '#reject?' do
7
- context 'w :aud claim an array' do
8
- let(:recipient) { 'recipient' }
9
- let(:uri) { 'http://www.example.com' }
10
- let(:aud) { [uri, recipient] }
11
- describe 'w match' do
12
- it 'string returns false' do
13
- expect(Aud.reject? aud, {aud: recipient}).to be false
14
- end
15
-
16
- it 'uri returns false' do
17
- expect(Aud.reject? aud, {aud: uri}).to be false
18
- end
19
- end
20
-
21
- it 'w/o match returns true' do
22
- expect(Aud.reject? aud, {aud: 'not recipient'}).to be true
23
- end
24
-
25
- it 'w/o options[:aud] returns true' do
26
- expect(Aud.reject? aud, {iss: 'recipient'}).to be true
27
- end
28
- end
29
-
30
- describe 'w :aud claim a string' do
31
- let(:recipient) { 'recipient' }
32
- let(:aud) { recipient }
33
- it 'w match returns false' do
34
- expect(Aud.reject? aud, {aud: recipient}).to be false
35
- end
36
-
37
- it 'w/o match returns true' do
38
- expect(Aud.reject? aud, {aud: 'not recipient'}).to be true
39
- end
40
-
41
- it 'w/o options[:aud] returns true' do
42
- expect(Aud.reject? aud, {iss: 'recipient'}).to be true
43
- end
44
- end
45
-
46
- shared_examples_for 'a blank :aud claim' do
47
- let(:options) { {aud: 'recipient'} }
48
- it 'returns true' do
49
- expect(Aud.reject? aud, options).to be true
50
- end
51
- end
52
-
53
- describe 'w :aud an empty array' do
54
- let(:aud) { [] }
55
- it_behaves_like 'a blank :aud claim'
56
- end
57
-
58
- describe 'w :aud an array w an empty string' do
59
- let(:aud) { [''] }
60
- it_behaves_like 'a blank :aud claim'
61
- end
62
-
63
- describe 'w :aud an empty string' do
64
- let(:aud) { '' }
65
- it_behaves_like 'a blank :aud claim'
66
- end
67
-
68
- describe 'w options[:aud] an empty string' do
69
- let(:aud) { 'recipient' }
70
- let(:options) { {aud: ''} }
71
- it 'returns truthy' do
72
- expect(Aud.reject? aud, options).to be true
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
79
-
@@ -1,37 +0,0 @@
1
- require 'jwt_claims/claim/exp'
2
-
3
- module JwtClaims
4
- module Claim
5
- describe Exp do
6
- let(:after_now) { Time.now.to_i + 1 }
7
- context '#reject?' do
8
- it 'w numeric_date after now returns false' do
9
- expect(Exp.reject? after_now).to be false
10
- end
11
-
12
- it 'w numeric_date now returns true' do
13
- expect(Exp.reject? Time.now.to_i).to be true
14
- end
15
-
16
- it 'w/o numeric numeric_date returns true' do
17
- expect(Exp.reject? after_now.to_s).to be true
18
- end
19
-
20
- context 'w leeway' do
21
- let(:seconds) { 180 }
22
- let(:options) { {leeway_seconds: seconds} }
23
- it 'w numeric_date after now returns false' do
24
- claim = after_now - seconds
25
- expect(Exp.reject? claim, options).to be false
26
- end
27
-
28
- it 'w numeric_date now returns true' do
29
- claim = Time.now.to_i - seconds
30
- expect(Exp.reject? claim, options).to be true
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
@@ -1,23 +0,0 @@
1
- require 'jwt_claims/claim/iat'
2
-
3
- module JwtClaims
4
- module Claim
5
- describe Iat do
6
- let(:before_now) { Time.now.to_i - 1 }
7
- describe '#reject?' do
8
- it 'w numeric_date now returns false' do
9
- expect(Iat.reject? before_now).to be false
10
- end
11
-
12
- it 'w numeric_date now returns true' do
13
- expect(Iat.reject? Time.now.to_i).to be true
14
- end
15
-
16
- it 'w/o numeric claimed_time returns true' do
17
- expect(Iat.reject? before_now.to_s).to be true
18
- end
19
- end
20
- end
21
- end
22
- end
23
-
@@ -1,30 +0,0 @@
1
- require 'jwt_claims/claim/iss'
2
-
3
- module JwtClaims
4
- module Claim
5
- describe Iss do
6
- context '#reject?' do
7
- let(:issuer) { 'issuer' }
8
- describe 'w an :iss claim' do
9
- let(:iss) { issuer }
10
- it 'w match returns false' do
11
- expect(Iss.reject? iss, {iss: issuer}).to be false
12
- end
13
-
14
- it 'w/o match returns true' do
15
- expect(Iss.reject? iss, {iss: 'not issuer'}).to be true
16
- end
17
-
18
- it 'w/o options[:iss] returns true' do
19
- expect(Iss.reject? iss, {aud: 'issuer'}).to be true
20
- end
21
- end
22
-
23
- it 'w a blank :iss claim returns true' do
24
- expect(Iss.reject? '', {iss: issuer}).to be true
25
- end
26
- end
27
- end
28
- end
29
- end
30
-
@@ -1,30 +0,0 @@
1
- require 'jwt_claims/claim/jti'
2
-
3
- module JwtClaims
4
- module Claim
5
- describe Jti do
6
- context '#reject?' do
7
- let(:jwt_id) { 'jwt_id' }
8
- describe 'w a :jti claim' do
9
- let(:jti) { jwt_id }
10
- it 'w match returns false' do
11
- expect(Jti.reject? jti, {jti: jwt_id}).to be false
12
- end
13
-
14
- it 'w/o match returns true' do
15
- expect(Jti.reject? jti, {jti: 'not jwt_id'}).to be true
16
- end
17
-
18
- it 'w/o options[:jti] returns true' do
19
- expect(Jti.reject? jti, {aud: jwt_id}).to be true
20
- end
21
- end
22
-
23
- it 'w a blank :jti claim returns true' do
24
- expect(Jti.reject? '', {jti: jwt_id}).to be true
25
- end
26
- end
27
- end
28
- end
29
- end
30
-
@@ -1,37 +0,0 @@
1
- require 'jwt_claims/claim/nbf'
2
-
3
- module JwtClaims
4
- module Claim
5
- describe Nbf do
6
- let(:after_now) { Time.now.to_i + 1 }
7
- context '#reject?' do
8
- it 'w numeric_date now returns false' do
9
- expect(Nbf.reject? Time.now.to_i).to be false
10
- end
11
-
12
- it 'w numeric_date after now returns true' do
13
- expect(Nbf.reject? after_now).to be true
14
- end
15
-
16
- it 'w/o numeric claimed_time returns true' do
17
- expect(Nbf.reject? after_now.to_s).to be true
18
- end
19
-
20
- context 'w leeway' do
21
- let(:seconds) { 180 }
22
- let(:options) { {leeway_seconds: seconds} }
23
- it 'w numeric_date now returns false' do
24
- claim = Time.now.to_i + seconds
25
- expect(Nbf.reject? claim, options).to be false
26
- end
27
-
28
- it 'w numeric_date after_now returns true' do
29
- claim = after_now + seconds
30
- expect(Nbf.reject? claim, options).to be true
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
@@ -1,30 +0,0 @@
1
- require 'jwt_claims/claim/sub'
2
-
3
- module JwtClaims
4
- module Claim
5
- describe Sub do
6
- context '#reject?' do
7
- let(:subject) { 'subject' }
8
- describe 'w a :sub claim' do
9
- let(:sub) { subject }
10
- it 'w match returns false' do
11
- expect(Sub.reject? sub, {sub: subject}).to be false
12
- end
13
-
14
- it 'w/o match returns true' do
15
- expect(Sub.reject? sub, {sub: 'not subject'}).to be true
16
- end
17
-
18
- it 'w/o options[:sub] returns true' do
19
- expect(Sub.reject? sub, {aud: subject}).to be true
20
- end
21
- end
22
-
23
- it 'w a blank :sub claim returns true' do
24
- expect(Sub.reject? '', {sub: subject}).to be true
25
- end
26
- end
27
- end
28
- end
29
- end
30
-
@@ -1,48 +0,0 @@
1
- require 'jwt_claims/string_or_uri'
2
-
3
- module JwtClaims
4
- describe StringOrUri do
5
- context '#present_and_equal?' do
6
- it 'w equality, returns true' do
7
- expect(StringOrUri.present_and_equal? 'foo', 'foo').to be true
8
- end
9
-
10
- shared_examples_for 'a blank value or not equal' do
11
- it 'returns false' do
12
- expect(StringOrUri.present_and_equal? a, b).to be false
13
- end
14
- end
15
-
16
- describe 'w 1st argument blank' do
17
- let(:a) { '' }
18
- let(:b) { 'bar' }
19
- it_behaves_like 'a blank value or not equal'
20
- end
21
-
22
- describe 'w 2nd argument blank' do
23
- let(:a) { 'foo' }
24
- let(:b) { '' }
25
- it_behaves_like 'a blank value or not equal'
26
- end
27
-
28
- describe 'w/o equality' do
29
- let(:a) { 'foo' }
30
- let(:b) { 'bar' }
31
- it_behaves_like 'a blank value or not equal'
32
- end
33
- end
34
-
35
- describe '#blank?' do
36
- it 'classifies nil, empty, or exclusively whitespace strings' do
37
- expect(StringOrUri.blank? nil).to be true
38
- expect(StringOrUri.blank? '').to be true
39
- expect(StringOrUri.blank? ' ').to be true
40
- expect(StringOrUri.blank? "\t\n\r").to be true
41
-
42
- expect(StringOrUri.blank? 'foo').to be false
43
- expect(StringOrUri.blank? 'bar ').to be false
44
- end
45
- end
46
- end
47
- end
48
-
@@ -1,16 +0,0 @@
1
- require 'jwt_claims/util'
2
-
3
- module JwtClaims
4
- describe Util do
5
- describe '#leeway_seconds' do
6
- it "returns a value between 0 and #{Util::LEEWAY_SECONDS_MAX}" do
7
- expect(Util.leeway_seconds 0).to eql 0
8
- expect(Util.leeway_seconds 180).to eql 180
9
- expect(Util.leeway_seconds 1.5).to eql 1.5
10
- expect(Util.leeway_seconds 181).to eql 0
11
- expect(Util.leeway_seconds -1).to eql 0
12
- expect(Util.leeway_seconds 'foo').to eql 0
13
- end
14
- end
15
- end
16
- end
@@ -1,70 +0,0 @@
1
- require 'jwt_claims/validation'
2
-
3
- module JwtClaims
4
- describe Validation do
5
- context 'example data' do
6
- let(:uri) { 'http://www.example.com' }
7
- let(:recipient) { 'recipient' }
8
- let(:aud) { [uri, recipient] }
9
-
10
- let(:after_now) { Time.now.to_i + 1 }
11
- let(:before_now) { Time.now.to_i - 1 }
12
-
13
- let(:issuer) { 'issuer' }
14
- let(:jwt_id) { 'jwt_id' }
15
- let(:subject) { 'subject' }
16
-
17
- let(:default_options) do
18
- {
19
- aud: uri,
20
- iss: issuer,
21
- jti: jwt_id,
22
- sub: subject,
23
- leeway_seconds: 120
24
- }
25
- end
26
- let(:default_claims) do
27
- {
28
- aud: [uri, recipient],
29
- exp: after_now,
30
- iat: before_now,
31
- iss: issuer,
32
- jti: jwt_id,
33
- nbf: before_now,
34
- sub: subject
35
- }
36
- end
37
- context '#rejected' do
38
- it 'w valid claims, returns empty array' do
39
- expect(Validation.rejected default_claims, default_options).to eql []
40
- end
41
-
42
- describe 'w all registered claims invalid' do
43
- let(:invalid_claims) do
44
- {
45
- aud: ['http://www.other.com', 'other recipient'],
46
- exp: before_now - 121, # two minute leeway
47
- iat: after_now,
48
- iss: 'other issuer',
49
- jti: 'other jwt_id',
50
- nbf: after_now + 121,
51
- sub: 'other subject'
52
- }
53
- end
54
- it 'returns array of failed claims' do
55
- expect(Validation.rejected invalid_claims, default_options)
56
- .to include(
57
- :aud,
58
- :exp,
59
- :iat,
60
- :iss,
61
- :jti,
62
- :nbf,
63
- :sub
64
- )
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,50 +0,0 @@
1
- require 'jwt_claims'
2
-
3
- describe JwtClaims do
4
- let(:after_now) { Time.now.to_i + 1 }
5
- let(:before_now) { Time.now.to_i - 1 }
6
- context '#verify' do
7
- describe 'JsonWebToken integration w :exp claim before now' do
8
- let(:jwt_w_exp_before_now_w_iss_joe) do
9
- "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLCJodHRwOi8vZXhhbXBsZS5jb20vaXNfcm9vdCI6dHJ1ZSwiZXhwIjoxMzAwODE5MzgwfQ.Ktfu3EdLz0SpuTIMpMoRZMtZsCATWJHeDEBGrsZE6LI"
10
- end
11
- let(:hs256_key) { "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C" }
12
- it 'w :iss claim matching' do
13
- options = {iss: 'joe', key: hs256_key}
14
- rejected_claims = JwtClaims.verify(jwt_w_exp_before_now_w_iss_joe, options)[:error]
15
- expect(rejected_claims.length).to eql 1
16
- expect(rejected_claims).to include(:exp)
17
- end
18
-
19
- it 'w/o :iss claim matching' do
20
- options = {iss: 'mary', key: hs256_key}
21
- rejected_claims = JwtClaims.verify(jwt_w_exp_before_now_w_iss_joe, options)[:error]
22
- expect(rejected_claims.length).to eql 2
23
- expect(rejected_claims).to include(:exp, :iss)
24
- end
25
- end
26
-
27
- describe 'w invalid JWT' do
28
- let(:invalid_jwt) do
29
- "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJqb2UiLCJodHRwOi8vZXhhbXBsZS5jb20vaXNfcm9vdCI6dHJ1ZSwiZXhwIjoxMzAwODE5MzgwfQ.Ktfu3EdLz0SpuTIMpMoRZMtZsCATWJHeDEBGrsZE6LX"
30
- end
31
- it 'returns error' do
32
- options = {exp: after_now}
33
- error = JwtClaims.verify(invalid_jwt, options)[:error]
34
- expect(error).to eql 'invalid JWT'
35
- end
36
- end
37
- end
38
-
39
- describe '#verified' do
40
- it 'w rejected_claims' do
41
- claims = {exp: before_now}
42
- expect(JwtClaims.verified claims, {}).to include(error: [:exp])
43
- end
44
-
45
- it 'w/o rejected_claims' do
46
- claims = {exp: after_now}
47
- expect(JwtClaims.verified claims, {}).to include(ok: claims)
48
- end
49
- end
50
- end
data/spec/spec_helper.rb DELETED
@@ -1,85 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start
3
-
4
- # Conventionally, all specs live under a `spec` directory, which RSpec adds to
5
- # the `$LOAD_PATH`. The generated `.rspec` file contains `--require spec_helper`
6
- # which will cause this file to always be loaded, without a need to explicitly
7
- # require it in any files.
8
- #
9
- # Given that it is always loaded, you are encouraged to keep this file as
10
- # light-weight as possible. Requiring heavyweight dependencies from this file
11
- # will add to the boot time of your test suite on EVERY test run, even for an
12
- # individual file that may not need all of that loaded. Instead, consider
13
- # making a separate helper file that requires the additional dependencies and
14
- # performs the additional setup, and require it from the spec files that
15
- # actually need it.
16
- #
17
- # The `.rspec` file also contains a few flags that are not defaults but that
18
- # users commonly want.
19
- #
20
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
- RSpec.configure do |config|
22
- config.expect_with :rspec do |expectations|
23
- # This option will default to `true` in RSpec 4. It makes the `description`
24
- # and `failure_message` of custom matchers include text for helper methods
25
- # defined using `chain`, e.g.:
26
- # be_bigger_than(2).and_smaller_than(4).description
27
- # # => "be bigger than 2 and smaller than 4"
28
- # ...rather than:
29
- # # => "be bigger than 2"
30
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
- end
32
-
33
- config.mock_with :rspec do |mocks|
34
- # Prevents you from mocking or stubbing a method that does not exist on
35
- # a real object. This is generally recommended, and will default to
36
- # `true` in RSpec 4.
37
- mocks.verify_partial_doubles = true
38
- end
39
-
40
- # The settings below are suggested to provide a good initial experience
41
- # with RSpec, but feel free to customize to your heart's content.
42
-
43
- # These two settings work together to allow you to limit a spec run to
44
- # individual examples or groups you care about by tagging them with `:focus`
45
- # metadata. When nothing is tagged with `:focus`, all examples get run.
46
- config.filter_run :focus
47
- config.run_all_when_everything_filtered = true
48
-
49
- # Allows RSpec to persist some state between runs in order to support the
50
- # `--only-failures` and `--next-failure` CLI options. We recommend you
51
- # configure your source control system to ignore this file.
52
- config.example_status_persistence_file_path = "spec/examples.txt"
53
-
54
- # Limits the available syntax to the non-monkey patched syntax that is
55
- # recommended. For more details, see:
56
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
57
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
58
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
59
- # config.disable_monkey_patching!
60
-
61
- # Many RSpec users commonly either run the entire suite or an individual
62
- # file, and it's useful to allow more verbose output when running an
63
- # individual spec file.
64
- if config.files_to_run.one?
65
- # Use the documentation formatter for detailed output, unless a formatter
66
- # has already been configured (e.g. via a command-line flag)
67
- config.default_formatter = 'doc'
68
- end
69
-
70
- # Print the 10 slowest examples and example groups at the end of the spec
71
- # run, to help surface which specs are running particularly slowly.
72
- # config.profile_examples = 10
73
-
74
- # Run specs in random order to surface order dependencies. If you find an
75
- # order dependency and want to debug it, you can fix the order by providing
76
- # the seed, which is printed after each run.
77
- # --seed 1234
78
- config.order = :random
79
-
80
- # Seed global randomization in this process using the `--seed` CLI option.
81
- # Setting this allows you to use `--seed` to deterministically reproduce
82
- # test failures related to randomization by passing the same `--seed` value
83
- # as the one that triggered the failure.
84
- Kernel.srand config.seed
85
- end