thttpclient_ssl_disabled.nim 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. ## Warning: this test performs external networking.
  9. ## Compile and run with:
  10. ## ./bin/nim c -d:nimDisableCertificateValidation -d:ssl -r -p:. tests/untestable/thttpclient_ssl_disabled.nim
  11. import httpclient,
  12. net,
  13. unittest,
  14. os
  15. from strutils import contains
  16. const expired = "https://expired.badssl.com/"
  17. doAssert defined(nimDisableCertificateValidation)
  18. suite "SSL certificate check - disabled":
  19. test "httpclient in insecure mode":
  20. var ctx = newContext(verifyMode = CVerifyPeer)
  21. var client = newHttpClient(sslContext = ctx)
  22. let a = $client.getContent(expired)
  23. test "httpclient in insecure mode":
  24. var ctx = newContext(verifyMode = CVerifyPeerUseEnvVars)
  25. var client = newHttpClient(sslContext = ctx)
  26. let a = $client.getContent(expired)
  27. test "net socket in insecure mode":
  28. var sock = newSocket()
  29. var ctx = newContext(verifyMode = CVerifyPeerUseEnvVars)
  30. ctx.wrapSocket(sock)
  31. sock.connect("expired.badssl.com", 443.Port)
  32. sock.close