thttpclient_ssl_disabled.nim 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #
  2. # Nim - SSL integration tests
  3. # (c) Copyright 2017 Nim contributors
  4. #
  5. # See the file "copying.txt", included in this
  6. # distribution, for details about the copyright.
  7. #
  8. ## Compile and run with:
  9. ## nim r --putenv:NIM_TESTAMENT_REMOTE_NETWORKING:1 -d:nimDisableCertificateValidation -d:ssl -p:. tests/untestable/thttpclient_ssl_disabled.nim
  10. from stdtest/testutils import enableRemoteNetworking
  11. when enableRemoteNetworking and (defined(nimTestsEnableFlaky) or not defined(openbsd)):
  12. import httpclient, net, unittest
  13. const expired = "https://expired.badssl.com/"
  14. doAssert defined(nimDisableCertificateValidation)
  15. suite "SSL certificate check - disabled":
  16. test "httpclient in insecure mode":
  17. var ctx = newContext(verifyMode = CVerifyPeer)
  18. var client = newHttpClient(sslContext = ctx)
  19. let a = $client.getContent(expired)
  20. test "httpclient in insecure mode":
  21. var ctx = newContext(verifyMode = CVerifyPeerUseEnvVars)
  22. var client = newHttpClient(sslContext = ctx)
  23. let a = $client.getContent(expired)
  24. test "net socket in insecure mode":
  25. var sock = newSocket()
  26. var ctx = newContext(verifyMode = CVerifyPeerUseEnvVars)
  27. ctx.wrapSocket(sock)
  28. sock.connect("expired.badssl.com", 443.Port)
  29. sock.close