11// Flags: --expose-internals
22import { mustCall , mustSucceed } from '../common/index.mjs' ;
3+ import fixtures from '../common/fixtures.js' ;
34import assert from 'node:assert' ;
45import {
56 checkExitData ,
@@ -13,17 +14,17 @@ const tests = [];
1314
1415tests . push ( {
1516 name : 'should work if agent is killed with signal' ,
16- test : async ( getEnv ) => {
17+ test : async ( getEnv , isSecure ) => {
1718 return new Promise ( ( resolve ) => {
18- const grpcServer = new GRPCServer ( ) ;
19+ const grpcServer = new GRPCServer ( { tls : isSecure } ) ;
1920 grpcServer . start ( mustSucceed ( async ( port ) => {
2021 grpcServer . on ( 'exit' , mustCall ( ( data ) => {
2122 checkExitData ( data . msg , data . metadata , agentId , { code : SIGTERM , error : null , profile : '' } ) ;
2223 grpcServer . close ( ) ;
2324 resolve ( ) ;
2425 } ) ) ;
2526
26- const env = getEnv ( port ) ;
27+ const env = getEnv ( port , isSecure ) ;
2728
2829 const opts = {
2930 stdio : [ 'inherit' , 'inherit' , 'inherit' , 'ipc' ] ,
@@ -39,17 +40,17 @@ tests.push({
3940
4041tests . push ( {
4142 name : 'should work if agent exits gracefully without error' ,
42- test : async ( getEnv ) => {
43+ test : async ( getEnv , isSecure ) => {
4344 return new Promise ( ( resolve ) => {
44- const grpcServer = new GRPCServer ( ) ;
45+ const grpcServer = new GRPCServer ( { tls : isSecure } ) ;
4546 grpcServer . start ( mustSucceed ( async ( port ) => {
4647 grpcServer . on ( 'exit' , mustCall ( ( data ) => {
4748 checkExitData ( data . msg , data . metadata , agentId , { code : 0 , error : null , profile : '' } ) ;
4849 grpcServer . close ( ) ;
4950 resolve ( ) ;
5051 } ) ) ;
5152
52- const env = getEnv ( port ) ;
53+ const env = getEnv ( port , isSecure ) ;
5354
5455 const opts = {
5556 stdio : [ 'inherit' , 'inherit' , 'inherit' , 'ipc' ] ,
@@ -68,17 +69,17 @@ tests.push({
6869
6970tests . push ( {
7071 name : 'should work if agent exits gracefully with error code' ,
71- test : async ( getEnv ) => {
72+ test : async ( getEnv , isSecure ) => {
7273 return new Promise ( ( resolve ) => {
73- const grpcServer = new GRPCServer ( ) ;
74+ const grpcServer = new GRPCServer ( { tls : isSecure } ) ;
7475 grpcServer . start ( mustSucceed ( async ( port ) => {
7576 grpcServer . on ( 'exit' , mustCall ( ( data ) => {
7677 checkExitData ( data . msg , data . metadata , agentId , { code : 1 , error : null , profile : '' } ) ;
7778 grpcServer . close ( ) ;
7879 resolve ( ) ;
7980 } ) ) ;
8081
81- const env = getEnv ( port ) ;
82+ const env = getEnv ( port , isSecure ) ;
8283
8384 const opts = {
8485 stdio : [ 'inherit' , 'inherit' , 'inherit' , 'ipc' ] ,
@@ -97,9 +98,9 @@ tests.push({
9798
9899tests . push ( {
99100 name : 'should work if agent exits with exception' ,
100- test : async ( getEnv ) => {
101+ test : async ( getEnv , isSecure ) => {
101102 return new Promise ( ( resolve ) => {
102- const grpcServer = new GRPCServer ( ) ;
103+ const grpcServer = new GRPCServer ( { tls : isSecure } ) ;
103104 grpcServer . start ( mustSucceed ( async ( port ) => {
104105 grpcServer . on ( 'exit' , mustCall ( ( data ) => {
105106 const error = { message : 'Uncaught Error: error' , stack : '' } ;
@@ -108,7 +109,7 @@ tests.push({
108109 resolve ( ) ;
109110 } ) ) ;
110111
111- const env = getEnv ( port ) ;
112+ const env = getEnv ( port , isSecure ) ;
112113
113114 const opts = {
114115 stdio : [ 'inherit' , 'inherit' , 'inherit' , 'ipc' ] ,
@@ -127,28 +128,41 @@ tests.push({
127128
128129const testConfigs = [
129130 {
130- getEnv : ( port ) => {
131- return {
131+ getEnv : ( port , isSecure ) => {
132+ const env = {
132133 NODE_DEBUG_NATIVE : 'nsolid_grpc_agent' ,
133- NSOLID_GRPC_INSECURE : 1 ,
134134 NSOLID_GRPC : `localhost:${ port } ` ,
135135 } ;
136+ if ( ! isSecure ) {
137+ env . NSOLID_GRPC_INSECURE = 1 ;
138+ } else {
139+ env . NSOLID_GRPC_CERTS = fixtures . path ( 'keys' , 'selfsigned-no-keycertsign' , 'cert.pem' ) ;
140+ }
141+ return env ;
136142 } ,
137143 } ,
138144 {
139- getEnv : ( port ) => {
140- return {
145+ getEnv : ( port , isSecure ) => {
146+ const env = {
141147 NODE_DEBUG_NATIVE : 'nsolid_grpc_agent' ,
142- NSOLID_GRPC_INSECURE : 1 ,
143148 NSOLID_SAAS : `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbtesting.localhost:${ port } ` ,
144149 } ;
150+ if ( ! isSecure ) {
151+ env . NSOLID_GRPC_INSECURE = 1 ;
152+ } else {
153+ env . NSOLID_GRPC_CERTS = fixtures . path ( 'keys' , 'selfsigned-no-keycertsign' , 'cert.pem' ) ;
154+ }
155+ return env ;
145156 } ,
146157 } ,
147158] ;
148159
160+ const isSecureOpts = [ false , true ] ;
149161for ( const testConfig of testConfigs ) {
150162 for ( const { name, test } of tests ) {
151- console . log ( `[basic] ${ name } ` ) ;
152- await test ( testConfig . getEnv ) ;
163+ for ( const isSecure of isSecureOpts ) {
164+ console . log ( `[basic] ${ name } ${ isSecure ? 'secure' : 'insecure' } ` ) ;
165+ await test ( testConfig . getEnv , isSecure ) ;
166+ }
153167 }
154168}
0 commit comments