Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gems/rack-session/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This configuration inherits from /.rubocop.yml.
# You can configure RBS style of this gem.
# This file is used on CI. It is configured to automatically
# make rubocop suggestions on pull requests for this gem.
# If you do not like the style enforcement, you should remove this file.
inherit_from: ../../.rubocop.yml

##
# If you want to customize the style, please consult with the gem reviewers.
# You can see the list of cops at https://github.com/ksss/rubocop-on-rbs/blob/main/docs/modules/ROOT/pages/cops.adoc

RBS/Layout:
Enabled: true

RBS/Lint:
Enabled: true

RBS/Style:
Enabled: true
51 changes: 51 additions & 0 deletions gems/rack-session/2.1/_test/test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "rack"
require "rack/session"

secret = "x" * 64

app = Rack::Builder.new do
use Rack::Session::Cookie, secrets: [secret], key: "_app_session", same_site: :lax, expire_after: 3600
run do |env|
session = env[Rack::RACK_SESSION] #: Rack::Session::Abstract::SessionHash
session["count"] = 1
session[:user_id] = 1
session.fetch("user_id", nil)
session.key?(:user_id)
session.delete("count")
session.to_hash.keys.first&.length
session.options[:skip] = true
[200, { "content-type" => "text/plain" }, ["ok"]]
end
end

Rack::Session::Pool.new(app.to_app, expire_after: 3600).pool.size
Rack::Session::Cookie.new(app.to_app, coder: Rack::Session::Cookie::Base64::JSON.new, let_coder_handle_secure_encoding: true).coder

encryptor = Rack::Session::Encryptor.new(secret)
data = encryptor.encrypt({ "user_id" => 1 })
data.length
encryptor.decrypt(data)

begin
encryptor.decrypt("invalid")
rescue Rack::Session::Encryptor::Error => e
e.message
end

Rack::Session::SessionId.new("abc").private_id.length

class MyStore < Rack::Session::Abstract::PersistedSecure
private

def find_session(req, sid)
[sid || generate_sid, {}]
end

def write_session(req, sid, session, options)
sid
end

def delete_session(req, sid, options)
generate_sid
end
end
2 changes: 2 additions & 0 deletions gems/rack-session/2.1/_test/test.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class MyStore < Rack::Session::Abstract::PersistedSecure
end
Loading
Loading