@@ -90,25 +90,28 @@ describe('trust-on-first-use', function() {
9090 fs . unlinkSync ( knownHostsPath ) ;
9191 }
9292
93- fs . writeFileSync (
94- knownHostsPath ,
95- 'localhost:7687 abcd\n' +
96- 'localhost:7687 abcd'
97- ) ;
98-
9993 driver = neo4j . driver ( "bolt://localhost" , neo4j . auth . basic ( "neo4j" , "neo4j" ) , {
10094 encrypted : true ,
10195 trust : "TRUST_ON_FIRST_USE" ,
10296 knownHosts : knownHostsPath
10397 } ) ;
10498
99+ driver . session ( ) ; // write into the knownHost file
100+
101+ // duplicate the same serverId twice
102+ setTimeout ( function ( ) {
103+ var text = fs . readFileSync ( knownHostsPath , 'utf8' ) ;
104+ fs . writeFileSync ( knownHostsPath , text + text ) ;
105+ } , 1000 ) ;
106+
105107 // When
106- driver . session ( ) . run ( "RETURN true AS a" ) . then ( function ( data ) {
107- // Then we get to here.
108- // And then the known_hosts file should have correct contents
109- expect ( data . records [ 0 ] . get ( 'a' ) ) . toBe ( true ) ;
110- done ( ) ;
111- } ) ;
108+ setTimeout ( function ( ) {
109+ driver . session ( ) . run ( "RETURN true AS a" ) . then ( function ( data ) {
110+ // Then we get to here.
111+ expect ( data . records [ 0 ] . get ( 'a' ) ) . toBe ( true ) ;
112+ done ( ) ;
113+ } ) ;
114+ } , 2000 ) ;
112115 } ) ;
113116
114117 it ( 'should accept previously un-seen hosts' , function ( done ) {
@@ -164,7 +167,7 @@ describe('trust-on-first-use', function() {
164167 driver . session ( ) ;
165168
166169 setTimeout ( function ( ) {
167- expect ( fs . readFileSync ( knownHostsPath , 'utf8' ) . split ( '\n' ) . length ) . toBe ( 1 ) ;
170+ expect ( fs . readFileSync ( knownHostsPath , 'utf8' ) . trim ( ) . split ( '\n' ) . length ) . toBe ( 1 ) ;
168171 done ( ) ;
169172 } , 1000 ) ;
170173 } ) ;
0 commit comments