Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix endpoint selection when alternate hostnames are specified #881
- Loading branch information
1 parent
0cff4bc
commit e522f1f
Showing
17 changed files
with
675 additions
and
582 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/node-opcua-end2end-test/test/end_to_end/test_e2e_187.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
packages/node-opcua-end2end-test/test/end_to_end/test_e2e_881.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { get_mini_nodeset_filename, nodesets, OPCUAClient, OPCUAServer, UserTokenType } from "node-opcua"; | ||
import { networkInterfaces } from "os"; | ||
|
||
const doDebug = false; | ||
function getIpAddresses() { | ||
const nets = networkInterfaces(); | ||
const results: any = {}; | ||
for (const name of Object.keys(nets)) { | ||
for (const net of nets[name]!) { | ||
// skip over non-ipv4 and internal (i.e. 127.0.0.1) addresses | ||
if (net.family === "IPv4" && !net.internal) { | ||
if (!results[name]) { | ||
results[name] = []; | ||
} | ||
results[name].push(net.address); | ||
} | ||
} | ||
} | ||
if (doDebug) { | ||
console.log(results); | ||
} | ||
|
||
return [].concat.apply([], Object.values(results)); | ||
} | ||
const port = 2000; | ||
const ip = getIpAddresses(); | ||
|
||
async function startServer(): Promise<OPCUAServer> { | ||
// get IP of the machine | ||
const mini = get_mini_nodeset_filename(); | ||
if (doDebug) { | ||
console.log(ip); | ||
} | ||
const server = new OPCUAServer({ | ||
port, | ||
alternateHostname: ip, | ||
nodeset_filename: [mini], | ||
userManager: { | ||
isValidUser(userName: string, password: string): boolean { | ||
if (userName === "test" && password === "test") { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
}); | ||
await server.initialize(); | ||
await server.start(); | ||
if (doDebug) { | ||
console.log(`server started ${port}`); | ||
} | ||
return server; | ||
} | ||
// tslint:disable-next-line:no-var-requires | ||
const describe = require("node-opcua-leak-detector").describeWithLeakDetector; | ||
describe("building server with an AlternateName", () => { | ||
let server: OPCUAServer; | ||
before(async () => { | ||
server = await startServer(); | ||
}); | ||
after(async () => { | ||
await server.shutdown(); | ||
server.dispose(); | ||
}); | ||
it("should not confuse endpoints", async () => { | ||
const client = OPCUAClient.create({ endpoint_must_exist: false }); | ||
client.on("backoff", () => console.log("keep trying", endpointUri)); | ||
|
||
const endpointUri = `opc.tcp://${ip[0]}:${port}`; | ||
if (doDebug) { | ||
console.log("endpoint = ", endpointUri); | ||
} | ||
|
||
await client.connect(endpointUri); | ||
|
||
try { | ||
const session = await client.createSession({ | ||
type: UserTokenType.UserName, | ||
password: "test", | ||
userName: "test" | ||
}); | ||
await session.close(); | ||
} catch (err) { | ||
throw err; | ||
} finally { | ||
await client.disconnect(); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.