mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-31 02:12:11 +00:00
* Working on OpenBSD CI * Condense steps into 2 steps to make output easier to follow. * Move up one directory after csources build. * Remove FreeBSD build manifest and add OpenBSD test ignores for coroutines and hot code reloading. * If runCI fails, run the test results script. * Add email trigger for build failure * Remove .git from repository URL * Disable SFML test on OpenBSD * Disable tgetaddrinfo on OpenBSD as only UDP and TCP protocols are supported. * Remove getFilePermissions as it causes CI test failures with NimScript. * Set clang as cc in nim.cfg and use gmake to build csources. * Add getCurrentDir to nimscript. * Remove duplicate getCurrentDir and check for not weirdTarget. * Add CI badge for OpenBSD. * Disable tests which allocate lots of memory for OpenBSD. * Use `CORO_BACKEND_SETJMP` on OpenBSD rather than ucontext. * Simplify building of koch * Disable t8657 on OpenBSD. See issue #13760. * Fix #12142 - tarray_of_channels fails on OpenBSD * Disable thhtpclient_ssl and tosprocterminate on OpenBSD. These tests can be enabled at a later date after fixing them. * Install libffi. * Set path to libc for openbsd. * Disable tevalffi for now. * Remove tevalffi.nim. * Use ncpuonline sysctl rather than ncpu. * Disable tacceptcloserace and tasynchttpserver on OpenBSD. * Enable tacceptcloserace and tasynchttpserver. * Fix #13775 as suggested by @alaviss - use /bin/cat on OpenBSD rather than /bin/sh. * Enable test on OpenBSD. * Disable tflowvar on OpenBSD.
128 lines
3.4 KiB
Nim
128 lines
3.4 KiB
Nim
discard """
|
|
cmd: "nim $target --threads:on -d:ssl $options $file"
|
|
disabled: "openbsd"
|
|
"""
|
|
|
|
# Nim - Basic SSL integration tests
|
|
# (c) Copyright 2018 Nim contributors
|
|
#
|
|
# See the file "copying.txt", included in this
|
|
# distribution, for details about the copyright.
|
|
#
|
|
## Warning: this test performs local networking.
|
|
## Test with:
|
|
## ./bin/nim c -d:ssl -p:. --threads:on -r tests/stdlib/thttpclient_ssl.nim
|
|
|
|
when not defined(windows):
|
|
# Disabled on Windows due to old OpenSSL version
|
|
|
|
import
|
|
httpclient,
|
|
net,
|
|
openssl,
|
|
os,
|
|
strutils,
|
|
threadpool,
|
|
times,
|
|
unittest
|
|
|
|
# bogus self-signed certificate
|
|
const
|
|
certFile = "tests/stdlib/thttpclient_ssl_cert.pem"
|
|
keyFile = "tests/stdlib/thttpclient_ssl_key.pem"
|
|
|
|
proc log(msg: string) =
|
|
when defined(ssldebug):
|
|
echo " [" & $epochTime() & "] " & msg
|
|
# FIXME
|
|
echo " [" & $epochTime() & "] " & msg
|
|
discard
|
|
|
|
proc runServer(port: Port): bool {.thread.} =
|
|
## Run a trivial HTTPS server in a {.thread.}
|
|
## Exit after serving one request
|
|
|
|
var socket = newSocket()
|
|
socket.setSockOpt(OptReusePort, true)
|
|
socket.bindAddr(port)
|
|
|
|
var ctx = newContext(certFile=certFile, keyFile=keyFile)
|
|
|
|
## Handle one connection
|
|
socket.listen()
|
|
|
|
var client: Socket
|
|
var address = ""
|
|
|
|
log "server: ready"
|
|
socket.acceptAddr(client, address)
|
|
log "server: incoming connection"
|
|
|
|
var ssl: SslPtr = SSL_new(ctx.context)
|
|
discard SSL_set_fd(ssl, client.getFd())
|
|
log "server: accepting connection"
|
|
if SSL_accept(ssl) <= 0:
|
|
ERR_print_errors_fp(stderr)
|
|
else:
|
|
const reply = "HTTP/1.0 200 OK\r\nServer: test\r\nContent-type: text/html\r\nContent-Length: 0\r\n\r\n"
|
|
log "server: sending reply"
|
|
discard SSL_write(ssl, reply.cstring, reply.len)
|
|
|
|
log "server: receiving a line"
|
|
let line = client.recvLine()
|
|
log "server: received $# bytes" % $line.len
|
|
log "closing"
|
|
SSL_free(ssl)
|
|
close(client)
|
|
close(socket)
|
|
log "server: exited"
|
|
|
|
|
|
suite "SSL self signed certificate check":
|
|
|
|
test "TCP socket":
|
|
const port = 12347.Port
|
|
let t = spawn runServer(port)
|
|
sleep(100)
|
|
var sock = newSocket()
|
|
var ctx = newContext()
|
|
ctx.wrapSocket(sock)
|
|
try:
|
|
log "client: connect"
|
|
sock.connect("127.0.0.1", port)
|
|
fail()
|
|
except:
|
|
let msg = getCurrentExceptionMsg()
|
|
check(msg.contains("certificate verify failed"))
|
|
|
|
test "HttpClient default: no check":
|
|
const port = 12345.Port
|
|
let t = spawn runServer(port)
|
|
sleep(100)
|
|
|
|
var client = newHttpClient()
|
|
try:
|
|
log "client: connect"
|
|
discard client.getContent("https://127.0.0.1:12345")
|
|
except:
|
|
let msg = getCurrentExceptionMsg()
|
|
log "client: unexpected exception: " & msg
|
|
fail()
|
|
|
|
test "HttpClient with CVerifyPeer":
|
|
const port = 12346.Port
|
|
let t = spawn runServer(port)
|
|
sleep(100)
|
|
|
|
var client = newHttpClient(sslContext=newContext(verifyMode=CVerifyPeer))
|
|
try:
|
|
log "client: connect"
|
|
discard client.getContent("https://127.0.0.1:12346")
|
|
log "getContent should have raised an exception"
|
|
fail()
|
|
except:
|
|
let msg = getCurrentExceptionMsg()
|
|
log "client: exception: " & msg
|
|
# SSL_shutdown:shutdown while in init
|
|
check(msg.contains("shutdown while in init") or msg.contains("alert number 48"))
|