|
19 | 19 | var NodeChannel = require('../../lib/v1/internal/ch-node.js');
|
20 | 20 | var neo4j = require("../../lib/v1");
|
21 | 21 | var fs = require("fs");
|
| 22 | +var path = require('path'); |
22 | 23 | var hasFeature = require("../../lib/v1/internal/features");
|
23 | 24 |
|
24 | 25 | describe('trust-signed-certificates', function() {
|
@@ -76,6 +77,44 @@ describe('trust-on-first-use', function() {
|
76 | 77 |
|
77 | 78 | var driver;
|
78 | 79 |
|
| 80 | + it("should create known_hosts file including full path if it doesn't exist", function(done) { |
| 81 | + // Assuming we only run this test on NodeJS with TOFU support |
| 82 | + if( !hasFeature("trust_on_first_use") ) { |
| 83 | + done(); |
| 84 | + return; |
| 85 | + } |
| 86 | + |
| 87 | + // Given |
| 88 | + // Non existing directory |
| 89 | + var knownHostsDir = path.join("build", "hosts"); |
| 90 | + var knownHostsPath = path.join(knownHostsDir, "known_hosts"); |
| 91 | + try { |
| 92 | + fs.unlinkSync(knownHostsPath); |
| 93 | + } catch (_) { } |
| 94 | + try { |
| 95 | + fs.rmdirSync(knownHostsDir); |
| 96 | + } catch (_) { } |
| 97 | + |
| 98 | + var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"), { |
| 99 | + encrypted: true, |
| 100 | + trust: "TRUST_ON_FIRST_USE", |
| 101 | + knownHosts: knownHostsPath |
| 102 | + }); |
| 103 | + |
| 104 | + // When |
| 105 | + driver.session().run( "RETURN 1").then( function() { |
| 106 | + // Then we get to here. |
| 107 | + // And then the known_hosts file should have been created |
| 108 | + expect( function() { fs.accessSync(knownHostsPath) }).not.toThrow() |
| 109 | + done(); |
| 110 | + }).catch( function(){ |
| 111 | + // Just here to gracefully exit test on failure so we don't get timeouts |
| 112 | + // when done() isn't called. |
| 113 | + expect( 'this' ).toBe( 'to never happen' ); |
| 114 | + done(); |
| 115 | + }); |
| 116 | + }); |
| 117 | + |
79 | 118 | it('should not throw an error if the host file contains two host duplicates', function(done) {
|
80 | 119 | 'use strict';
|
81 | 120 | // Assuming we only run this test on NodeJS with TOFU support
|
@@ -141,60 +180,7 @@ describe('trust-on-first-use', function() {
|
141 | 180 | done();
|
142 | 181 | });
|
143 | 182 | });
|
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 |
| - |
| 183 | + |
198 | 184 | it('should should give helpful error if database cert does not match stored certificate', function(done) {
|
199 | 185 | // Assuming we only run this test on NodeJS with TOFU support
|
200 | 186 | if( !hasFeature("trust_on_first_use") ) {
|
|
0 commit comments