Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | // Copyright (c) ZeroC, Inc.
import { Ice } from "@zeroc/ice";
import { Test } from "./Test.js";
import { TestHelper, test } from "../../Common/TestHelper.js";
function getTCPEndpointInfo(info) {
let p = info;
do {
if (p instanceof Ice.TCPEndpointInfo) {
return p;
}
p = p.underlying;
} while (p !== null);
return null;
}
function getTCPConnectionInfo(info) {
let p = info;
do {
if (p instanceof Ice.TCPConnectionInfo) {
return p;
}
p = p.underlying;
} while (p !== null);
return null;
}
export class Client extends TestHelper {
async allTests() {
const out = this.getWriter();
const communicator = this.communicator();
const defaultHost = communicator.getProperties().getIceProperty("Ice.Default.Host");
out.write("testing proxy endpoint information... ");
const ref = "test -t:default -h tcphost -p 10000 -t 1200 -z --sourceAddress 10.10.10.10:opaque -e 1.8 -t 100 -v ABCD";
const p1 = new Ice.ObjectPrx(communicator, ref);
const endpoints = p1.ice_getEndpoints();
const endpoint = endpoints[0].getInfo();
const ipEndpoint = getTCPEndpointInfo(endpoint);
test(ipEndpoint !== null);
test(ipEndpoint.host == "tcphost");
test(ipEndpoint.port == 10000);
test(ipEndpoint.timeout == 1200);
test(ipEndpoint.sourceAddress == "10.10.10.10");
test(ipEndpoint.compress);
test((ipEndpoint.type() == Ice.TCPEndpointType && !ipEndpoint.secure()) ||
(ipEndpoint.type() == Ice.WSEndpointType && !ipEndpoint.secure()) ||
(ipEndpoint.type() == Ice.WSSEndpointType && ipEndpoint.secure()));
test((ipEndpoint.type() == Ice.TCPEndpointType && endpoint instanceof Ice.TCPEndpointInfo) ||
(ipEndpoint.type() == Ice.WSEndpointType && endpoint instanceof Ice.WSEndpointInfo) ||
(ipEndpoint.type() == Ice.WSSEndpointType && endpoint instanceof Ice.WSEndpointInfo));
const opaqueEndpoint = endpoints[1].getInfo();
test(opaqueEndpoint.rawEncoding.equals(new Ice.EncodingVersion(1, 8)));
out.writeLine("ok");
out.write("testing connection endpoint information... ");
const testIntf = new Test.TestIntfPrx(communicator, `test:${this.getTestEndpoint()}`);
const endpointPort = this.getTestPort(0);
let conn = await testIntf.ice_getConnection();
const ipinfo = getTCPEndpointInfo(conn.getEndpoint().getInfo());
test(ipinfo !== null);
test(ipinfo.port == endpointPort);
test(!ipinfo.compress);
test(ipinfo.host == defaultHost);
let ctx = await testIntf.getEndpointInfoAsContext();
test(ctx.get("host") == ipinfo.host);
test(ctx.get("compress") == "false");
const port = ctx.get("port");
test(port !== undefined);
test(parseInt(port) > 0);
out.writeLine("ok");
out.write("testing connection information... ");
conn = await testIntf.ice_getConnection();
const info = conn.getInfo();
const ipConnectionInfo = getTCPConnectionInfo(info);
test(ipConnectionInfo != null);
test(info.adapterName.length === 0);
if (conn.type() != "ws" && conn.type() != "wss") {
test(ipConnectionInfo.localPort > 0);
}
test(ipConnectionInfo.remotePort == endpointPort);
if (defaultHost == "127.0.0.1") {
test(ipConnectionInfo.remoteAddress == defaultHost);
if (conn.type() != "ws" && conn.type() != "wss") {
test(ipConnectionInfo.localAddress == defaultHost);
}
}
ctx = await testIntf.getConnectionInfoAsContext();
test(ctx.get("incoming") == "true");
test(ctx.get("adapterName") == "TestAdapter");
if (conn.type() != "ws" && conn.type() != "wss") {
test(ctx.get("remoteAddress") == ipConnectionInfo.localAddress);
test(ctx.get("localAddress") == ipConnectionInfo.remoteAddress);
test(parseInt(ctx.get("remotePort")) === ipConnectionInfo.localPort);
test(parseInt(ctx.get("localPort")) === ipConnectionInfo.remotePort);
}
function getHeader(ctx, key) {
return ctx.get(key) || ctx.get(key.toLowerCase());
}
if (conn.type() == "ws" || conn.type() == "wss") {
test(getHeader(ctx, "ws.Upgrade").toLowerCase() == "websocket");
test(getHeader(ctx, "ws.Connection").indexOf("Upgrade") >= 0 ||
getHeader(ctx, "ws.Connection").indexOf("upgrade") >= 0);
test(getHeader(ctx, "ws.Sec-WebSocket-Protocol") == "ice.zeroc.com");
test(getHeader(ctx, "ws.Sec-WebSocket-Version") == "13");
test(getHeader(ctx, "ws.Sec-WebSocket-Key") !== null);
}
out.writeLine("ok");
await testIntf.shutdown();
}
async run(args) {
let communicator = null;
try {
[communicator] = this.initialize(args);
await this.allTests();
}
finally {
if (communicator) {
await communicator.destroy();
}
}
}
}
|