Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running tests with badssl.com #550

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions http-client-tls/http-client-tls.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ test-suite spec
, http-client-tls
, http-types
, crypton-connection
, data-default
, tls

benchmark benchmark
main-is: Bench.hs
Expand Down
21 changes: 18 additions & 3 deletions http-client-tls/test/Spec.hs
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
import Test.Hspec
import Network.Connection
import Network.HTTP.Client
import Network.HTTP.Client.TLS
import Network.HTTP.Client.TLS hiding (tlsManagerSettings)
import Network.HTTP.Types
import Control.Monad (join)
import Data.Default
import qualified Network.TLS as TLS

main :: IO ()
main = hspec $ do
let tlsSettings = def
-- Since the release of v2.0.0 of the `tls` package , the default value of
-- the `supportedExtendedMainSecret` parameter `is `RequireEMS`, this means
-- that all the connections to a server not supporting TLS1.2+EMS will fail.
-- The badssl.com service does not yet support TLS1.2+EMS connections, so
-- let's switch to the value `AllowEMS`, ie: TLS1.2 conenctions without EMS.
#if MIN_VERSION_crypton_connection(0,4,0)
{settingClientSupported = def {TLS.supportedExtendedMainSecret = TLS.AllowEMS}}
#endif

let tlsManagerSettings = mkManagerSettings tlsSettings Nothing

it "make a TLS connection" $ do
manager <- newManager tlsManagerSettings
withResponse "https://httpbin.org/status/418" manager $ \res ->
Expand Down Expand Up @@ -52,13 +67,13 @@ main = hspec $ do
-- https://github.com/snoyberg/http-client/issues/289
it "accepts TLS settings" $ do
let
tlsSettings = TLSSettingsSimple
tlsSettings' = tlsSettings
{ settingDisableCertificateValidation = True
, settingDisableSession = False
, settingUseServerName = False
}
socketSettings = Nothing
managerSettings = mkManagerSettings tlsSettings socketSettings
managerSettings = mkManagerSettings tlsSettings' socketSettings
manager <- newTlsManagerWith managerSettings
let url = "https://wrong.host.badssl.com"
request <- parseRequest url
Expand Down