castle-rb 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/castle-rb.rb +0 -5
- data/lib/castle-rb/version.rb +1 -1
- data/spec/models/user_spec.rb +0 -27
- metadata +15 -35
- data/lib/castle-rb/jwt.rb +0 -34
- data/spec/models/challenge_spec.rb +0 -18
- data/spec/models/session_spec.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 515b2d0525aa3a9c503718710f8f6ad603d26d7e
|
4
|
+
data.tar.gz: d8019db012e15fcf4f422091e4989f47c784662f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ea61acff364b45b8048362fa1ec5e4249006ad03b4d07434ed4ef056e5a703677ad663d2881022b270c27e5966c1cb1312c442a960df0639a848397852aa788
|
7
|
+
data.tar.gz: 3aab08d752b931956c7a44fcda4734fc14ac65a2915616d9994872a5f71275c6db614606ede1481be9f03bbedd766923b7b17f1e937929aad778c972c14a9e92
|
data/lib/castle-rb.rb
CHANGED
@@ -12,7 +12,6 @@ require 'castle-rb/version'
|
|
12
12
|
require 'castle-rb/configuration'
|
13
13
|
require 'castle-rb/client'
|
14
14
|
require 'castle-rb/errors'
|
15
|
-
require 'castle-rb/jwt'
|
16
15
|
require 'castle-rb/utils'
|
17
16
|
require 'castle-rb/request'
|
18
17
|
|
@@ -28,10 +27,6 @@ end
|
|
28
27
|
|
29
28
|
module Castle
|
30
29
|
API = Castle.setup_api
|
31
|
-
|
32
|
-
def self.secure_encode(properties = {})
|
33
|
-
::JWT.encode(properties, Castle.config.api_secret)
|
34
|
-
end
|
35
30
|
end
|
36
31
|
|
37
32
|
# These need to be required after setting up Her
|
data/lib/castle-rb/version.rb
CHANGED
data/spec/models/user_spec.rb
CHANGED
@@ -1,31 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe 'Castle::User' do
|
4
|
-
it 'retrieves a user' do
|
5
|
-
VCR.use_cassette('user_find') do
|
6
|
-
user = Castle::User.find('9RA2j3cYDxt8gefQUduKnxUxRRGy6Rz4')
|
7
|
-
user.email.should == 'brissmyr@gmail.com'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'handles non-existing user' do
|
12
|
-
VCR.use_cassette('user_find_non_existing') do
|
13
|
-
error = nil
|
14
|
-
begin
|
15
|
-
user = Castle::User.find('non_existing')
|
16
|
-
rescue Castle::Error => e
|
17
|
-
error = e
|
18
|
-
end
|
19
|
-
error.to_s.should match /Not found/
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'updates a user' do
|
24
|
-
VCR.use_cassette('user_update') do
|
25
|
-
user = Castle::User.new(id: 'AKfwtfrAzdDKp55aty8o14MoudkaS9BL')
|
26
|
-
user.email = 'updated@example.com'
|
27
|
-
user.created_at = Time.now
|
28
|
-
user.save
|
29
|
-
end
|
30
|
-
end
|
31
4
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: castle-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johan Brissmyr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: her
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: jwt
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.2.0
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.2.0
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: request_store
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,84 +70,84 @@ dependencies:
|
|
84
70
|
name: activesupport
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
|
-
- - "
|
73
|
+
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
75
|
version: '3'
|
90
76
|
type: :runtime
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
|
-
- - "
|
80
|
+
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: '3'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: rspec
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
|
-
- - "
|
87
|
+
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
89
|
version: '0'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
|
-
- - "
|
94
|
+
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '0'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
98
|
name: rack
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
|
-
- - "
|
101
|
+
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: '0'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
|
-
- - "
|
108
|
+
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
110
|
version: '0'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: webmock
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
|
-
- - "
|
115
|
+
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
117
|
version: '0'
|
132
118
|
type: :development
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
|
-
- - "
|
122
|
+
- - "~>"
|
137
123
|
- !ruby/object:Gem::Version
|
138
124
|
version: '0'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: vcr
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
|
-
- - "
|
129
|
+
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
131
|
version: '0'
|
146
132
|
type: :development
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
|
-
- - "
|
136
|
+
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
138
|
version: '0'
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: timecop
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
156
142
|
requirements:
|
157
|
-
- - "
|
143
|
+
- - "~>"
|
158
144
|
- !ruby/object:Gem::Version
|
159
145
|
version: '0'
|
160
146
|
type: :development
|
161
147
|
prerelease: false
|
162
148
|
version_requirements: !ruby/object:Gem::Requirement
|
163
149
|
requirements:
|
164
|
-
- - "
|
150
|
+
- - "~>"
|
165
151
|
- !ruby/object:Gem::Version
|
166
152
|
version: '0'
|
167
153
|
- !ruby/object:Gem::Dependency
|
@@ -178,8 +164,7 @@ dependencies:
|
|
178
164
|
- - "~>"
|
179
165
|
- !ruby/object:Gem::Version
|
180
166
|
version: 0.7.2
|
181
|
-
description: Secure your authentication stack with
|
182
|
-
notifying you and your users on potential account hijacks
|
167
|
+
description: Secure your authentication stack with user account monitoring
|
183
168
|
email: johan@castle.io
|
184
169
|
executables: []
|
185
170
|
extensions: []
|
@@ -191,7 +176,6 @@ files:
|
|
191
176
|
- lib/castle-rb/configuration.rb
|
192
177
|
- lib/castle-rb/errors.rb
|
193
178
|
- lib/castle-rb/ext/her.rb
|
194
|
-
- lib/castle-rb/jwt.rb
|
195
179
|
- lib/castle-rb/models/account.rb
|
196
180
|
- lib/castle-rb/models/context.rb
|
197
181
|
- lib/castle-rb/models/event.rb
|
@@ -205,8 +189,6 @@ files:
|
|
205
189
|
- lib/castle-rb/support/sinatra.rb
|
206
190
|
- lib/castle-rb/utils.rb
|
207
191
|
- lib/castle-rb/version.rb
|
208
|
-
- spec/models/challenge_spec.rb
|
209
|
-
- spec/models/session_spec.rb
|
210
192
|
- spec/models/user_spec.rb
|
211
193
|
- spec/spec_helper.rb
|
212
194
|
homepage: https://castle.io
|
@@ -234,7 +216,5 @@ signing_key:
|
|
234
216
|
specification_version: 4
|
235
217
|
summary: Castle
|
236
218
|
test_files:
|
237
|
-
- spec/models/challenge_spec.rb
|
238
|
-
- spec/models/session_spec.rb
|
239
219
|
- spec/models/user_spec.rb
|
240
220
|
- spec/spec_helper.rb
|
data/lib/castle-rb/jwt.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'jwt'
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
class JWT
|
5
|
-
attr_accessor :header, :payload
|
6
|
-
|
7
|
-
def initialize(jwt)
|
8
|
-
begin
|
9
|
-
raise Castle::SecurityError, 'Empty JWT' unless jwt
|
10
|
-
@payload, @header = ::JWT.decode(jwt, Castle.config.api_secret, true)
|
11
|
-
@payload = @payload.with_indifferent_access
|
12
|
-
rescue ::JWT::DecodeError => e
|
13
|
-
raise Castle::SecurityError.new(e)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def expired?
|
18
|
-
Time.now.utc > Time.at(@header['exp']).utc
|
19
|
-
end
|
20
|
-
|
21
|
-
def merge!(payload = {})
|
22
|
-
@payload.merge!(payload)
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_json
|
26
|
-
@payload
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_token
|
30
|
-
::JWT.encode(@payload, Castle.config.api_secret, "HS256", @header)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Castle::Challenge' do
|
4
|
-
xit 'creates a challenge' do
|
5
|
-
VCR.use_cassette('challenge_create') do
|
6
|
-
challenge = Castle::Challenge.post(
|
7
|
-
"users/dTxR68nzuRXT4wrB2HJ4hanYtcaGSz2y/challenges")
|
8
|
-
challenge.channel.token.id.should == 'VVG3qirUxy8mUSkmzy3QpPcuhLN1JY4r'
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
xit 'verifies a challenge' do
|
13
|
-
VCR.use_cassette('challenge_verify') do
|
14
|
-
challenge = Castle::Challenge.new(id: 'UWwy5FrWf9DTeoTpJz1LpBp4dPkWZ2Ne')
|
15
|
-
challenge.verify(response: '000000')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/spec/models/session_spec.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'Castle::Session' do
|
4
|
-
let(:session_token) { 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlzcyI6InVzZXItMjQxMiIsInN1YiI6IlMyb2R4UmVabkdxaHF4UGFRN1Y3a05rTG9Ya0daUEZ6IiwiYXVkIjoiODAwMDAwMDAwMDAwMDAwIiwiZXhwIjoxMzk5NDc5Njc1LCJpYXQiOjEzOTk0Nzk2NjUsImp0aSI6MH0.eyJjaGFsbGVuZ2UiOnsiaWQiOiJUVENqd3VyM3lwbTRUR1ZwWU43cENzTXFxOW9mWEVBSCIsInR5cGUiOiJvdHBfYXV0aGVudGljYXRvciJ9fQ.LT9mUzJEbsizbFxcpMo3zbms0aCDBzfgMbveMGSi1-s' }
|
5
|
-
|
6
|
-
xit 'creates a session' do
|
7
|
-
VCR.use_cassette('session_create') do
|
8
|
-
user_id = 'user-2412'
|
9
|
-
session = Castle::Session.post(
|
10
|
-
"users/#{user_id}/sessions", user: {email: 'valid@example.com'})
|
11
|
-
Castle::JWT.new(session.token).header['iss'].should == user_id
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|