11'use strict' ;
2- var common = require ( '../common' ) ;
3- var assert = require ( 'assert' ) ;
2+ const common = require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
44
55if ( ! common . hasCrypto ) {
66 common . skip ( 'missing crypto' ) ;
77 return ;
88}
9- var tls = require ( 'tls' ) ;
9+ const tls = require ( 'tls' ) ;
1010
11- var fs = require ( 'fs' ) ;
11+ const fs = require ( 'fs' ) ;
1212
1313
14- var options = {
14+ const options = {
1515 key : fs . readFileSync ( common . fixturesDir + '/keys/agent2-key.pem' ) ,
1616 cert : fs . readFileSync ( common . fixturesDir + '/keys/agent2-cert.pem' )
1717} ;
1818
19- var message = 'hello world\n' ;
19+ // Contains a UTF8 only character
20+ const messageUtf8 = 'x√ab c' ;
2021
22+ // The same string above represented with ASCII
23+ const messageAscii = 'xb\b\u001aab c' ;
2124
22- var server = tls . Server ( options , common . mustCall ( function ( socket ) {
23- socket . end ( message ) ;
25+ const server = tls . Server ( options , common . mustCall ( function ( socket ) {
26+ socket . end ( messageUtf8 ) ;
2427} ) ) ;
2528
2629
2730server . listen ( 0 , function ( ) {
28- var client = tls . connect ( {
31+ const client = tls . connect ( {
2932 port : this . address ( ) . port ,
3033 rejectUnauthorized : false
3134 } ) ;
3235
33- var buffer = '' ;
36+ let buffer = '' ;
3437
35- client . setEncoding ( 'utf8 ' ) ;
38+ client . setEncoding ( 'ascii ' ) ;
3639
3740 client . on ( 'data' , function ( d ) {
3841 assert . ok ( typeof d === 'string' ) ;
@@ -44,10 +47,16 @@ server.listen(0, function() {
4447 // readyState is deprecated but we want to make
4548 // sure this isn't triggering an assert in lib/net.js
4649 // See issue #1069.
47- assert . equal ( 'closed' , client . readyState ) ;
50+ assert . strictEqual ( 'closed' , client . readyState ) ;
51+
52+ // Confirming the buffer string is encoded in ASCII
53+ // and thus does NOT match the UTF8 string
54+ assert . notEqual ( buffer , messageUtf8 ) ;
55+
56+ // Confirming the buffer string is encoded in ASCII
57+ // and thus does equal the ASCII string representation
58+ assert . strictEqual ( buffer , messageAscii ) ;
4859
49- assert . equal ( buffer , message ) ;
50- console . log ( message ) ;
5160 server . close ( ) ;
5261 } ) ;
5362} ) ;
0 commit comments