@@ -75,7 +75,7 @@ data ClientServerConfig = ClientServerConfig {
75
75
-- The client will query the server for its port; this makes it possible
76
76
-- to use @0@ for 'serverPort', so that the server picks a random
77
77
-- available port (this is the default).
78
- serverPort :: PortNumber
78
+ serverPort :: Either FilePath PortNumber
79
79
80
80
-- | Compression algorithms supported by the client
81
81
, clientCompr :: Compr. Negotation
@@ -117,7 +117,7 @@ data ContentTypeOverride =
117
117
118
118
instance Default ClientServerConfig where
119
119
def = ClientServerConfig {
120
- serverPort = 0
120
+ serverPort = Right 0
121
121
, clientCompr = def
122
122
, clientInitCompr = Nothing
123
123
, serverCompr = def
@@ -366,32 +366,40 @@ withTestServer cfg firstTestFailure handlerLock serverHandlers k = do
366
366
367
367
let serverConfig :: Server. ServerConfig
368
368
serverConfig =
369
- case useTLS cfg of
370
- Nothing -> Server. ServerConfig {
371
- serverInsecure = Just Server. InsecureConfig {
372
- insecureHost = Just " 127.0.0.1"
373
- , insecurePort = serverPort cfg
369
+ case serverPort cfg of
370
+ Left socketPath -> Server. ServerConfig {
371
+ serverInsecure = Just Server. InsecureUnix {
372
+ insecurePath = socketPath
374
373
}
375
374
, serverSecure = Nothing
376
375
}
377
- Just (TlsFail TlsFailUnsupported ) -> Server. ServerConfig {
378
- serverInsecure = Just Server. InsecureConfig {
379
- insecureHost = Just " 127.0.0.1"
380
- , insecurePort = serverPort cfg
376
+ Right portNumber ->
377
+ case useTLS cfg of
378
+ Nothing -> Server. ServerConfig {
379
+ serverInsecure = Just Server. InsecureConfig {
380
+ insecureHost = Just " 127.0.0.1"
381
+ , insecurePort = portNumber
382
+ }
383
+ , serverSecure = Nothing
381
384
}
382
- , serverSecure = Nothing
383
- }
384
- Just _tlsSetup -> Server. ServerConfig {
385
- serverInsecure = Nothing
386
- , serverSecure = Just $ Server. SecureConfig {
387
- secureHost = " 127.0.0.1"
388
- , securePort = serverPort cfg
389
- , securePubCert = pubCert
390
- , secureChainCerts = []
391
- , securePrivKey = privKey
392
- , secureSslKeyLog = SslKeyLogNone
385
+ Just (TlsFail TlsFailUnsupported ) -> Server. ServerConfig {
386
+ serverInsecure = Just Server. InsecureConfig {
387
+ insecureHost = Just " 127.0.0.1"
388
+ , insecurePort = portNumber
389
+ }
390
+ , serverSecure = Nothing
391
+ }
392
+ Just _tlsSetup -> Server. ServerConfig {
393
+ serverInsecure = Nothing
394
+ , serverSecure = Just $ Server. SecureConfig {
395
+ secureHost = " 127.0.0.1"
396
+ , securePort = portNumber
397
+ , securePubCert = pubCert
398
+ , secureChainCerts = []
399
+ , securePrivKey = privKey
400
+ , secureSslKeyLog = SslKeyLogNone
401
+ }
393
402
}
394
- }
395
403
396
404
serverParams :: Server. ServerParams
397
405
serverParams = def {
@@ -437,10 +445,10 @@ simpleTestClient test params testServer delimitTestScope =
437
445
runTestClient ::
438
446
ClientServerConfig
439
447
-> TMVar FirstTestFailure
440
- -> PortNumber
448
+ -> Either FilePath PortNumber
441
449
-> TestClient
442
450
-> IO ()
443
- runTestClient cfg firstTestFailure port clientRun = do
451
+ runTestClient cfg firstTestFailure pathOrPort clientRun = do
444
452
pubCert <- getDataFileName " grpc-demo.pem"
445
453
446
454
let clientParams :: Client. ConnParams
@@ -469,36 +477,40 @@ runTestClient cfg firstTestFailure port clientRun = do
469
477
470
478
clientServer :: Client. Server
471
479
clientServer =
472
- case useTLS cfg of
473
- Just tlsSetup ->
474
- Client. ServerSecure
475
- ( case tlsSetup of
476
- TlsOk TlsOkCertAsRoot ->
477
- correctClientSetup
478
- TlsOk TlsOkSkipValidation ->
479
- Client. NoServerValidation
480
- TlsFail TlsFailValidation ->
481
- Client. ValidateServer mempty
482
- TlsFail TlsFailUnsupported ->
483
- correctClientSetup
484
- )
485
- -- We enable key logging in the client and disable it in the
486
- -- server. This avoids the client and server trying to write
487
- -- to the same file.
488
- SslKeyLogFromEnv
489
- clientAuthority
490
-
491
- Nothing ->
492
- Client. ServerInsecure
493
- clientAuthority
480
+ case pathOrPort of
481
+ Left socketPath ->
482
+ Client. ServerUnix socketPath
483
+ Right port ->
484
+ case useTLS cfg of
485
+ Just tlsSetup ->
486
+ Client. ServerSecure
487
+ ( case tlsSetup of
488
+ TlsOk TlsOkCertAsRoot ->
489
+ correctClientSetup
490
+ TlsOk TlsOkSkipValidation ->
491
+ Client. NoServerValidation
492
+ TlsFail TlsFailValidation ->
493
+ Client. ValidateServer mempty
494
+ TlsFail TlsFailUnsupported ->
495
+ correctClientSetup
496
+ )
497
+ -- We enable key logging in the client and disable it in the
498
+ -- server. This avoids the client and server trying to write
499
+ -- to the same file.
500
+ SslKeyLogFromEnv
501
+ (clientAuthority port)
502
+
503
+ Nothing ->
504
+ Client. ServerInsecure
505
+ (clientAuthority port)
494
506
where
495
507
correctClientSetup :: Client. ServerValidation
496
508
correctClientSetup =
497
509
Client. ValidateServer $
498
510
Client. certStoreFromPath pubCert
499
511
500
- clientAuthority :: Client. Address
501
- clientAuthority =
512
+ clientAuthority :: PortNumber -> Client. Address
513
+ clientAuthority port =
502
514
case useTLS cfg of
503
515
Just _tlsSetup -> Client. Address {
504
516
addressHost = " 127.0.0.1"
@@ -545,12 +557,14 @@ runTestClientServer (ClientServerTest cfg clientRun handlers) = do
545
557
let server :: (Server. RunningServer -> IO a ) -> IO a
546
558
server = withTestServer cfg firstTestFailure serverHandlerLock handlers
547
559
548
- let client :: PortNumber -> IO ()
560
+ let client :: Either FilePath PortNumber -> IO ()
549
561
client port = runTestClient cfg firstTestFailure port clientRun
550
562
551
563
-- Run the test
552
564
server $ \ runningServer -> do
553
- port <- Server. getServerPort runningServer
565
+ port <- case serverPort cfg of
566
+ Left unixPath -> pure $ Left unixPath
567
+ Right _ -> Right <$> Server. getServerPort runningServer
554
568
555
569
withAsync (client port) $ \ clientThread -> do
556
570
let failure = waitForFailure runningServer clientThread firstTestFailure
0 commit comments