isomorfeus-transport 2.0.1 → 2.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa0acbcbd591284295e444b772feb04cfd666a9ffc760f9883d6ca4e1ab92cf8
4
- data.tar.gz: a71a263b02d3652bc2a934c2369c8e432baa8b11f4bca1c3b44202a819f4d650
3
+ metadata.gz: af7ac21b51feff9d69404ec0273205e4572da1c8d25cb86edf06517b132b351d
4
+ data.tar.gz: 7c91bed9c1b313ee5533c1eb9e0f079c4aef1a16909eb960f77ab4dc863b63db
5
5
  SHA512:
6
- metadata.gz: 1069e0e06fd752d82ef00f059c9afddb095e13b0891d14e4d3e5d2f4d27498ea2971142f8c6535566864d41aad49a804af538f6fc53cb9a65230a6555305c193
7
- data.tar.gz: 57f34ceceea085bb19891bd4c30420aa506f8c69d6305f04eb1a8662fb9dff8089785b043bd9703caa0be3e5fd42c9d33cb02ef6b9abc7c62673393dabb13157
6
+ metadata.gz: 5749d6b1233b66a844351576d374afdbda9515a94f60bddf727516983eead5206e74358bbd49183a584db82f5544337e116dc3e7efa7b03e72c1e4db8228306a
7
+ data.tar.gz: d7d76c36ab734eb91ed231fba6a707a39f2f2aa62d88b49844c9f6687caaef77273c6d766f0d1f86583e5f3a5c026f219691ae1a9369fea0c48d453b98c497a3
@@ -33,9 +33,7 @@ module Isomorfeus
33
33
  session_id = SecureRandom.uuid
34
34
  session_cookie = "session=#{session_id}; SameSite=Strict; HttpOnly; Path=/; Max-Age=2592000#{'; Secure' if Isomorfeus.production?}"
35
35
  session_cookie_accessor = SecureRandom.uuid
36
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_user, user)
37
36
  Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
38
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_session_cookie, session_cookie)
39
37
  Isomorfeus.session_store.add(session_id: session_id, cookie: session_cookie, user: user, accessor: session_cookie_accessor)
40
38
  response_agent.agent_result = { success: 'ok', data: user.to_transport, session_cookie_accessor: session_cookie_accessor }
41
39
  end
@@ -45,9 +43,7 @@ module Isomorfeus
45
43
  session_id = response_agent.request['ssr_login']
46
44
  user = Isomorfeus.session_store.get_user(session_id: session_id)
47
45
  if user
48
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_user, user)
49
46
  Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_authentication_tries, nil)
50
- Isomorfeus.pub_sub_client.instance_variable_set(:@isomorfeus_session_cookie, nil)
51
47
  response_agent.agent_result = { success: 'ok', data: user.to_transport }
52
48
  end
53
49
  end
@@ -9,10 +9,24 @@ module Isomorfeus
9
9
  @app = app
10
10
  end
11
11
 
12
+ def user_from_env(env)
13
+ cookies = env['HTTP_COOKIE']
14
+ if cookies
15
+ cookies = cookies.split('; ')
16
+ cookie = cookies.detect { |c| c.start_with?('session=') }
17
+ if cookie
18
+ session_id = cookie[8..-1]
19
+ user = Isomorfeus.session_store.get_user(session_id: session_id)
20
+ [user, session_id]
21
+ end
22
+ end
23
+ end
24
+
12
25
  def call(env)
13
26
  if env['PATH_INFO'] == Isomorfeus.api_websocket_path
14
27
  if env['rack.upgrade?'] == :websocket
15
- env['rack.upgrade'] = Isomorfeus::Transport::ServerSocketProcessor.new
28
+ user, _session_id = user_from_env(env)
29
+ env['rack.upgrade'] = Isomorfeus::Transport::ServerSocketProcessor.new(user)
16
30
  end
17
31
  WS_RESPONSE
18
32
  elsif env['PATH_INFO'] == Isomorfeus.cookie_eater_path
