brevio-session 0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +29 -29
- data/brevio-session.gemspec +2 -2
- data/lib/brevio/session/testing.rb +16 -0
- data/lib/brevio/session.rb +5 -2
- data/lib/brevio_session.rb +2 -0
- metadata +3 -8
- data/test/brevio_session_integration_test.rb +0 -38
- data/test/redis_json_wrapper.rb +0 -39
- data/test/stubs.rb +0 -18
- data/test/test_app.rb +0 -36
- data/test/test_helper.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe6f0b7a1308fc36fc7af2653b213a467243d0ad33425f19e07d212434601b04
|
4
|
+
data.tar.gz: b4260b34995a0d3be0fee13a39e6bfa4fca2da00998f00831d457f9735ccec11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 613c235b33dd2333ec2bf8e0239a669f55c047efa550e7a3145bb07aa9cdf32dea980c00e5c54577e6db90aa7c792bde203709ff156971faf7f4c2b493db047b
|
7
|
+
data.tar.gz: 92c6e7374afa7ec52a57a6b6485b18140f40bd260856cff26aec3c2cb0349d038dd6ee06dae416fcfffe6567f22b142751df9877521abc828c9f82477405939a
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
brevio-session (0.
|
4
|
+
brevio-session (0.2.0)
|
5
5
|
actionpack (~> 7.0.3)
|
6
6
|
redis (~> 5.0)
|
7
7
|
zeitwerk (~> 2.6.7)
|
@@ -9,63 +9,63 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
actionpack (7.0.
|
13
|
-
actionview (= 7.0.
|
14
|
-
activesupport (= 7.0.
|
15
|
-
rack (~> 2.0, >= 2.2.
|
12
|
+
actionpack (7.0.8)
|
13
|
+
actionview (= 7.0.8)
|
14
|
+
activesupport (= 7.0.8)
|
15
|
+
rack (~> 2.0, >= 2.2.4)
|
16
16
|
rack-test (>= 0.6.3)
|
17
17
|
rails-dom-testing (~> 2.0)
|
18
18
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
19
|
-
actionview (7.0.
|
20
|
-
activesupport (= 7.0.
|
19
|
+
actionview (7.0.8)
|
20
|
+
activesupport (= 7.0.8)
|
21
21
|
builder (~> 3.1)
|
22
22
|
erubi (~> 1.4)
|
23
23
|
rails-dom-testing (~> 2.0)
|
24
24
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
25
|
-
activesupport (7.0.
|
25
|
+
activesupport (7.0.8)
|
26
26
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
27
27
|
i18n (>= 1.6, < 2)
|
28
28
|
minitest (>= 5.1)
|
29
29
|
tzinfo (~> 2.0)
|
30
30
|
ast (2.4.2)
|
31
31
|
builder (3.2.4)
|
32
|
-
concurrent-ruby (1.
|
33
|
-
connection_pool (2.4.
|
32
|
+
concurrent-ruby (1.2.2)
|
33
|
+
connection_pool (2.4.1)
|
34
34
|
crass (1.0.6)
|
35
35
|
debug (1.5.0)
|
36
36
|
irb (>= 1.3.6)
|
37
37
|
reline (>= 0.2.7)
|
38
|
-
erubi (1.
|
39
|
-
i18n (1.
|
38
|
+
erubi (1.12.0)
|
39
|
+
i18n (1.14.1)
|
40
40
|
concurrent-ruby (~> 1.0)
|
41
41
|
io-console (0.6.0)
|
42
42
|
irb (1.6.1)
|
43
43
|
reline (>= 0.3.0)
|
44
44
|
json (2.6.2)
|
45
|
-
loofah (2.
|
45
|
+
loofah (2.21.3)
|
46
46
|
crass (~> 1.0.2)
|
47
|
-
nokogiri (>= 1.
|
48
|
-
|
49
|
-
|
50
|
-
nokogiri (1.13.9)
|
51
|
-
mini_portile2 (~> 2.8.0)
|
47
|
+
nokogiri (>= 1.12.0)
|
48
|
+
minitest (5.20.0)
|
49
|
+
nokogiri (1.15.4-arm64-darwin)
|
52
50
|
racc (~> 1.4)
|
53
51
|
parallel (1.22.1)
|
54
52
|
parser (3.1.2.1)
|
55
53
|
ast (~> 2.4.1)
|
56
|
-
racc (1.
|
57
|
-
rack (2.2.
|
58
|
-
rack-test (2.0
|
54
|
+
racc (1.7.1)
|
55
|
+
rack (2.2.8)
|
56
|
+
rack-test (2.1.0)
|
59
57
|
rack (>= 1.3)
|
60
|
-
rails-dom-testing (2.0
|
61
|
-
activesupport (>=
|
58
|
+
rails-dom-testing (2.2.0)
|
59
|
+
activesupport (>= 5.0.0)
|
60
|
+
minitest
|
62
61
|
nokogiri (>= 1.6)
|
63
|
-
rails-html-sanitizer (1.
|
64
|
-
loofah (~> 2.
|
62
|
+
rails-html-sanitizer (1.6.0)
|
63
|
+
loofah (~> 2.21)
|
64
|
+
nokogiri (~> 1.14)
|
65
65
|
rainbow (3.1.1)
|
66
|
-
redis (5.0.
|
66
|
+
redis (5.0.7)
|
67
67
|
redis-client (>= 0.9.0)
|
68
|
-
redis-client (0.
|
68
|
+
redis-client (0.17.0)
|
69
69
|
connection_pool
|
70
70
|
regexp_parser (2.5.0)
|
71
71
|
reline (0.3.2)
|
@@ -84,10 +84,10 @@ GEM
|
|
84
84
|
rubocop-ast (1.21.0)
|
85
85
|
parser (>= 3.1.1.0)
|
86
86
|
ruby-progressbar (1.11.0)
|
87
|
-
tzinfo (2.0.
|
87
|
+
tzinfo (2.0.6)
|
88
88
|
concurrent-ruby (~> 1.0)
|
89
89
|
unicode-display_width (2.2.0)
|
90
|
-
zeitwerk (2.6.
|
90
|
+
zeitwerk (2.6.12)
|
91
91
|
|
92
92
|
PLATFORMS
|
93
93
|
arm64-darwin-21
|
data/brevio-session.gemspec
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'brevio-session'
|
5
|
-
spec.version = '0.
|
5
|
+
spec.version = '0.2.0'
|
6
6
|
spec.authors = ['Brevio AS']
|
7
7
|
spec.email = ['support@brevio.com']
|
8
8
|
spec.files = `git ls-files -z`.split("\0")
|
9
9
|
|
10
10
|
spec.homepage = 'https://github.com/team-brevio/brevio-session'
|
11
11
|
spec.summary = 'Brevio session wrapper'
|
12
|
-
spec.required_ruby_version = '3.2'
|
12
|
+
spec.required_ruby_version = '~> 3.2'
|
13
13
|
spec.description = 'Wrapper around HTTP session set by Brevio ID'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -26,6 +26,22 @@ module Brevio::Session
|
|
26
26
|
set_cookie(redis_key)
|
27
27
|
end
|
28
28
|
|
29
|
+
def brevio_login_new_user(user_brevio_id, audit_company:)
|
30
|
+
redis_key = SecureRandom.hex(6)
|
31
|
+
|
32
|
+
session_hash = { user_id: user_brevio_id,
|
33
|
+
audit_company_id: audit_company.brevio_id,
|
34
|
+
user_stamp: Time.current.yesterday }
|
35
|
+
|
36
|
+
Testing.config.logger.info "setting Brevio session to #{session_hash}"
|
37
|
+
|
38
|
+
Testing.config.gem_config.redis.set(
|
39
|
+
redis_key,
|
40
|
+
session_hash
|
41
|
+
)
|
42
|
+
set_cookie(redis_key)
|
43
|
+
end
|
44
|
+
|
29
45
|
def brevio_logout
|
30
46
|
cookies[Testing.config.gem_config.session_cookie] = nil
|
31
47
|
end
|
data/lib/brevio/session.rb
CHANGED
@@ -13,7 +13,9 @@ module Brevio::Session
|
|
13
13
|
# available in the context of a controller.
|
14
14
|
#
|
15
15
|
included do
|
16
|
-
|
16
|
+
unless self <= ActionController::Base || instance_methods.include?(:session)
|
17
|
+
raise 'Included Brevio::Session outside of controller'
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
# Fetches the Brevio session from Redis, based on the encrypted key stored in the client's cookie.
|
@@ -44,7 +46,8 @@ module Brevio::Session
|
|
44
46
|
# and whether this cookie contains a user ID.
|
45
47
|
#
|
46
48
|
def brevio_logged_in?
|
47
|
-
fetch_session
|
49
|
+
brevio_session, _ = fetch_session
|
50
|
+
brevio_session&.dig(:user_id).present?
|
48
51
|
end
|
49
52
|
|
50
53
|
private
|
data/lib/brevio_session.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brevio-session
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brevio AS
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,11 +122,6 @@ files:
|
|
122
122
|
- lib/brevio/session/redis.rb
|
123
123
|
- lib/brevio/session/testing.rb
|
124
124
|
- lib/brevio_session.rb
|
125
|
-
- test/brevio_session_integration_test.rb
|
126
|
-
- test/redis_json_wrapper.rb
|
127
|
-
- test/stubs.rb
|
128
|
-
- test/test_app.rb
|
129
|
-
- test/test_helper.rb
|
130
125
|
homepage: https://github.com/team-brevio/brevio-session
|
131
126
|
licenses:
|
132
127
|
- MIT
|
@@ -138,7 +133,7 @@ require_paths:
|
|
138
133
|
- lib
|
139
134
|
required_ruby_version: !ruby/object:Gem::Requirement
|
140
135
|
requirements:
|
141
|
-
- -
|
136
|
+
- - "~>"
|
142
137
|
- !ruby/object:Gem::Version
|
143
138
|
version: '3.2'
|
144
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class BrevioSessionIntegrationTest < Minitest::Test
|
6
|
-
include Rack::Test::Methods
|
7
|
-
include Brevio::Session::Testing
|
8
|
-
|
9
|
-
def brevio_redis
|
10
|
-
Brevio::Session::Config.config.redis
|
11
|
-
end
|
12
|
-
|
13
|
-
def user
|
14
|
-
UserStub.new(brevio_id: 1)
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_sets_brevio_session_in_redis
|
18
|
-
session = brevio_login(user)
|
19
|
-
get '/', nil, cookie: "brevio_session=#{session}"
|
20
|
-
assert last_response.ok?
|
21
|
-
assert current_session.cookie_jar['brevio_session']
|
22
|
-
assert_equal user.brevio_id, brevio_redis.get("brevio-id:session:#{session}")[:user_id]
|
23
|
-
json_body = JSON.parse(last_response.body)
|
24
|
-
assert_equal user.brevio_id, json_body['user_id']
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_user_stamp
|
28
|
-
time = Time.current
|
29
|
-
session = brevio_login(user, updated_at: time)
|
30
|
-
get '/', nil, cookie: "brevio_session=#{session}"
|
31
|
-
assert last_response.ok?
|
32
|
-
json_body = JSON.parse(last_response.body)
|
33
|
-
# ceil ceils the subsecond to a default decimal (0) by default. We don't really care about
|
34
|
-
# microsecond precision here during the JSON parsing/dumping
|
35
|
-
assert_equal time.ceil, Time.parse(json_body['user_stamp']).ceil
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
data/test/redis_json_wrapper.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Brevio ID stores its session using redis-session-store, which stores all values as JSON.
|
4
|
-
# The returned value is a JSON string, which needs to be parsed by the redis client. The native
|
5
|
-
# Redis.get would simply return the JSON string, so we need to wrap it.
|
6
|
-
#
|
7
|
-
# The services consuming the Brevio::Session (e.g. Confirm/Sign) already assume the values
|
8
|
-
# in Redis are all JSON (see domain/brevio/redis/client.rb).
|
9
|
-
#
|
10
|
-
#
|
11
|
-
class RedisJSONWrapper
|
12
|
-
def set(key, value)
|
13
|
-
redis.set(key, value.to_json)
|
14
|
-
end
|
15
|
-
|
16
|
-
def get(key)
|
17
|
-
raw = redis.get(key)
|
18
|
-
return nil if raw.nil?
|
19
|
-
|
20
|
-
value = JSON.parse(raw)
|
21
|
-
return value if value.empty?
|
22
|
-
|
23
|
-
value.with_indifferent_access
|
24
|
-
end
|
25
|
-
|
26
|
-
def del(keys)
|
27
|
-
redis.del(keys)
|
28
|
-
end
|
29
|
-
|
30
|
-
def expire(key, expiry)
|
31
|
-
redis.expire(key, expiry)
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def redis
|
37
|
-
@redis ||= ::Redis.new
|
38
|
-
end
|
39
|
-
end
|
data/test/stubs.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class UserStub
|
4
|
-
attr_accessor :brevio_id, :audit_company
|
5
|
-
|
6
|
-
def initialize(attrs)
|
7
|
-
@brevio_id = attrs[:brevio_id]
|
8
|
-
@audit_company = AuditCompanyStub.new(brevio_id: @brevio_id + 1)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class AuditCompanyStub
|
13
|
-
attr_accessor :brevio_id
|
14
|
-
|
15
|
-
def initialize(attrs)
|
16
|
-
@brevio_id = attrs[:brevio_id]
|
17
|
-
end
|
18
|
-
end
|
data/test/test_app.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Based on https://github.com/rails/rails/blob/6-0-stable/guides/bug_report_templates/action_controller_master.rb
|
4
|
-
|
5
|
-
require 'action_controller/railtie'
|
6
|
-
require 'rack/test'
|
7
|
-
require 'brevio-session'
|
8
|
-
|
9
|
-
class TestApp < Rails::Application
|
10
|
-
config.root = __dir__
|
11
|
-
config.hosts << 'example.org'
|
12
|
-
config.session_store :cookie_store, key: 'brevio_session'
|
13
|
-
secrets.secret_key_base = 'secret_key_base'
|
14
|
-
|
15
|
-
config.logger = Logger.new($stdout)
|
16
|
-
config.log_level = :info
|
17
|
-
Rails.logger = config.logger
|
18
|
-
|
19
|
-
routes.draw do
|
20
|
-
get '/' => 'test#index'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class TestController < ActionController::Base
|
25
|
-
include Brevio::Session
|
26
|
-
include Rails.application.routes.url_helpers
|
27
|
-
|
28
|
-
def logger
|
29
|
-
Rails.logger
|
30
|
-
end
|
31
|
-
|
32
|
-
def index
|
33
|
-
brevio_session = fetch_brevio_session
|
34
|
-
render json: brevio_session.to_json
|
35
|
-
end
|
36
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'minitest/autorun'
|
4
|
-
require 'rack/test'
|
5
|
-
|
6
|
-
require 'debug'
|
7
|
-
require 'fakeredis'
|
8
|
-
require 'priscilla'
|
9
|
-
require 'brevio-session'
|
10
|
-
require 'brevio_session/testing'
|
11
|
-
|
12
|
-
require 'redis_json_wrapper'
|
13
|
-
require 'stubs'
|
14
|
-
require 'test_app'
|
15
|
-
|
16
|
-
Brevio::Session::Config.configure do |config|
|
17
|
-
config.debug = true
|
18
|
-
config.production = false
|
19
|
-
config.redis = RedisJSONWrapper.new
|
20
|
-
config.secret_key = 'secret_key_base'
|
21
|
-
config.session_cookie = 'brevio_session'
|
22
|
-
config.session_expire = 45.minutes
|
23
|
-
end
|
24
|
-
|
25
|
-
Brevio::Session::Testing.setup!(logger: Rails.logger)
|
26
|
-
|
27
|
-
module Minitest
|
28
|
-
class Test
|
29
|
-
include Rack::Test::Methods
|
30
|
-
include TestApp.routes.url_helpers
|
31
|
-
|
32
|
-
def app
|
33
|
-
TestApp
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|