traitify 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +101 -69
- data/lib/traitify/configuration.rb +6 -5
- data/lib/traitify/error.rb +4 -0
- data/lib/traitify/version.rb +1 -1
- data/lib/traitify.rb +58 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/traitify_spec.rb +242 -0
- data/traitify.gemspec +2 -1
- metadata +23 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1f53da4ace0d1005c2982c0e2681132c21a05e9d9365057eab89e488caf10d4f
|
|
4
|
+
data.tar.gz: be22aff51d262cc2c685cf51b957547ad5e4d0a4d16c4a15b47db7e3913cd130
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ee8e51a6ad407827f7dc68c538278ce1a4f22e1a1891de56e275b8f2267a882c48327055d478b55e9bcc8753498c1ee681b6aff523297bc0c4dd202d13b5288
|
|
7
|
+
data.tar.gz: '08ffb2eabe9e9c7fc92a12ef81a1a03c71eb1fb83061c98819b1861bed669385f278fb30d4f040a611b65cd9a6499f6ce76dedf6e6d7613a5f4d587a19734a98'
|
data/Gemfile.lock
CHANGED
|
@@ -6,115 +6,147 @@ PATH
|
|
|
6
6
|
faraday (~> 2.5)
|
|
7
7
|
faraday-net_http (~> 3.0)
|
|
8
8
|
faraday-retry (~> 2.2)
|
|
9
|
+
jwt (~> 2.0)
|
|
9
10
|
|
|
10
11
|
GEM
|
|
11
12
|
remote: https://rubygems.org/
|
|
12
13
|
specs:
|
|
13
|
-
activesupport (7.1.2)
|
|
14
|
+
activesupport (7.1.5.2)
|
|
14
15
|
base64
|
|
16
|
+
benchmark (>= 0.3)
|
|
15
17
|
bigdecimal
|
|
16
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
17
19
|
connection_pool (>= 2.2.5)
|
|
18
20
|
drb
|
|
19
21
|
i18n (>= 1.6, < 2)
|
|
22
|
+
logger (>= 1.4.2)
|
|
20
23
|
minitest (>= 5.1)
|
|
21
24
|
mutex_m
|
|
25
|
+
securerandom (>= 0.3)
|
|
22
26
|
tzinfo (~> 2.0)
|
|
23
|
-
addressable (2.8.
|
|
24
|
-
public_suffix (>= 2.0.2, <
|
|
25
|
-
ast (2.4.
|
|
26
|
-
base64 (0.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
addressable (2.8.7)
|
|
28
|
+
public_suffix (>= 2.0.2, < 7.0)
|
|
29
|
+
ast (2.4.3)
|
|
30
|
+
base64 (0.3.0)
|
|
31
|
+
benchmark (0.4.1)
|
|
32
|
+
bigdecimal (3.3.0)
|
|
33
|
+
binding_of_caller (1.0.1)
|
|
34
|
+
debug_inspector (>= 1.2.0)
|
|
30
35
|
coderay (1.1.3)
|
|
31
|
-
concurrent-ruby (1.
|
|
32
|
-
connection_pool (2.4
|
|
33
|
-
crack (0.
|
|
36
|
+
concurrent-ruby (1.3.5)
|
|
37
|
+
connection_pool (2.5.4)
|
|
38
|
+
crack (1.0.0)
|
|
39
|
+
bigdecimal
|
|
34
40
|
rexml
|
|
35
|
-
debug_inspector (1.
|
|
36
|
-
diff-lcs (1.
|
|
37
|
-
docile (1.4.
|
|
38
|
-
drb (2.2.
|
|
39
|
-
ruby2_keywords
|
|
41
|
+
debug_inspector (1.2.0)
|
|
42
|
+
diff-lcs (1.6.2)
|
|
43
|
+
docile (1.4.1)
|
|
44
|
+
drb (2.2.3)
|
|
40
45
|
faraday (2.8.1)
|
|
41
46
|
base64
|
|
42
47
|
faraday-net_http (>= 2.0, < 3.1)
|
|
43
48
|
ruby2_keywords (>= 0.0.4)
|
|
44
49
|
faraday-net_http (3.0.2)
|
|
45
|
-
faraday-retry (2.2
|
|
50
|
+
faraday-retry (2.3.2)
|
|
46
51
|
faraday (~> 2.0)
|
|
47
|
-
hashdiff (1.
|
|
48
|
-
i18n (1.14.
|
|
52
|
+
hashdiff (1.2.1)
|
|
53
|
+
i18n (1.14.7)
|
|
49
54
|
concurrent-ruby (~> 1.0)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
json (2.15.1)
|
|
56
|
+
jwt (2.10.2)
|
|
57
|
+
base64
|
|
58
|
+
language_server-protocol (3.17.0.5)
|
|
59
|
+
lint_roller (1.1.0)
|
|
60
|
+
logger (1.7.0)
|
|
61
|
+
method_source (1.1.0)
|
|
62
|
+
minitest (5.25.5)
|
|
63
|
+
mutex_m (0.3.0)
|
|
64
|
+
parallel (1.27.0)
|
|
65
|
+
parser (3.3.9.0)
|
|
55
66
|
ast (~> 2.4.1)
|
|
56
|
-
|
|
67
|
+
racc
|
|
68
|
+
prism (1.5.1)
|
|
69
|
+
pry (0.15.2)
|
|
57
70
|
coderay (~> 1.1)
|
|
58
71
|
method_source (~> 1.0)
|
|
59
|
-
public_suffix (5.
|
|
60
|
-
|
|
72
|
+
public_suffix (5.1.1)
|
|
73
|
+
racc (1.8.1)
|
|
74
|
+
rack (3.1.17)
|
|
61
75
|
rainbow (3.1.1)
|
|
62
|
-
rake (13.0
|
|
63
|
-
regexp_parser (2.
|
|
64
|
-
rexml (3.
|
|
65
|
-
rspec (3.
|
|
66
|
-
rspec-core (~> 3.
|
|
67
|
-
rspec-expectations (~> 3.
|
|
68
|
-
rspec-mocks (~> 3.
|
|
69
|
-
rspec-core (3.
|
|
70
|
-
rspec-support (~> 3.
|
|
71
|
-
rspec-expectations (3.
|
|
76
|
+
rake (13.3.0)
|
|
77
|
+
regexp_parser (2.11.3)
|
|
78
|
+
rexml (3.4.4)
|
|
79
|
+
rspec (3.13.1)
|
|
80
|
+
rspec-core (~> 3.13.0)
|
|
81
|
+
rspec-expectations (~> 3.13.0)
|
|
82
|
+
rspec-mocks (~> 3.13.0)
|
|
83
|
+
rspec-core (3.13.5)
|
|
84
|
+
rspec-support (~> 3.13.0)
|
|
85
|
+
rspec-expectations (3.13.5)
|
|
72
86
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
73
|
-
rspec-support (~> 3.
|
|
74
|
-
rspec-mocks (3.
|
|
87
|
+
rspec-support (~> 3.13.0)
|
|
88
|
+
rspec-mocks (3.13.5)
|
|
75
89
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
76
|
-
rspec-support (~> 3.
|
|
77
|
-
rspec-support (3.
|
|
78
|
-
rubocop (
|
|
90
|
+
rspec-support (~> 3.13.0)
|
|
91
|
+
rspec-support (3.13.6)
|
|
92
|
+
rubocop (1.81.1)
|
|
93
|
+
json (~> 2.3)
|
|
94
|
+
language_server-protocol (~> 3.17.0.2)
|
|
95
|
+
lint_roller (~> 1.1.0)
|
|
79
96
|
parallel (~> 1.10)
|
|
80
|
-
parser (>=
|
|
97
|
+
parser (>= 3.3.0.2)
|
|
81
98
|
rainbow (>= 2.2.2, < 4.0)
|
|
82
|
-
regexp_parser (>=
|
|
83
|
-
|
|
84
|
-
rubocop-ast (>= 0.6.0)
|
|
99
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
100
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
85
101
|
ruby-progressbar (~> 1.7)
|
|
86
|
-
unicode-display_width (>=
|
|
87
|
-
rubocop-airbnb (
|
|
88
|
-
|
|
89
|
-
rubocop
|
|
90
|
-
rubocop-
|
|
91
|
-
rubocop-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
102
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
103
|
+
rubocop-airbnb (8.0.0)
|
|
104
|
+
lint_roller (~> 1.1)
|
|
105
|
+
rubocop (~> 1.72)
|
|
106
|
+
rubocop-capybara (~> 2.22)
|
|
107
|
+
rubocop-factory_bot (~> 2.27)
|
|
108
|
+
rubocop-performance (~> 1.24)
|
|
109
|
+
rubocop-rails (~> 2.30)
|
|
110
|
+
rubocop-rspec (~> 3.5)
|
|
111
|
+
rubocop-ast (1.47.1)
|
|
112
|
+
parser (>= 3.3.7.2)
|
|
113
|
+
prism (~> 1.4)
|
|
114
|
+
rubocop-capybara (2.22.1)
|
|
115
|
+
lint_roller (~> 1.1)
|
|
116
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
117
|
+
rubocop-factory_bot (2.27.1)
|
|
118
|
+
lint_roller (~> 1.1)
|
|
119
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
120
|
+
rubocop-performance (1.26.0)
|
|
121
|
+
lint_roller (~> 1.1)
|
|
122
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
123
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
|
124
|
+
rubocop-rails (2.33.4)
|
|
98
125
|
activesupport (>= 4.2.0)
|
|
126
|
+
lint_roller (~> 1.1)
|
|
99
127
|
rack (>= 1.1)
|
|
100
|
-
rubocop (>=
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
128
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
129
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
|
130
|
+
rubocop-rspec (3.7.0)
|
|
131
|
+
lint_roller (~> 1.1)
|
|
132
|
+
rubocop (~> 1.72, >= 1.72.1)
|
|
133
|
+
rubocop-traitify (1.3.0)
|
|
134
|
+
rubocop-airbnb (~> 8.0.0)
|
|
135
|
+
ruby-progressbar (1.13.0)
|
|
107
136
|
ruby2_keywords (0.0.5)
|
|
137
|
+
securerandom (0.3.2)
|
|
108
138
|
simplecov (0.21.2)
|
|
109
139
|
docile (~> 1.1)
|
|
110
140
|
simplecov-html (~> 0.11)
|
|
111
141
|
simplecov_json_formatter (~> 0.1)
|
|
112
|
-
simplecov-html (0.
|
|
142
|
+
simplecov-html (0.13.2)
|
|
113
143
|
simplecov_json_formatter (0.1.4)
|
|
114
144
|
tzinfo (2.0.6)
|
|
115
145
|
concurrent-ruby (~> 1.0)
|
|
116
|
-
unicode-display_width (
|
|
117
|
-
|
|
146
|
+
unicode-display_width (3.2.0)
|
|
147
|
+
unicode-emoji (~> 4.1)
|
|
148
|
+
unicode-emoji (4.1.0)
|
|
149
|
+
webmock (3.25.1)
|
|
118
150
|
addressable (>= 2.8.0)
|
|
119
151
|
crack (>= 0.3.2)
|
|
120
152
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
@@ -136,4 +168,4 @@ DEPENDENCIES
|
|
|
136
168
|
webmock (~> 3.18)
|
|
137
169
|
|
|
138
170
|
BUNDLED WITH
|
|
139
|
-
2.
|
|
171
|
+
2.3.16
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
module Traitify
|
|
2
2
|
module Configuration
|
|
3
3
|
VALID_OPTIONS_KEYS = [
|
|
4
|
-
:host,
|
|
5
|
-
:public_key,
|
|
6
|
-
:secret_key,
|
|
7
|
-
:version,
|
|
8
4
|
:auto_retry,
|
|
9
5
|
:deck_id,
|
|
6
|
+
:host,
|
|
10
7
|
:image_pack,
|
|
8
|
+
:jwt_public_keys,
|
|
11
9
|
:locale_key,
|
|
12
|
-
:
|
|
10
|
+
:public_key,
|
|
11
|
+
:retry_options,
|
|
12
|
+
:secret_key,
|
|
13
|
+
:version
|
|
13
14
|
].freeze
|
|
14
15
|
|
|
15
16
|
attr_accessor(*VALID_OPTIONS_KEYS)
|
data/lib/traitify/error.rb
CHANGED
data/lib/traitify/version.rb
CHANGED
data/lib/traitify.rb
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
require "active_support"
|
|
2
2
|
require "active_support/core_ext/object/deep_dup"
|
|
3
|
+
require "ostruct"
|
|
4
|
+
require "jwt"
|
|
5
|
+
require "openssl"
|
|
3
6
|
require "traitify/configuration"
|
|
4
7
|
require "traitify/client"
|
|
5
8
|
require "traitify/data"
|
|
@@ -33,9 +36,64 @@ module Traitify
|
|
|
33
36
|
case level
|
|
34
37
|
when :debug
|
|
35
38
|
logger.debug message
|
|
39
|
+
when :warn
|
|
40
|
+
logger.warn message
|
|
41
|
+
when :error
|
|
42
|
+
logger.error message
|
|
36
43
|
else
|
|
37
44
|
logger.info message
|
|
38
45
|
end
|
|
39
46
|
end
|
|
47
|
+
|
|
48
|
+
def valid_jwt_token?(token)
|
|
49
|
+
algorithm = "RS256"
|
|
50
|
+
return false unless jwt_public_keys && jwt_public_keys.any?
|
|
51
|
+
|
|
52
|
+
public_keys = jwt_public_keys.map { |key| OpenSSL::PKey::RSA.new(key) }
|
|
53
|
+
|
|
54
|
+
public_keys.each do |public_key|
|
|
55
|
+
decoded_token = JWT.decode(token, public_key, true, {
|
|
56
|
+
algorithm: algorithm,
|
|
57
|
+
iss: "Traitify by Paradox",
|
|
58
|
+
verify_iss: true,
|
|
59
|
+
verify_iat: true,
|
|
60
|
+
verify_nbf: true,
|
|
61
|
+
verify_jti: true
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
payload = decoded_token[0]
|
|
65
|
+
validate_claims(payload)
|
|
66
|
+
return true
|
|
67
|
+
rescue JWT::ExpiredSignature, JWT::DecodeError, JWT::VerificationError => e
|
|
68
|
+
log(:warn, "[JWT] #{e.class.name}: #{e.message}")
|
|
69
|
+
next
|
|
70
|
+
rescue => e
|
|
71
|
+
log(:error, "[JWT] Unexpected error: #{e.class} - #{e.message}")
|
|
72
|
+
next
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
false
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
private
|
|
79
|
+
|
|
80
|
+
def validate_claims(payload)
|
|
81
|
+
current_time = Time.now.to_i
|
|
82
|
+
|
|
83
|
+
iat_value = payload["iat"] || payload[:iat]
|
|
84
|
+
if iat_value && iat_value > current_time
|
|
85
|
+
raise JWT::InvalidIatError.new("Token issued in the future")
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
nbf_value = payload["nbf"] || payload[:nbf]
|
|
89
|
+
if nbf_value && nbf_value > current_time
|
|
90
|
+
raise JWT::DecodeError.new("Token not yet valid")
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
jti_value = payload["jti"] || payload[:jti]
|
|
94
|
+
if jti_value.nil? || jti_value.empty?
|
|
95
|
+
raise JWT::DecodeError.new("Missing JWT ID (jti)")
|
|
96
|
+
end
|
|
97
|
+
end
|
|
40
98
|
end
|
|
41
99
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
require "spec_helper"
|
|
2
|
+
|
|
3
|
+
describe Traitify do
|
|
4
|
+
describe ".valid_jwt_token?" do
|
|
5
|
+
let(:private_key){ OpenSSL::PKey::RSA.new(2048) }
|
|
6
|
+
let(:public_key){ private_key.public_key }
|
|
7
|
+
let(:valid_payload) do
|
|
8
|
+
{
|
|
9
|
+
iss: "Traitify by Paradox",
|
|
10
|
+
iat: Time.now.to_i,
|
|
11
|
+
nbf: Time.now.to_i,
|
|
12
|
+
jti: "unique-token-id"
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
before do
|
|
17
|
+
Traitify.jwt_public_keys = [public_key.to_pem]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
after do
|
|
21
|
+
Traitify.jwt_public_keys = nil
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context "with valid token" do
|
|
25
|
+
let(:valid_token) do
|
|
26
|
+
JWT.encode(valid_payload, private_key, "RS256")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "returns true" do
|
|
30
|
+
expect(Traitify.valid_jwt_token?(valid_token)).to be true
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context "with invalid signature" do
|
|
35
|
+
let(:invalid_token) do
|
|
36
|
+
other_private_key = OpenSSL::PKey::RSA.new(2048)
|
|
37
|
+
JWT.encode(valid_payload, other_private_key, "RS256")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "returns false" do
|
|
41
|
+
expect(Traitify.valid_jwt_token?(invalid_token)).to be false
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "with malformed token" do
|
|
46
|
+
let(:malformed_token){ "not.a.valid.jwt" }
|
|
47
|
+
|
|
48
|
+
it "returns false" do
|
|
49
|
+
expect(Traitify.valid_jwt_token?(malformed_token)).to be false
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "with expired token" do
|
|
54
|
+
let(:expired_payload) do
|
|
55
|
+
valid_payload.merge(iat: 1.hour.ago.to_i, exp: 1.hour.ago.to_i)
|
|
56
|
+
end
|
|
57
|
+
let(:expired_token) do
|
|
58
|
+
JWT.encode(expired_payload, private_key, "RS256")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "returns false" do
|
|
62
|
+
expect(Traitify.valid_jwt_token?(expired_token)).to be false
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
context "with wrong issuer" do
|
|
67
|
+
let(:wrong_issuer_payload) do
|
|
68
|
+
valid_payload.merge(iss: "Wrong Issuer")
|
|
69
|
+
end
|
|
70
|
+
let(:wrong_issuer_token) do
|
|
71
|
+
JWT.encode(wrong_issuer_payload, private_key, "RS256")
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "returns false" do
|
|
75
|
+
expect(Traitify.valid_jwt_token?(wrong_issuer_token)).to be false
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context "with multiple public keys" do
|
|
80
|
+
let(:legacy_private_key){ OpenSSL::PKey::RSA.new(2048) }
|
|
81
|
+
let(:legacy_public_key){ legacy_private_key.public_key }
|
|
82
|
+
|
|
83
|
+
before do
|
|
84
|
+
Traitify.jwt_public_keys = [public_key.to_pem, legacy_public_key.to_pem]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context "when token is signed with current key" do
|
|
88
|
+
let(:current_token) do
|
|
89
|
+
JWT.encode(valid_payload, private_key, "RS256")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
it "returns true" do
|
|
93
|
+
expect(Traitify.valid_jwt_token?(current_token)).to be true
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
context "when token is signed with legacy key" do
|
|
98
|
+
let(:legacy_token) do
|
|
99
|
+
JWT.encode(valid_payload, legacy_private_key, "RS256")
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "returns true" do
|
|
103
|
+
expect(Traitify.valid_jwt_token?(legacy_token)).to be true
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context "with future iat" do
|
|
109
|
+
let(:future_iat_payload) do
|
|
110
|
+
{
|
|
111
|
+
iss: "Traitify by Paradox",
|
|
112
|
+
iat: Time.now.to_i + 100,
|
|
113
|
+
nbf: Time.now.to_i - 50,
|
|
114
|
+
jti: "unique-token-id"
|
|
115
|
+
}
|
|
116
|
+
end
|
|
117
|
+
let(:future_iat_token) do
|
|
118
|
+
JWT.encode(future_iat_payload, private_key, "RS256")
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "returns false" do
|
|
122
|
+
expect(Traitify.valid_jwt_token?(future_iat_token)).to be false
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
context "with future nbf" do
|
|
127
|
+
let(:future_nbf_payload) do
|
|
128
|
+
{
|
|
129
|
+
iss: "Traitify by Paradox",
|
|
130
|
+
iat: Time.now.to_i - 100,
|
|
131
|
+
nbf: Time.now.to_i + 50,
|
|
132
|
+
jti: "unique-token-id"
|
|
133
|
+
}
|
|
134
|
+
end
|
|
135
|
+
let(:future_nbf_token) do
|
|
136
|
+
JWT.encode(future_nbf_payload, private_key, "RS256")
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "returns false" do
|
|
140
|
+
expect(Traitify.valid_jwt_token?(future_nbf_token)).to be false
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
context "with missing jti" do
|
|
145
|
+
let(:missing_jti_payload) do
|
|
146
|
+
{
|
|
147
|
+
iss: "Traitify by Paradox",
|
|
148
|
+
iat: Time.now.to_i - 100,
|
|
149
|
+
nbf: Time.now.to_i - 50
|
|
150
|
+
}
|
|
151
|
+
end
|
|
152
|
+
let(:missing_jti_token) do
|
|
153
|
+
JWT.encode(missing_jti_payload, private_key, "RS256")
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "returns false" do
|
|
157
|
+
expect(Traitify.valid_jwt_token?(missing_jti_token)).to be false
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
context "with blank jti" do
|
|
162
|
+
let(:blank_jti_payload) do
|
|
163
|
+
{
|
|
164
|
+
iss: "Traitify by Paradox",
|
|
165
|
+
iat: Time.now.to_i - 100,
|
|
166
|
+
nbf: Time.now.to_i - 50,
|
|
167
|
+
jti: ""
|
|
168
|
+
}
|
|
169
|
+
end
|
|
170
|
+
let(:blank_jti_token) do
|
|
171
|
+
JWT.encode(blank_jti_payload, private_key, "RS256")
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
it "returns false" do
|
|
175
|
+
expect(Traitify.valid_jwt_token?(blank_jti_token)).to be false
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
context "with nil jti" do
|
|
180
|
+
let(:nil_jti_payload) do
|
|
181
|
+
{
|
|
182
|
+
iss: "Traitify by Paradox",
|
|
183
|
+
iat: Time.now.to_i - 100,
|
|
184
|
+
nbf: Time.now.to_i - 50,
|
|
185
|
+
jti: nil
|
|
186
|
+
}
|
|
187
|
+
end
|
|
188
|
+
let(:nil_jti_token) do
|
|
189
|
+
JWT.encode(nil_jti_payload, private_key, "RS256")
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "returns false" do
|
|
193
|
+
expect(Traitify.valid_jwt_token?(nil_jti_token)).to be false
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
context "with missing iat" do
|
|
198
|
+
let(:missing_iat_payload) do
|
|
199
|
+
{
|
|
200
|
+
iss: "Traitify by Paradox",
|
|
201
|
+
nbf: Time.now.to_i - 50,
|
|
202
|
+
jti: "unique-token-id"
|
|
203
|
+
}
|
|
204
|
+
end
|
|
205
|
+
let(:missing_iat_token) do
|
|
206
|
+
JWT.encode(missing_iat_payload, private_key, "RS256")
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it "returns true" do
|
|
210
|
+
expect(Traitify.valid_jwt_token?(missing_iat_token)).to be true
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
context "with missing nbf" do
|
|
215
|
+
let(:missing_nbf_payload) do
|
|
216
|
+
{
|
|
217
|
+
iss: "Traitify by Paradox",
|
|
218
|
+
iat: Time.now.to_i - 100,
|
|
219
|
+
jti: "unique-token-id"
|
|
220
|
+
}
|
|
221
|
+
end
|
|
222
|
+
let(:missing_nbf_token) do
|
|
223
|
+
JWT.encode(missing_nbf_payload, private_key, "RS256")
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
it "returns true" do
|
|
227
|
+
expect(Traitify.valid_jwt_token?(missing_nbf_token)).to be true
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
context "when no public keys are configured" do
|
|
232
|
+
before do
|
|
233
|
+
Traitify.jwt_public_keys = nil
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
it "returns false" do
|
|
237
|
+
expect(Traitify.valid_jwt_token?("any.token")).to be false
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
data/traitify.gemspec
CHANGED
|
@@ -22,13 +22,14 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.add_runtime_dependency "faraday", "~> 2.5"
|
|
23
23
|
spec.add_runtime_dependency "faraday-net_http", "~> 3.0"
|
|
24
24
|
spec.add_runtime_dependency "faraday-retry", "~> 2.2"
|
|
25
|
+
spec.add_runtime_dependency "jwt", "~> 2.0"
|
|
25
26
|
|
|
26
27
|
spec.add_development_dependency "binding_of_caller", "~> 1.0"
|
|
27
28
|
spec.add_development_dependency "bundler", "~> 2.2"
|
|
28
29
|
spec.add_development_dependency "pry", "~> 0.14"
|
|
29
30
|
spec.add_development_dependency "rake", "~> 13.0"
|
|
30
31
|
spec.add_development_dependency "rspec", "~> 3.11"
|
|
31
|
-
spec.add_development_dependency "rubocop-traitify", "~> 1.
|
|
32
|
+
spec.add_development_dependency "rubocop-traitify", "~> 1.2"
|
|
32
33
|
spec.add_development_dependency "simplecov", "~> 0.21.2"
|
|
33
34
|
spec.add_development_dependency "webmock", "~> 3.18"
|
|
34
35
|
end
|
metadata
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: traitify
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom Prats
|
|
8
8
|
- Eric Fleming
|
|
9
9
|
- Carson Wright
|
|
10
|
-
autorequire:
|
|
10
|
+
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2026-01-14 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activesupport
|
|
@@ -74,6 +74,20 @@ dependencies:
|
|
|
74
74
|
- - "~>"
|
|
75
75
|
- !ruby/object:Gem::Version
|
|
76
76
|
version: '2.2'
|
|
77
|
+
- !ruby/object:Gem::Dependency
|
|
78
|
+
name: jwt
|
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - "~>"
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '2.0'
|
|
84
|
+
type: :runtime
|
|
85
|
+
prerelease: false
|
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - "~>"
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: '2.0'
|
|
77
91
|
- !ruby/object:Gem::Dependency
|
|
78
92
|
name: binding_of_caller
|
|
79
93
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -150,14 +164,14 @@ dependencies:
|
|
|
150
164
|
requirements:
|
|
151
165
|
- - "~>"
|
|
152
166
|
- !ruby/object:Gem::Version
|
|
153
|
-
version: '1.
|
|
167
|
+
version: '1.2'
|
|
154
168
|
type: :development
|
|
155
169
|
prerelease: false
|
|
156
170
|
version_requirements: !ruby/object:Gem::Requirement
|
|
157
171
|
requirements:
|
|
158
172
|
- - "~>"
|
|
159
173
|
- !ruby/object:Gem::Version
|
|
160
|
-
version: '1.
|
|
174
|
+
version: '1.2'
|
|
161
175
|
- !ruby/object:Gem::Dependency
|
|
162
176
|
name: simplecov
|
|
163
177
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -255,12 +269,13 @@ files:
|
|
|
255
269
|
- spec/traitify/error_spec.rb
|
|
256
270
|
- spec/traitify/response_spec.rb
|
|
257
271
|
- spec/traitify/version_spec.rb
|
|
272
|
+
- spec/traitify_spec.rb
|
|
258
273
|
- traitify.gemspec
|
|
259
274
|
homepage: https://www.traitify.com
|
|
260
275
|
licenses:
|
|
261
276
|
- MIT
|
|
262
277
|
metadata: {}
|
|
263
|
-
post_install_message:
|
|
278
|
+
post_install_message:
|
|
264
279
|
rdoc_options: []
|
|
265
280
|
require_paths:
|
|
266
281
|
- lib
|
|
@@ -276,7 +291,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
276
291
|
version: '0'
|
|
277
292
|
requirements: []
|
|
278
293
|
rubygems_version: 3.1.4
|
|
279
|
-
signing_key:
|
|
294
|
+
signing_key:
|
|
280
295
|
specification_version: 4
|
|
281
296
|
summary: Traitify Gem
|
|
282
297
|
test_files:
|
|
@@ -321,3 +336,4 @@ test_files:
|
|
|
321
336
|
- spec/traitify/error_spec.rb
|
|
322
337
|
- spec/traitify/response_spec.rb
|
|
323
338
|
- spec/traitify/version_spec.rb
|
|
339
|
+
- spec/traitify_spec.rb
|