File: test_ssl_server.cr

package info (click to toggle)
crystal 1.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 24,384 kB
  • sloc: javascript: 6,400; sh: 695; makefile: 269; ansic: 121; python: 105; cpp: 77; xml: 32
file content (34 lines) | stat: -rwxr-xr-x 897 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /usr/bin/env crystal
#
# This helper runs a default `HTTP::Server` instance and checks its behaviour
# using [testssl.sh](https://testssl.sh/).
# testssl.sh is a tool for validating TLS implementations.

require "http"
require "../spec/support/ssl"

# This is needed for the ssl_context_pair helper
def datapath(*components)
  File.join("spec", "std", "data", *components)
end

server = HTTP::Server.new do |context|
  context.response.content_type = "text/plain"
  context.response.print "Hello world!"
end
server_context, client_context = ssl_context_pair
address = server.bind_tls "0.0.0.0", 0, server_context

puts "== Starting HTTP server at #{address}"

spawn do
  puts "== Running testssl.sh"
  puts "This may take some time..."

  Process.run("testssl.sh", %w(--parallel --nodns none --color 2) << address.to_s,
    output: :inherit, error: :inherit)

  server.close
end

server.listen