@@ -206,6 +206,66 @@ function TestFatalAlert() {
206
206
}
207
207
} ) ) ;
208
208
} ) ) ;
209
+
210
+ TestALPNFallback ( ) ;
211
+ }
212
+
213
+ function TestALPNFallback ( ) {
214
+ const serverOptions = {
215
+ ALPNProtocols : [ 'b' ] ,
216
+ allowALPNFallback : true
217
+ } ;
218
+
219
+ const clientOptions = [ {
220
+ ALPNProtocols : [ 'a' , 'b' ]
221
+ } , {
222
+ ALPNProtocols : [ 'a' ]
223
+ } ] ;
224
+
225
+ runTest ( clientOptions , serverOptions , function ( results ) {
226
+ // 'b' is selected by ALPN if available
227
+ checkResults ( results [ 0 ] ,
228
+ { server : { ALPN : 'b' } ,
229
+ client : { ALPN : 'b' } } ) ;
230
+
231
+ // 'a' is selected by ALPN if not, due to fallback
232
+ checkResults ( results [ 1 ] ,
233
+ { server : { ALPN : 'a' } ,
234
+ client : { ALPN : 'a' } } ) ;
235
+ } ) ;
236
+
237
+ TestEmptyALPNFallback ( ) ;
238
+ }
239
+
240
+ function TestEmptyALPNFallback ( ) {
241
+ const serverOptions = {
242
+ ALPNProtocols : [ ] ,
243
+ allowALPNFallback : true
244
+ } ;
245
+
246
+ const clientOptions = [ {
247
+ ALPNProtocols : [ 'a' , 'b' ]
248
+ } ] ;
249
+
250
+ runTest ( clientOptions , serverOptions , function ( results ) {
251
+ // 'a' is selected by ALPN, due to fallback with empty array
252
+ checkResults ( results [ 0 ] ,
253
+ { server : { ALPN : 'a' } ,
254
+ client : { ALPN : 'a' } } ) ;
255
+ } ) ;
256
+
257
+ TestFallbackWithoutProtocols ( ) ;
258
+ }
259
+
260
+ function TestFallbackWithoutProtocols ( ) {
261
+ assert . throws ( ( ) => {
262
+ tls . createServer ( {
263
+ allowALPNFallback : true
264
+ } ) ;
265
+ } , {
266
+ code : 'ERR_TLS_ALPN_FALLBACK_WITHOUT_PROTOCOLS' ,
267
+ message : 'The allowALPNFallback TLS option cannot be set without ALPNProtocols'
268
+ } ) ;
209
269
}
210
270
211
271
Test1 ( ) ;
0 commit comments