@@ -8,6 +8,7 @@ import * as protoLoader from '@grpc/proto-loader';
88import { Client , NamespaceNotFoundError , WorkflowNotFoundError } from '@temporalio/client' ;
99import { InternalConnectionOptions , InternalConnectionOptionsSymbol } from '@temporalio/client/lib/connection' ;
1010import { IllegalStateError , NativeConnection , NativeConnectionOptions , TransportError } from '@temporalio/worker' ;
11+ import { toNativeClientOptions } from '@temporalio/worker/lib/connection-options' ;
1112import { temporal } from '@temporalio/proto' ;
1213import { TestWorkflowEnvironment } from '@temporalio/testing' ;
1314import { RUN_INTEGRATION_TESTS , Worker } from './helpers' ;
@@ -475,3 +476,18 @@ test('setMetadata accepts binary headers', async (t) => {
475476 await connection . close ( ) ;
476477 server . forceShutdown ( ) ;
477478} ) ;
479+
480+ test ( 'NativeConnection: TLS is enabled by default when apiKey is provided and tls is not configured' , ( t ) => {
481+ // Use toNativeClientOptions to inspect the resulting config without actually connecting
482+ const options = toNativeClientOptions ( { apiKey : 'test-api-key' } ) ;
483+ // When TLS is enabled, targetUrl should use https://
484+ t . true ( options . targetUrl . startsWith ( 'https://' ) , 'targetUrl should use https when apiKey is provided' ) ;
485+ t . not ( options . tls , null , 'TLS config should not be null when apiKey is provided' ) ;
486+ } ) ;
487+
488+ test ( 'NativeConnection: TLS can be explicitly disabled even when apiKey is provided' , ( t ) => {
489+ const options = toNativeClientOptions ( { apiKey : 'test-api-key' , tls : false } ) ;
490+ // When TLS is explicitly disabled, targetUrl should use http://
491+ t . true ( options . targetUrl . startsWith ( 'http://' ) , 'targetUrl should use http when tls: false' ) ;
492+ t . is ( options . tls , null , 'TLS config should be null when tls: false' ) ;
493+ } ) ;
0 commit comments