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