Sha256: f6963971fe45bf8cb8a533d1b98c5453799be648735d70f7dbfc68d43b7d342f

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require_relative "../lib/tynn/ssl"

setup do
  Tynn::Test.new
end

test "redirects to https" do |app|
  Tynn.plugin(Tynn::SSL)

  Tynn.define do
  end

  app.get("/")

  assert_equal 301, app.res.status
  assert_equal "https://example.org/", app.res.location
end

test "https request" do |app|
  Tynn.plugin(Tynn::SSL)

  Tynn.define do
    root do
      res.write("secure")
    end
  end

  app.get("/", {}, "HTTPS" => "on")

  assert_equal 200, app.res.status
  assert_equal "secure", app.res.body
end

test "hsts header" do |app|
  Tynn.plugin(Tynn::SSL)

  Tynn.define do
  end

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

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

  assert_equal "max-age=15552000; includeSubdomains", header
end

test "hsts header options" do |app|
  Tynn.plugin(Tynn::SSL, hsts: { expires: 1, subdomains: false, preload: true })

  Tynn.define do
  end

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

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

  assert_equal "max-age=1; preload", header
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tynn-1.4.0 test/ssl_test.rb
tynn-1.3.0 test/ssl_test.rb