brevio-session 0.1 → 0.1.1
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 +4 -4
- data/brevio-session.gemspec +1 -1
- data/lib/brevio/session.rb +3 -1
- data/lib/brevio_session.rb +2 -0
- metadata +2 -7
- 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: cba1f34cb1c21a2b40226dd174a9de1a9263fa0a30365e9621fc181baffb98d0
|
4
|
+
data.tar.gz: 4bafca01227c5ed4704d3cfdba571c4a063939203876860c8dadac46a125ba4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8173f7928ce6e54c1f0bfeec4a5b76bd4088c5fb1ef5622b8b17a076689da5e709e16d31f0b24867ad8ce805d5304b81bcaf00b0d09d82b6d03f1924c4edc3d8
|
7
|
+
data.tar.gz: 452279a03c727a0ccb0bacf0acd302c7699f2873e5c1851893e58cfb3cb4751426244d4c0ccc54ff0ff1790840fdc368a0667c2c75fb397615505cb9fa9aae5b
|
data/brevio-session.gemspec
CHANGED
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.
|
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.1.1
|
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-04-
|
11
|
+
date: 2023-04-20 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
|
@@ -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
|