Skip to content

Commit c64c727

Browse files
author
Zhen
committed
Revert changes to prevent duplicates in known_host
This reverts commit 6723da8 and 6e38ec1
1 parent 6006a2f commit c64c727

File tree

2 files changed

+2
-73
lines changed

2 files changed

+2
-73
lines changed

src/v1/internal/ch-node.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,12 @@ function loadFingerprint( serverId, knownHostsPath, cb ) {
5656
});
5757
}
5858

59-
const _lockFingerprintFromAppending = {};
60-
function storeFingerprint( serverId, knownHostsPath, fingerprint ) {
61-
// we check if the serverId has been appended
62-
if(!!_lockFingerprintFromAppending[serverId]){
63-
// if it has, we ignore it
64-
return;
65-
}
66-
67-
// we make the line as appended
68-
// ( 1 is more efficient to store than true because true is an oddball )
69-
_lockFingerprintFromAppending[serverId] = 1;
70-
71-
// we append to file
59+
function storeFingerprint(serverId, knownHostsPath, fingerprint) {
7260
fs.appendFile(knownHostsPath, serverId + " " + fingerprint + EOL, "utf8", (err) => {
7361
if (err) {
7462
console.log(err);
7563
}
7664
});
77-
78-
// since the error occurs in the span of one tick
79-
// after one tick we clean up to not interfere with anything else
80-
setImmediate(() => {
81-
delete _lockFingerprintFromAppending[serverId];
82-
});
8365
}
8466

8567
const TrustStrategy = {

test/internal/tls.test.js

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -141,60 +141,7 @@ describe('trust-on-first-use', function() {
141141
done();
142142
});
143143
});
144-
145-
it('should not duplicate fingerprint entries', function(done) {
146-
// Assuming we only run this test on NodeJS with TOFU support
147-
if( !hasFeature("trust_on_first_use") ) {
148-
done();
149-
return;
150-
}
151-
152-
// Given
153-
var knownHostsPath = "build/known_hosts";
154-
if( fs.existsSync(knownHostsPath) ) {
155-
fs.unlinkSync(knownHostsPath);
156-
}
157-
fs.writeFileSync(knownHostsPath, '');
158-
159-
driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), {
160-
encrypted: true,
161-
trust: "TRUST_ON_FIRST_USE",
162-
knownHosts: knownHostsPath
163-
});
164-
165-
// When
166-
driver.session();
167-
driver.session();
168-
169-
setTimeout(function() {
170-
var lines = {};
171-
fs.readFileSync(knownHostsPath, 'utf8')
172-
.split('\n')
173-
.filter(function(line) {
174-
return !! (line.trim());
175-
})
176-
.forEach(function(line) {
177-
if (!lines[line]) {
178-
lines[line] = 0;
179-
}
180-
lines[line]++;
181-
});
182-
183-
var duplicatedLines = Object
184-
.keys(lines)
185-
.map(function(line) {
186-
return lines[line];
187-
})
188-
.filter(function(count) {
189-
return count > 1;
190-
})
191-
.length;
192-
193-
expect( duplicatedLines ).toBe( 0 );
194-
done();
195-
}, 1000);
196-
});
197-
144+
198145
it('should should give helpful error if database cert does not match stored certificate', function(done) {
199146
// Assuming we only run this test on NodeJS with TOFU support
200147
if( !hasFeature("trust_on_first_use") ) {

0 commit comments

Comments
 (0)