@@ -28,39 +42,23 @@ module Isomorfeus
28
42
  [404, {}, ["Must specify relative path!"]]
29
43
  end
30
44
  elsif env['PATH_INFO'] == Isomorfeus.api_logout_path
31
- cookies = env['HTTP_COOKIE']
32
- if cookies
33
- cookies = cookies.split('; ')
34
- cookie = cookies.detect { |c| c.start_with?('session=') }
35
- if cookie
36
- session_id = cookie[8..-1]
37
- user = Isomorfeus.session_store.get_user(session_id: session_id)
38
- if user
39
- begin
40
- Isomorfeus.session_store.remove(session_id: session_id)
41
- cookie = "session=#{session_id}; SameSite=Strict; HttpOnly; Path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC#{'; Secure' if Isomorfeus.production?}"
42
- return [302, { 'Location' => '/', 'Set-Cookie' => cookie }, ["Logged out!"]]
43
- ensure
44
- Thread.current[:isomorfeus_user] = nil
45
- Thread.current[:isomorfeus_session_id] = nil
46
- end
47
- end
45
+ user, session_id = user_from_env(env)
46
+ if user
47
+ begin
48
+ Isomorfeus.session_store.remove(session_id: session_id)
49
+ cookie = "session=#{session_id}; SameSite=Strict; HttpOnly; Path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC#{'; Secure' if Isomorfeus.production?}"
50
+ return [302, { 'Location' => '/', 'Set-Cookie' => cookie }, ["Logged out!"]]
51
+ ensure
52
+ Thread.current[:isomorfeus_user] = nil
53
+ Thread.current[:isomorfeus_session_id] = nil
48
54
  end
49
55
  end
50
56
  return [302, { 'Location' => '/', 'Set-Cookie' => cookie }, ["Tried to log out!"]]
51
57
  else
52
- cookies = env['HTTP_COOKIE']
53
- if cookies
54
- cookies = cookies.split('; ')
55
- cookie = cookies.detect { |c| c.start_with?('session=') }
56
- if cookie
57
- session_id = cookie[8..-1]
58
- user = Isomorfeus.session_store.get_user(session_id: session_id)
59
- if user
60
- Thread.current[:isomorfeus_user] = user
61
- Thread.current[:isomorfeus_session_id] = session_id
62
- end
63
- end
58
+ user, session_id = user_from_env(env)
59
+ if user
60
+ Thread.current[:isomorfeus_user] = user
61
+ Thread.current[:isomorfeus_session_id] = session_id
64
62
  end
65
63
  begin
66
64
  result = @app.call(env)
@@ -3,6 +3,10 @@ module Isomorfeus
3
3
  class ServerSocketProcessor
4
4
  include Isomorfeus::Transport::ServerProcessor
5
5
 
6
+ def initialize(user)
7
+ @user = user
8
+ end
9
+
6
10
  def on_message(client, data)
7
11
  if Isomorfeus.development?
8
12
  write_lock = Isomorfeus.zeitwerk_lock.try_write_lock
@@ -45,9 +49,7 @@ module Isomorfeus
45
49
  end
46
50
 
47
51
  def user(client)
48
- current_user = client.instance_variable_get(:@isomorfeus_user)
49
- return current_user if current_user
50
- Anonymous.new
52
+ @user ||= Anonymous.new
51
53
  end
52
54
  end
53
55
  end
@@ -1,5 +1,5 @@
1
1
  module Isomorfeus
2
2
  module Transport
3
- VERSION = '2.0.1'
3
+ VERSION = '2.0.5'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-transport
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-20 00:00:00.000000000 Z
11
+ date: 2022-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 2.0.1
131
+ version: 2.0.5
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 2.0.1
138
+ version: 2.0.5
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: isomorfeus-redux
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 2.0.1
173
+ version: 2.0.5
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 2.0.1
180
+ version: 2.0.5
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rake
183
183
  requirement: !ruby/object:Gem::Requirement