Skip to content

Commit 732fc33

Browse files
author
Stefan-Gabriel Muscalu
committed
Fix: readded missing should not duplicate fingerprint entries test
1 parent 07baedb commit 732fc33

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/internal/tls.test.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,60 @@ describe('trust-on-first-use', function() {
180180
done();
181181
});
182182
});
183+
184+
it('should not duplicate fingerprint entries', function(done) {
185+
// Assuming we only run this test on NodeJS with TOFU support
186+
if( !hasFeature("trust_on_first_use") ) {
187+
done();
188+
return;
189+
}
190+
191+
// Given
192+
var knownHostsPath = "build/known_hosts";
193+
if( fs.existsSync(knownHostsPath) ) {
194+
fs.unlinkSync(knownHostsPath);
195+
}
196+
fs.writeFileSync(knownHostsPath, '');
197+
198+
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
199+
encrypted: true,
200+
trust: "TRUST_ON_FIRST_USE",
201+
knownHosts: knownHostsPath
202+
});
203+
204+
// When
205+
driver.session();
206+
driver.session();
207+
208+
// Then
209+
setTimeout(function() {
210+
var lines = {};
211+
fs.readFileSync(knownHostsPath, 'utf8')
212+
.split('\n')
213+
.filter(function(line) {
214+
return !! (line.trim());
215+
})
216+
.forEach(function(line) {
217+
if (!lines[line]) {
218+
lines[line] = 0;
219+
}
220+
lines[line]++;
221+
});
222+
223+
var duplicatedLines = Object
224+
.keys(lines)
225+
.map(function(line) {
226+
return lines[line];
227+
})
228+
.filter(function(count) {
229+
return count > 1;
230+
})
231+
.length;
232+
233+
expect( duplicatedLines ).toBe( 0 );
234+
done();
235+
}, 1000);
236+
});
183237

184238
it('should should give helpful error if database cert does not match stored certificate', function(done) {
185239
// Assuming we only run this test on NodeJS with TOFU support

0 commit comments

Comments
 (0)