forest_liana 8.0.15 → 8.0.16

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: f05d57e597b220694bfa6681b6fd44ce847bbc3d9bed60c23547f4b6f879bcb5
4
- data.tar.gz: d3bbd0453df99c237ead29a3d86b7b67a64dc6ceedf03420cc99ccd39eefd1ff
3
+ metadata.gz: d66f322c9f51d6beebaa2eb338b8f568f7d12bc781d71c4b47a8c2c3e6503c73
4
+ data.tar.gz: 37db17c392bac96b35c43595c03ef702e840ae40e420538151d36edc2a347c68
5
5
  SHA512:
6
- metadata.gz: 03506c47bf6f748129c80823b372246845f215d253b7b3ee3d2d14a27b4588c4014fa6a27d05a8199bee5134549663637c19f35327a87ff3ee0a0f4bfba82632
7
- data.tar.gz: 2b55b11b94dc2fa393bcdbb66bf2a16305b193f004399ac4b79c2a33ac0c0d81f1fed98c8c798725c1504e38a718990ff402e6e1fdb2f1e91726306ff6c3cb29
6
+ metadata.gz: 9466f6b82dc0ffbfae007bfc0024e5b831172dacdffcf00e51c58a8ca2333dbbefb165227a3d36b704954b1cdb75ecdfb9a5f2605840572220e612226e6cb39d
7
+ data.tar.gz: 5c313811aead7c0617d1e5d5d9c424f66e56b0482a46dc8354a1714b59f61490a728cc1cacb9224553110b0577b68712ba62366e8b214d6c7bddb2daffde4c7d
@@ -39,6 +39,8 @@ module ForestLiana
39
39
  end
40
40
 
41
41
  def authentication_callback
42
+ return authentication_exception if params.key?(:error)
43
+
42
44
  begin
43
45
  token = @authentication_service.verify_code_and_generate_token(params)
44
46
 
@@ -55,6 +57,21 @@ module ForestLiana
55
57
  end
56
58
  end
57
59
 
60
+ def authentication_exception
61
+ begin
62
+ raise ForestLiana::Errors::AuthenticationOpenIdClientException.new(params[:error], params[:error_description], params[:state])
63
+ rescue => error
64
+ FOREST_REPORTER.report error
65
+ FOREST_LOGGER.error "AuthenticationOpenIdClientException: #{error.error_description}"
66
+
67
+ render json: {
68
+ error: error.error,
69
+ error_description: error.error_description,
70
+ state: error.state
71
+ }, status: :unauthorized
72
+ end
73
+ end
74
+
58
75
  def logout
59
76
  begin
60
77
  if cookies.has_key?(:forest_session_token)
@@ -38,8 +38,6 @@ module ForestLiana
38
38
  raise ForestLiana::MESSAGES[:SERVER_TRANSACTION][:INVALID_STATE_MISSING]
39
39
  end
40
40
 
41
- rendering_id = nil
42
-
43
41
  begin
44
42
  parsed_state = JSON.parse(state.gsub("'",'"').gsub('=>',':'))
45
43
  rendering_id = parsed_state["renderingId"].to_s
@@ -30,6 +30,17 @@ module ForestLiana
30
30
  end
31
31
  end
32
32
 
33
+ class AuthenticationOpenIdClientException < StandardError
34
+ attr_reader :error, :error_description, :state
35
+
36
+ def initialize(error, error_description, state)
37
+ super(error_description)
38
+ @error = error
39
+ @error_description = error_description
40
+ @state = state
41
+ end
42
+ end
43
+
33
44
  class ExpectedError < StandardError
34
45
  attr_reader :error_code, :status, :message, :name
35
46
 
@@ -1,3 +1,3 @@
1
1
  module ForestLiana
2
- VERSION = "8.0.15"
2
+ VERSION = "8.0.16"
3
3
  end
@@ -44,44 +44,66 @@ describe "Authentications", type: :request do
44
44
  end
45
45
 
46
46
  describe "GET /authentication/callback" do
