Skip to content

Commit

Permalink
Explicitly use 127.0.0.1 in test suite
Browse files Browse the repository at this point in the history
When `Nothing` is used as a host, it gets defaulted to `localhost`, which
resolves differently in IPv6 vs IPv4.

Remove TlsFailHostName test, because it depends on having two names for the same
server (`localhost` vs `127.0.0.1`), but the choice of two names depends on what
`localhost` resolves to. The test doesn't add much value, since we still verify
that the certificate is rejected if it is not set as a root certificate.
  • Loading branch information
FinleyMcIlwaine committed Jul 11, 2024
1 parent 978cba0 commit 5a05d57
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
20 changes: 4 additions & 16 deletions test-grapesy/Test/Driver/ClientServer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,6 @@ data TlsFail =
-- self signed.
TlsFailValidation

-- | Client uses the wrong address (@localhost@ instead of @127.0.0.1@)
--
-- This too will result in a TLS failure (hostname mismatch). To ensure we
-- get the TLS failure we expect, we /do/ add the server's certificate to
-- the client's trusted certs.
| TlsFailHostname

-- | The server is not configured for TLS
| TlsFailUnsupported

Expand Down Expand Up @@ -323,7 +316,6 @@ isExpectedTLSException :: ClientServerConfig -> TLSException -> Bool
isExpectedTLSException cfg tls =
case (useTLS cfg, tls) of
(Just (TlsFail TlsFailValidation) , HandshakeFailed _) -> True
(Just (TlsFail TlsFailHostname) , HandshakeFailed _) -> True
(Just (TlsFail TlsFailUnsupported) , HandshakeFailed _) -> True
_otherwise -> False

Expand Down Expand Up @@ -449,14 +441,14 @@ withTestServer cfg firstTestFailure handlerLock serverHandlers k = do
case useTLS cfg of
Nothing -> Server.ServerConfig {
serverInsecure = Just Server.InsecureConfig {
insecureHost = Nothing
insecureHost = Just "127.0.0.1"
, insecurePort = serverPort cfg
}
, serverSecure = Nothing
}
Just (TlsFail TlsFailUnsupported) -> Server.ServerConfig {
serverInsecure = Just Server.InsecureConfig {
insecureHost = Nothing
insecureHost = Just "127.0.0.1"
, insecurePort = serverPort cfg
}
, serverSecure = Nothing
Expand Down Expand Up @@ -558,8 +550,6 @@ runTestClient cfg firstTestFailure port clientRun = do
Client.NoServerValidation
TlsFail TlsFailValidation ->
Client.ValidateServer mempty
TlsFail TlsFailHostname ->
correctClientSetup
TlsFail TlsFailUnsupported ->
correctClientSetup
)
Expand All @@ -581,10 +571,8 @@ runTestClient cfg firstTestFailure port clientRun = do
clientAuthority :: Client.Address
clientAuthority =
case useTLS cfg of
Just tlsSetup -> Client.Address {
addressHost = case tlsSetup of
TlsFail TlsFailHostname -> "localhost"
_otherwise -> "127.0.0.1"
Just _tlsSetup -> Client.Address {
addressHost = "127.0.0.1"
, addressPort = port
, addressAuthority = Nothing
}
Expand Down
4 changes: 0 additions & 4 deletions test-grapesy/Test/Sanity/StreamingType/NonStreaming.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ tests = testGroup "Test.Sanity.StreamingType.NonStreaming" [
test_increment def {
useTLS = Just $ TlsFail TlsFailValidation
}
, testCase "hostname" $
test_increment def {
useTLS = Just $ TlsFail TlsFailHostname
}
, testCase "unsupported" $
test_increment def {
useTLS = Just $ TlsFail TlsFailUnsupported
Expand Down

0 comments on commit 5a05d57

Please sign in to comment.