@@ -80,7 +80,7 @@ describe('sendEmailNotification', () => {
80
80
} ;
81
81
82
82
await expect ( sendEmailNotification ( notificationInfo , errors , false ) ) . resolves . not . toThrow ( ) ;
83
- expect ( createTransportSpy ) . toBeCalledWith ( { host : notificationInfo . host , port : notificationInfo . port , tls : { rejectUnauthorized : false } } ) ;
83
+ expect ( createTransportSpy ) . toBeCalledWith ( { host : notificationInfo . host , port : notificationInfo . port , tls : { rejectUnauthorized : notificationInfo . tlsRejectUnauthorized } } ) ;
84
84
expect ( sendMailMock ) . toBeCalled ( ) ;
85
85
const sendMailMockArgs = sendMailMock . mock . calls [ 0 ] [ 0 ] ;
86
86
expect ( sendMailMockArgs . to ) . toEqual ( notificationInfo . to ) ;
@@ -94,6 +94,48 @@ describe('sendEmailNotification', () => {
94
94
expect ( sendMailMockArgs . text ) . not . toMatch ( / E r r o r a t l i n e 4 ` / i) ;
95
95
} ) ;
96
96
97
+ it ( 'should send an email with tlsRejectUnauthorized set to true, false, and not set' , async ( ) => {
98
+ const notificationInfoTLSFalse = {
99
+ host : 'my.host.com' ,
100
+ to : [ 'something@example.com' , 'someone@example.com' ] ,
101
+ tlsRejectUnauthorized : false ,
102
+ } ;
103
+ const notificationInfoTLSTrue = {
104
+ host : 'my.host.com' ,
105
+ to : [ 'something@example.com' , 'someone@example.com' ] ,
106
+ tlsRejectUnauthorized : true ,
107
+ } ;
108
+ const notificationInfoNoTLS = {
109
+ host : 'my.host.com' ,
110
+ to : [ 'something@example.com' , 'someone@example.com' ] ,
111
+ } ;
112
+ const notificationInfoUnexpectedTLS = {
113
+ host : 'my.host.com' ,
114
+ to : [ 'something@example.com' , 'someone@example.com' ] ,
115
+ tlsRejectUnauthorized : 'true' , // Any value that is not true or false will log a warning and not be used
116
+ } ;
117
+ const errors = {
118
+ 0 : [ ] ,
119
+ 1 : [ { message : 'something bad' , stack : 'Error at line 1' } ] ,
120
+ } ;
121
+ createTransportSpy . mockReturnValueOnce ( { sendMail : sendMailMock } ) ;
122
+ await expect ( sendEmailNotification ( notificationInfoTLSFalse , errors , false ) ) . resolves . not . toThrow ( ) ;
123
+ expect ( createTransportSpy ) . toBeCalledWith ( { host : notificationInfoTLSFalse . host , port : notificationInfoTLSFalse . port , tls : { rejectUnauthorized : false } } ) ;
124
+
125
+ createTransportSpy . mockReturnValueOnce ( { sendMail : sendMailMock } ) ;
126
+ await expect ( sendEmailNotification ( notificationInfoTLSTrue , errors , false ) ) . resolves . not . toThrow ( ) ;
127
+ expect ( createTransportSpy ) . toBeCalledWith ( { host : notificationInfoTLSTrue . host , port : notificationInfoTLSTrue . port , tls : { rejectUnauthorized : true } } ) ;
128
+
129
+ createTransportSpy . mockReturnValueOnce ( { sendMail : sendMailMock } ) ;
130
+ await expect ( sendEmailNotification ( notificationInfoNoTLS , errors , false ) ) . resolves . not . toThrow ( ) ;
131
+ expect ( createTransportSpy ) . toBeCalledWith ( { host : notificationInfoNoTLS . host , port : notificationInfoNoTLS . port } ) ; // No tls object set
132
+
133
+ createTransportSpy . mockReturnValueOnce ( { sendMail : sendMailMock } ) ;
134
+ await expect ( sendEmailNotification ( notificationInfoUnexpectedTLS , errors , false ) ) . resolves . not . toThrow ( ) ;
135
+ // A warning will be logged and the unexpected value will not be used
136
+ expect ( createTransportSpy ) . toBeCalledWith ( { host : notificationInfoUnexpectedTLS . host , port : notificationInfoUnexpectedTLS . port } ) ;
137
+ } ) ;
138
+
97
139
it ( 'should send an email with stack traces if debug flag was used' , async ( ) => {
98
140
createTransportSpy . mockReturnValueOnce ( { sendMail : sendMailMock } ) ;
99
141
const notificationInfo = {
0 commit comments