scim_rails 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,9 @@ FactoryBot.define do
2
2
  factory :company do
3
3
  name { "Test Company" }
4
4
  subdomain { "test" }
5
- api_token { "1" }
5
+
6
+ after(:build) do |company|
7
+ company.api_token = ScimRails::Encoder.encode(company)
8
+ end
6
9
  end
7
10
  end
@@ -0,0 +1,62 @@
1
+ require "spec_helper"
2
+
3
+ describe ScimRails::Encoder do
4
+ let(:company) { Company.new(subdomain: "test") }
5
+
6
+ describe "::encode" do
7
+ context "with signing configuration" do
8
+ it "generates a signed token with the company attribute" do
9
+ token = ScimRails::Encoder.encode(company)
10
+ payload = ScimRails::Encoder.decode(token)
11
+
12
+ expect(token).to match /[a-z|A-Z|0-9.]{16,}\.[a-z|A-Z|0-9.]{16,}/
13
+ expect(payload).to contain_exactly(["iat", Integer], ["subdomain", "test"])
14
+ end
15
+ end
16
+
17
+ context "without signing configuration" do
18
+ before do
19
+ allow(ScimRails.config).to receive(:signing_secret).and_return(nil)
20
+ allow(ScimRails.config).to receive(:signing_algorithm).and_return(ScimRails::Config::ALGO_NONE)
21
+ end
22
+
23
+ it "generates an unsigned token with the company attribute" do
24
+ token = ScimRails::Encoder.encode(company)
25
+ payload = ScimRails::Encoder.decode(token)
26
+
27
+ expect(token).to match /[a-z|A-Z|0-9.]{16,}/
28
+ expect(payload).to contain_exactly(["iat", Integer], ["subdomain", "test"])
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "::decode" do
34
+ let(:token) { ScimRails::Encoder.encode(company) }
35
+
36
+ it "raises InvalidCredentials error for an invalid token" do
37
+ token = "f487bf84bfub4f74fj4894fnh483f4h4u8f"
38
+ expect { ScimRails::Encoder.decode(token) }.to raise_error ScimRails::ExceptionHandler::InvalidCredentials
39
+ end
40
+
41
+ context "with signing configuration" do
42
+ it "decodes a signed token, returning the company attributes" do
43
+ payload = ScimRails::Encoder.decode(token)
44
+
45
+ expect(payload).to contain_exactly(["iat", Integer], ["subdomain", "test"])
46
+ end
47
+ end
48
+
49
+ context "without signing configuration" do
50
+ before do
51
+ allow(ScimRails.config).to receive(:signing_secret).and_return(nil)
52
+ allow(ScimRails.config).to receive(:signing_algorithm).and_return(ScimRails::Config::ALGO_NONE)
53
+ end
54
+
55
+ it "decodes an unsigned token, returning the company attributes" do
56
+ payload = ScimRails::Encoder.decode(token)
57
+
58
+ expect(payload).to contain_exactly(["iat", Integer], ["subdomain", "test"])
59
+ end
60
+ end
61
+ end
62
+ end
@@ -10,6 +10,9 @@ ScimRails.configure do |config|
10
10
  config.scim_users_scope = :users
11
11
  config.scim_users_list_order = :id
12
12
 
13
+ config.signing_algorithm = "HS256"
14
+ config.signing_secret = "2d6806dd11c2fece2e81b8ca76dcb0062f5b08e28e3264e8ba1c44bbd3578b70"
15
+
13
16
  config.user_deprovision_method = :archive!
14
17
  config.user_reprovision_method = :unarchive!
15
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scim_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spencer Alan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-02 00:00:00.000000000 Z
11
+ date: 2019-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,6 +30,20 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '6.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: jwt
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 1.5.1
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 1.5.1
33
47
  - !ruby/object:Gem::Dependency
34
48
  name: bundler
35
49
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +146,7 @@ files:
132
146
  - lib/generators/scim_rails/templates/initializer.rb
133
147
  - lib/scim_rails.rb
134
148
  - lib/scim_rails/config.rb
149
+ - lib/scim_rails/encoder.rb
135
150
  - lib/scim_rails/engine.rb
136
151
  - lib/scim_rails/version.rb
137
152
  - lib/tasks/scim_rails_tasks.rake
@@ -201,6 +216,7 @@ files:
201
216
  - spec/dummy/tmp/restart.txt
202
217
  - spec/factories/company.rb
203
218
  - spec/factories/user.rb
219
+ - spec/lib/scim_rails/encoder_spec.rb
204
220
  - spec/spec_helper.rb
205
221
  - spec/support/auth_helper.rb
206
222
  - spec/support/factory_bot.rb
@@ -297,5 +313,6 @@ test_files:
297
313
  - spec/support/scim_rails_config.rb
298
314
  - spec/factories/company.rb
299
315
  - spec/factories/user.rb
316
+ - spec/lib/scim_rails/encoder_spec.rb
300
317
  - spec/controllers/scim_rails/scim_users_request_spec.rb
301
318
  - spec/controllers/scim_rails/scim_users_controller_spec.rb