Skip to content

Commit

Permalink
chore: test adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Jun 4, 2023
1 parent 578b1fd commit aa95d2a
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import * as path from "path";
import * as fs from "fs";
import "mocha";
import "should";
import rimraf from "rimraf";
import should from "should";

import { CertificateAuthority } from "node-opcua-pki";
import { StatusCodes } from "node-opcua-status-code";
Expand Down Expand Up @@ -77,7 +77,7 @@ async function createFreshCertificateManager(options: OPCUACertificateManagerOpt

if (fs.existsSync(temporaryFolder)) {
await rimraf.sync(temporaryFolder);
await fs.mkdirSync(temporaryFolder);
fs.mkdirSync(temporaryFolder);
}
const certificateMgr = new OPCUACertificateManager(options);
await certificateMgr.initialize();
Expand All @@ -87,7 +87,7 @@ async function createFreshCertificateManager(options: OPCUACertificateManagerOpt
// tslint:disable-next-line:no-var-requires
const describe = require("node-opcua-leak-detector").describeWithLeakDetector;
describe("Testing OPCUA Client Certificate Manager", function (this: any) {
this.timeout(Math.max(40000,this.timeout()));
this.timeout(Math.max(40000, this.timeout()));

let certificateMgr: OPCUACertificateManager;
let certificateMgrWithNoIssuerCert: OPCUACertificateManager;
Expand All @@ -96,7 +96,9 @@ describe("Testing OPCUA Client Certificate Manager", function (this: any) {
let certificateSelfSigned: Certificate;

before(async () => await initializeDemoCertificates());
after(async () => {/** */});
after(async () => {
/** */
});
beforeEach(async () => {
// create a PKI with no issuer certificate
const temporaryFolder2 = path.join(_tmpFolder, "testing_certificates");
Expand Down Expand Up @@ -264,7 +266,7 @@ describe("Testing OPCUA Client Certificate Manager", function (this: any) {
});

describe("Testing OPCUA Certificate Manager with automatically acceptance of unknown certificate", function (this: any) {
this.timeout(Math.max(40000,this.timeout()));
this.timeout(Math.max(40000, this.timeout()));

let acceptingCertificateMgr: OPCUACertificateManager;
let rejectingCertificateMgr: OPCUACertificateManager;
Expand Down
2 changes: 1 addition & 1 deletion packages/node-opcua-client/test/test_issue_931.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("issue #931 investigation", function () {
securityMode: MessageSecurityMode.SignAndEncrypt,
securityPolicy: SecurityPolicy.Basic256Sha256
};
await doTest(options, "localhost");
await doTest(options, os.hostname());
});
it("931-B should be able to disconnect when the client is trying to initially connect to a server - With Security - hostname", async () => {
const options = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as os from "os";
import "should";
import "mocha";
import chalk from "chalk";
Expand Down Expand Up @@ -30,7 +31,7 @@ const users = [
];

const port = 2237;
const endpointUrl = `opc.tcp://localhost:${port}`;
const endpointUrl = `opc.tcp://${os.hostname()}:${port}`;
const nodeId = "ns=1;s=SecretValue";

async function startServer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as os from "os";
import { ClientSession, DataType, DiagnosticInfo, OPCUAClient, OPCUAServer, StatusCodes } from "node-opcua";
import should from "should";

Expand Down Expand Up @@ -49,7 +50,7 @@ describe("list status codes for input arguments", () => {
callback(null, { statusCode: StatusCodes.Good, inputArgumentResults: [StatusCodes.Good] });
});
await server.start();
await client.connect(`opc.tcp://localhost:${port}/UA/NodeOPCUA`);
await client.connect(`opc.tcp://${os.hostname()}:${port}/UA/NodeOPCUA`);
clientSession = await client.createSession();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from "path";
import * as fs from "fs";
import * as os from "os";
import "should";
import { DataType, OPCUAClient, OPCUAServer, nodesets, AttributeIds, UAObject, UAVariableT, UAVariable } from "node-opcua";

Expand Down Expand Up @@ -36,7 +37,7 @@ describe("testing github issue", function () {
server && (await server.shutdown());
});
it("should be possible ", async () => {
const endpointUrl = `opc.tcp://localhost:${port}`;
const endpointUrl = `opc.tcp://${os.hostname()}:${port}`;

const client = OPCUAClient.create({ endpointMustExist: false });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ describe("KJH2 testing ability for client to reconnect when server close connect
});

it("TR14 - it should be possible to disconnect a client which is attempting to establish it's first connection to a unavailable server", async () => {
const endpointUrl = "opc.tcp://localhost:11111"; // uri of an unavailable opcua server
const endpointUrl = `opc.tcp://${os.hostname()}:11111`; // uri of an unavailable opcua server

// use robust connectionStrategy
await f(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as os from "os";
import { allPermissions, OPCUAClient, OPCUAServer, StatusCodes, UserTokenType, WellKnownRoles, makeRoles } from "node-opcua";
import "should";

Expand Down Expand Up @@ -57,7 +58,7 @@ describe("Issue #896: Check Authorization for UAMethods", () => {
callback(null, { statusCode: StatusCodes.Good });
});
await server.start();
return client.connect(`opc.tcp://localhost:${port}/UA/NodeOPCUA`);
return client.connect(`opc.tcp://${os.hostname()}:${port}/UA/NodeOPCUA`);
});

after(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2003,8 +2003,7 @@ module.exports = function (test) {
if (process.platform === "darwin") {
return done(); // skipping on MacOS
}
//xx endpointUrl = "opc.tcp://localhost:2200/OPCUA/SimulationServer";


// from Spec OPCUA Version 1.03 Part 4 - 5.13.1.1 Description : Page 69
// h. Subscriptions have a lifetime counter that counts the number of consecutive publishing cycles in
// which there have been no Publish requests available to send a Publish response for the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
const os = require("os");
const should = require("should");
const {OPCUAClient} = require("node-opcua");

Expand Down Expand Up @@ -68,7 +69,7 @@ module.exports = function(test) {

const match = test.endpointUrl.match(/:([0-9]*)$/);
const port = parseInt(match[1],10);
const endpointUrl = `opc.tcp://localhost:${port}`;
const endpointUrl = `opc.tcp://${os.hostname()}:${port}`;
// console.log(endpointUrl);
const { createSessionResponse, err }= await testCreateSessionResponse(endpointUrl);
should.not.exist(err);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// tslint:disable:no-console
import * as path from "path";
import * as os from "os";

import "should";
import { types } from "util";
import chalk from "chalk";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as os from "os";
import { OPCUAServer, OPCUAClient } from "node-opcua";
import should from "should";
import { createServerCertificateManager } from "../test_helpers/createServerCertificateManager";
Expand All @@ -7,7 +8,7 @@ const port = 2004;
const describe = require("node-opcua-leak-detector").describeWithLeakDetector;
describe("Verifying Server Endpoint", () => {
let server: OPCUAServer;
let endpointUri = `opc.tcp://localhost:${port}`;
let endpointUri = `opc.tcp://${os.hostname()}:${port}`;
before(async () => {
const serverCertificateManager = await createServerCertificateManager(port);
server = new OPCUAServer({ port, serverCertificateManager });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

const os = require("os");
const { promisify } = require("util");
const should = require("should");
const { ReadRequest } = require("node-opcua-types");
Expand Down Expand Up @@ -62,7 +63,7 @@ describe("Testing ClientSecureChannel 1", function () {
client_has_received_close_event += 1;
});

secureChannel.create("opc.tcp://localhost:8888/UA/Sample", function (err) {
secureChannel.create("opc.tcp://"+ os.hostname()+ ":8888/UA/Sample", function (err) {
should(err).be.instanceOf(Error);
err.message.should.match(/connect ECONNREFUSED/);
client_has_received_close_event.should.eql(0);
Expand Down Expand Up @@ -127,7 +128,7 @@ describe("Testing ClientSecureChannel 2", function () {
/** */
}
});
secureChannel.create(`opc.tcp://localhost:${port}/UA/Sample`, function (err) {
secureChannel.create(`opc.tcp://${os.hostname()}:${port}/UA/Sample`, function (err) {
should(!err).be.eql(true, "connection expected to succeed");

secureChannel.close(function () {
Expand All @@ -152,7 +153,7 @@ describe("Testing ClientSecureChannel with BackOff reconnection strategy", funct
};
const secureChannel = new ClientSecureChannelLayer(options);

const endpoint = `opc.tcp://localhost:${port}/UA/Sample`;
const endpoint = `opc.tcp://${os.hostname()}:${port}/UA/Sample`;
let nbRetry = 0;
secureChannel.on("backoff", function (number, delay) {
debugLog(number + " " + delay + "ms");
Expand All @@ -179,7 +180,7 @@ describe("Testing ClientSecureChannel with BackOff reconnection strategy", funct

const secureChannel = new ClientSecureChannelLayer(options);

const endpoint = `opc.tcp://localhost:${port}/UA/Sample`;
const endpoint = `opc.tcp://${os.hostname()}:${port}/UA/Sample`;
let nbRetry = 0;

secureChannel.on("backoff", function (number, delay) {
Expand Down Expand Up @@ -221,7 +222,7 @@ describe("Testing ClientSecureChannel with BackOff reconnection strategy", funct

const secureChannel = new ClientSecureChannelLayer(options);

const endpoint = `opc.tcp://localhost:${port}/UA/Sample`;
const endpoint = `opc.tcp://${os.hostname()}:${port}/UA/Sample`;
let nbRetry = 0;

secureChannel.on("backoff", function (number, delay) {
Expand Down Expand Up @@ -285,7 +286,7 @@ describe("Testing ClientSecureChannel with BackOff reconnection strategy", funct

await promisify(startServer)(holder, port);

const endpoint = `opc.tcp://localhost:${port}/UA/Sample`;
const endpoint = `opc.tcp://${os.hostname()}:${port}/UA/Sample`;
await promisify(secureChannel.create).call(secureChannel, endpoint);

//-----------------------------------------------------------------
Expand Down Expand Up @@ -344,7 +345,7 @@ describe("Testing ClientSecureChannel with BackOff reconnection strategy", funct
await promisify(startServer)(holder, port);

try {
const endpoint = `opc.tcp://localhost:${port}/UA/Sample`;
const endpoint = `opc.tcp://${os.hostname()}:${port}/UA/Sample`;
await promisify(secureChannel.create).call(secureChannel, endpoint);
secureChannel._closeWithError(StatusCodes.Bad, new Error("Sabotage"));
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const os = require("os");
const should = require("should");

const { HelloMessage } = require("node-opcua-transport");
Expand Down Expand Up @@ -379,7 +380,7 @@ describe("testing ServerSecureChannelLayer ", function () {
sendBufferSize: 8 * 1024,
maxMessageSize: 16 * 1024,
maxChunkCount: 2,
endpointUrl: "opc.tcp://localhost:1234/SomeEndpoint"
endpointUrl: `opc.tcp://${os.hostname()}:1234/SomeEndpoint`
});
await send1("HEL", helloMessage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function installTestFor(TransportPair) {
});

afterEach((done) => {
transportPair.shutdown(done);
transportPair.shutdown(()=>{
setTimeout(done,10);
});
});

/** @type {ServerTCP_transport} */
Expand Down Expand Up @@ -91,7 +93,9 @@ function installTestFor(TransportPair) {
if (spyOnConnect.callCount === 1) {
spyOnClose.callCount.should.equal(1);
}
done();
setTimeout(()=>{
done();
}, 100);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class HalfComChannel extends EventEmitter implements ISocketLike{
if (this._ended) return;
this._ended = true;
if (this._timeoutId) clearTimeout(this._timeoutId);
this._timeoutId = null;
this._timeoutId = null;HalfComChannel;
this.timeout = 0;
this._disconnectOtherParty();
this.emit("end");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ export class TransportPairSocket implements ITransportPair {
}

public shutdown(done: (err?: Error) => void): void {
this.client.end();
this._server.shutdown((err?: Error) => {
done(err);
this.client.end(() => {
this._server.shutdown((err?: Error) => {
done(err);
});
});
}
}

0 comments on commit aa95d2a

Please sign in to comment.