Sha256: 2742ace66bd1d0623ae1e972842d8ea58b85614faae09054255bed2a6672c0bb

Contents?: true

Size: 811 Bytes

Versions: 2

Compression:

Stored size: 811 Bytes

Contents

require_relative "../lib/tynn/protection"
require_relative "../lib/tynn/session"

test "supports hsts options" do
  hsts = { expires: 100, subdomains: false, preload: true }

  Tynn.helpers(Tynn::Protection, ssl: true, hsts: hsts)

  Tynn.define do
  end

  app = Tynn::Test.new
  app.get("/", {}, "HTTPS" => "on")

  hsts = app.res.headers["Strict-Transport-Security"]

  assert_equal "max-age=100; preload", hsts
end

test "adds secure flag to session cookie" do
  Tynn.helpers(Tynn::Protection, ssl: true)
  Tynn.helpers(Tynn::Session, secret: "_this_must_be_random_")

  Tynn.define do
    root do
      session[:foo] = "foo"
    end
  end

  app = Tynn::Test.new
  app.get("/", {}, "HTTPS" => "on")

  session, _ = app.res.headers["Set-Cookie"].split("\n")

  assert(/;\s*secure\s*(;|$)/i === session)
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tynn-1.0.0 test/protection_test.rb
tynn-1.0.0.rc3 test/protection_test.rb