47
- before() do
48
- response = '{"data":{"id":666,"attributes":{"first_name":"Alice","last_name":"Doe","email":"alice@forestadmin.com","teams":[1,2,3],"role":"Test","tags":[{"key":"city","value":"Paris"}]}}}'
49
- allow(ForestLiana::ForestApiRequester).to receive(:get).with(
50
- "/liana/v2/renderings/42/authorization", { :headers => { "forest-token" => "THE-ACCESS-TOKEN" }, :query => {} }
51
- ).and_return(
52
- instance_double(HTTParty::Response, :body => response, :code => 200)
53
- )
54
-
55
- get ForestLiana::Engine.routes.url_helpers.authentication_callback_path + "?code=THE-CODE&state=#{CGI::escape('{"renderingId":42}')}"
56
- end
47
+ context 'when the response is a 200' do
48
+ before() do
49
+ response = '{"data":{"id":666,"attributes":{"first_name":"Alice","last_name":"Doe","email":"alice@forestadmin.com","teams":[1,2,3],"role":"Test","tags":[{"key":"city","value":"Paris"}]}}}'
50
+ allow(ForestLiana::ForestApiRequester).to receive(:get).with(
51
+ "/liana/v2/renderings/42/authorization", { :headers => { "forest-token" => "THE-ACCESS-TOKEN" }, :query => {} }
52
+ ).and_return(
53
+ instance_double(HTTParty::Response, :body => response, :code => 200)
54
+ )
57
55
 
58
- it "should respond with a 200 code" do
59
- expect(response).to have_http_status(200)
60
- end
56
+ get ForestLiana::Engine.routes.url_helpers.authentication_callback_path + "?code=THE-CODE&state=#{CGI::escape('{"renderingId":42}')}"
57
+ end
61
58
 
62
- it "should return a valid authentication token" do
63
- body = JSON.parse(response.body, :symbolize_names => true);
59
+ it "should respond with a 200 code" do
60
+ expect(response).to have_http_status(200)
61
+ end
64
62
 
65
- token = body[:token]
66
- decoded = JWT.decode(token, ForestLiana.auth_secret, true, { algorithm: 'HS256' })[0]
63
+ it "should return a valid authentication token" do
64
+ body = JSON.parse(response.body, :symbolize_names => true);
67
65
 
68
- expected_token_data = {
69
- "id" => 666,
70
- "email" => 'alice@forestadmin.com',
71
- "rendering_id" => "42",
72
- "first_name" => 'Alice',
73
- "last_name" => 'Doe',
74
- "team" => 1,
75
- "role" => "Test",
76
- }
66
+ token = body[:token]
67
+ decoded = JWT.decode(token, ForestLiana.auth_secret, true, { algorithm: 'HS256' })[0]
77
68
 
78
- expect(decoded).to include(expected_token_data)
79
- tags = decoded['tags']
80
- expect(tags.length).to eq(1)
81
- expect(tags[0]['key']).to eq("city")
82
- expect(tags[0]['value']).to eq("Paris")
83
- expect(body).to eq({ token: token, tokenData: decoded.deep_symbolize_keys! })
84
- expect(response).to have_http_status(200)
69
+ expected_token_data = {
70
+ "id" => 666,
71
+ "email" => 'alice@forestadmin.com',
72
+ "rendering_id" => "42",
73
+ "first_name" => 'Alice',
74
+ "last_name" => 'Doe',
75
+ "team" => 1,
76
+ "role" => "Test",
77
+ }
78
+
79
+ expect(decoded).to include(expected_token_data)
80
+ tags = decoded['tags']
81
+ expect(tags.length).to eq(1)
82
+ expect(tags[0]['key']).to eq("city")
83
+ expect(tags[0]['value']).to eq("Paris")
84
+ expect(body).to eq({ token: token, tokenData: decoded.deep_symbolize_keys! })
85
+ expect(response).to have_http_status(200)
86
+ end
87
+ end
88
+
89
+ context 'when the response is not a 200' do
90
+ before() do
91
+ get ForestLiana::Engine.routes.url_helpers.authentication_callback_path,
92
+ params: {
93
+ error: 'TrialBlockedError',
94
+ error_description: 'Your free trial has ended. We hope you enjoyed your experience with Forest Admin.',
95
+ state: '{"renderingId":100}'
96
+ },
97
+ headers: {
98
+ 'Accept' => 'application/json',
99
+ 'Content-Type' => 'application/json',
100
+ }
101
+ end
102
+
103
+ it "should respond with a 401 code" do
104
+ expect(response).to have_http_status(401)
105
+ expect(response.body).to eq('{"error":"TrialBlockedError","error_description":"Your free trial has ended. We hope you enjoyed your experience with Forest Admin.","state":"{\"renderingId\":100}"}')
106
+ end
85
107
  end
86
108
  end
87
109
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forest_liana
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.15
4
+ version: 8.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Munda
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-23 00:00:00.000000000 Z
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails