add secure http test for both http client and server

fixes #96
This commit is contained in:
jangko 2021-08-16 20:07:08 +07:00
parent 62980e5493
commit 219a0e3b38
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 20 additions and 5 deletions

View File

@ -40,6 +40,8 @@ task test, "Run all tests":
test "--threads:on", "tests/test_all"
test "--threads:off -d:release", "tests/test_all"
test "--threads:on -d:release", "tests/test_all"
test "--threads:off -d:release -d:tls", "tests/test_httpserver"
test "--threads:on -d:release -d:tls", "tests/test_httpserver"
test "-d:release", "playground/swserver", false
test "-d:release", "playground/tests/test_all"
test "--threads:on -d:release", "playground/tests/test_all"

View File

@ -11,9 +11,9 @@
import
std/[os, json],
pkg/[chronos, toml_serialization, unittest2],
pkg/[toml_serialization, unittest2, chronos],
../graphql, ../graphql/[httpserver, httpclient],
../graphql/test_config, ./test_utils
../graphql/test_config, ./test_utils, keys/keys
type
Unit = object
@ -59,7 +59,16 @@ proc createServer(serverAddress: TransportAddress): GraphqlHttpServerRef =
debugEcho r.error
return
when defined(tls):
let res = GraphqlHttpServerRef.new(
graphql = ctx,
address = serverAddress,
tlsPrivateKey = TLSPrivateKey.init(SecureKey),
tlsCertificate = TLSCertificate.init(SecureCrt),
socketFlags = socketFlags)
else:
let res = GraphqlHttpServerRef.new(ctx, serverAddress, socketFlags = socketFlags)
if res.isErr():
debugEcho res.error
return
@ -67,7 +76,11 @@ proc createServer(serverAddress: TransportAddress): GraphqlHttpServerRef =
res.get()
proc setupClient(address: TransportAddress): GraphqlHttpClientRef =
GraphqlHttpClientRef.new(address)
when defined(tls):
let flags = {TLSFlags.NoVerifyHost, TLSFlags.NoVerifyServerName}
GraphqlSHttpClientRef.new(address = address, tlsFlags = flags).get()
else:
GraphqlHttpClientRef.new(address).get()
proc runExecutor(client: GraphqlHttpClientRef, unit: Unit, testStatusIMPL: var TestStatus) =
client.operationName(unit.opName)
@ -153,7 +166,7 @@ when isMainModule:
var message: string
## Processing command line arguments
if processArguments(message) != Success:
if processArguments(message) != ConfigStatus.Success:
echo message
quit(QuitFailure)
else: