41 lines
2.1 KiB
Java
41 lines
2.1 KiB
Java
package com.workbenchclassic.hmi;
|
|
|
|
import com.sun.net.httpserver.HttpServer;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.URL;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
|
|
/** Isolated integration test: local JNLP endpoint, no real MES connection. */
|
|
public final class HmiWorkplaceClusterSelfTest {
|
|
private HmiWorkplaceClusterSelfTest() {}
|
|
public static void main(String[] args) throws Exception {
|
|
Path jnlp=Path.of(args[0]);
|
|
byte[] original=Files.readAllBytes(jnlp);
|
|
HttpServer server=HttpServer.create(new InetSocketAddress("127.0.0.1",0),0);
|
|
server.createContext("/Workplace.jnlp",exchange -> {
|
|
exchange.getResponseHeaders().add("Content-Type","application/x-java-jnlp-file");
|
|
exchange.sendResponseHeaders(200,original.length);
|
|
try(var out=exchange.getResponseBody()){out.write(original);}
|
|
});
|
|
server.start();
|
|
try {
|
|
URL url=new URL("http://127.0.0.1:"+server.getAddress().getPort()+"/Workplace.jnlp");
|
|
HmiWorkplaceManifest manifest=HmiWorkplaceManifest.fetch(url,"https://mon-svwin021136.itac.intra:8181/mes");
|
|
if (!manifest.rewritten.contains("name=\"itac.artes.clusternodes\""))
|
|
throw new AssertionError("Missing cluster nodes property");
|
|
if (!manifest.rewritten.contains("value=\"https://mon-svwin021136.itac.intra:8181/mes\""))
|
|
throw new AssertionError("Missing cluster nodes URL");
|
|
if (manifest.jars.size()<100)throw new AssertionError("Missing JNLP jar dependencies: "+manifest.jars.size());
|
|
if (!manifest.rewritten.contains("/backend/api/hmi/v1/cheerpj/workplace/jars"))
|
|
throw new AssertionError("Unrewritten codebase");
|
|
try {
|
|
HmiWorkplaceManifest.fetch(url,"https://evil.example.com/");
|
|
throw new AssertionError("Wrong MES path accepted");
|
|
} catch(java.io.IOException correct) { /* expected */ }
|
|
System.out.println("JNLP cluster property test: OK; jars="+manifest.jars.size());
|
|
} finally {server.stop(0);}
|
|
}
|
|
}
|