fix tests so they pass on a self-signed single 21.10 node

This commit is contained in:
Nicolas Dextraze 2022-10-22 09:05:18 -04:00
parent 05e716e563
commit aa07b04dd3
5 changed files with 14 additions and 7 deletions

View File

@ -15,9 +15,10 @@ function safeParseJson(json) {
} }
} }
function ProjectionsClient(log, operationTimeout) { function ProjectionsClient(log, operationTimeout, rejectUnauthorized) {
this._log = log; this._log = log;
this._operationTimeout = operationTimeout; this._operationTimeout = operationTimeout;
this._rejectUnauthorized = typeof rejectUnauthorized === 'undefined' ? true : !!rejectUnauthorized;
} }
ProjectionsClient.prototype.enable = function(httpEndPoint, name, userCredentials) { ProjectionsClient.prototype.enable = function(httpEndPoint, name, userCredentials) {
@ -118,6 +119,9 @@ ProjectionsClient.prototype.request = function(method, _url, data, userCredentia
if (userCredentials) { if (userCredentials) {
options.auth = [userCredentials.username, userCredentials.password].join(':'); options.auth = [userCredentials.username, userCredentials.password].join(':');
} }
if (!this._rejectUnauthorized) {
options.rejectUnauthorized = false;
}
var self = this; var self = this;
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
const timeout = setTimeout(function () { const timeout = setTimeout(function () {

View File

@ -6,12 +6,13 @@ const ProjectionsClient = require('./projectionsClient');
* @param {Logger} log Instance of Logger to use for logging. * @param {Logger} log Instance of Logger to use for logging.
* @param {string} httpEndPoint HTTP endpoint of an Event Store server. * @param {string} httpEndPoint HTTP endpoint of an Event Store server.
* @param {number} operationTimeout Operation timeout in milliseconds. * @param {number} operationTimeout Operation timeout in milliseconds.
* @param {boolean} [rejectUnauthorized] Reject authorized SSL certs (if using SSL) - set to false is using self-signed certs
* @constructor * @constructor
*/ */
function ProjectionsManager(log, httpEndPoint, operationTimeout) { function ProjectionsManager(log, httpEndPoint, operationTimeout, rejectUnauthorized) {
ensure.notNull(log, "log"); ensure.notNull(log, "log");
ensure.notNull(httpEndPoint, "httpEndPoint"); ensure.notNull(httpEndPoint, "httpEndPoint");
this._client = new ProjectionsClient(log, operationTimeout); this._client = new ProjectionsClient(log, operationTimeout, rejectUnauthorized);
this._httpEndPoint = httpEndPoint; this._httpEndPoint = httpEndPoint;
} }
@ -211,4 +212,4 @@ ProjectionsManager.prototype.delete = function(name, deleteEmittedStreams, delet
return this._client.delete(this._httpEndPoint, name, deleteEmittedStreams, deleteStateStream, deleteCheckpointStream, userCredentials); return this._client.delete(this._httpEndPoint, name, deleteEmittedStreams, deleteStateStream, deleteCheckpointStream, userCredentials);
}; };
module.exports = ProjectionsManager; module.exports = ProjectionsManager;

View File

@ -12,6 +12,8 @@ protobufJS.configure();
var settings = { var settings = {
log: new NoopLogger(), log: new NoopLogger(),
useSslConnection: true,
validateServer: false
}; };
if (process.env.TESTS_VERBOSE_LOGGING === '1') { if (process.env.TESTS_VERBOSE_LOGGING === '1') {
settings.verboseLogging = true; settings.verboseLogging = true;

View File

@ -41,7 +41,7 @@ module.exports = {
done(); done();
} }
var self = this; var self = this;
this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped) this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped, adminCredentials)
.then(function(subscription) { .then(function(subscription) {
test.ok(subscription, "Subscription is null."); test.ok(subscription, "Subscription is null.");
return self.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent(), createRandomEvent()]); return self.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent(), createRandomEvent()]);

View File

@ -2,7 +2,7 @@ const client = require('../lib/dist');
const userCredentials = new client.UserCredentials('admin', 'changeit'); const userCredentials = new client.UserCredentials('admin', 'changeit');
const log = new client.NoopLogger(); const log = new client.NoopLogger();
const httpEndpoint = `http://${process.env.EVENTSTORE_HOST || "localhost"}:2113`; const httpEndpoint = `https://${process.env.EVENTSTORE_HOST || "localhost"}:2113`;
const operationTimeout = 5000; const operationTimeout = 5000;
const simpleProjection = "\ const simpleProjection = "\
@ -21,7 +21,7 @@ fromStream('$stats-127.0.0.1:2113')\
module.exports = { module.exports = {
setUp: function(cb) { setUp: function(cb) {
this.projectionsManager = new client.ProjectionsManager(log, httpEndpoint, operationTimeout); this.projectionsManager = new client.ProjectionsManager(log, httpEndpoint, operationTimeout, false);
cb(); cb();
}, },
'Create One Time Projection Happy Path': function(test) { 'Create One Time Projection Happy Path': function(test) {