diff --git a/web/src/Service.jsx b/web/src/Service.jsx index a5f4953..2d6e449 100644 --- a/web/src/Service.jsx +++ b/web/src/Service.jsx @@ -27,21 +27,8 @@ function Service(props) { const configMapWidgets = configMaps(service.pods, service.svc.metadata.namespace, capacitorClient) const secretWidgets = secrets(service.pods, service.svc.metadata.namespace, capacitorClient) - const svcPort = service.svc.spec.ports[0].port - let hostPort = "" - if (svcPort) { - if (svcPort <= 99) { - hostPort = "100" + svcPort - } else if (svcPort <= 999) { - hostPort = "10" + svcPort - } else { - hostPort = svcPort - } - - if (hostPort === "10080") { // Connections to HTTP, HTTPS or FTP servers on port 10080 will fail. This is a mitigation for the NAT Slipstream 2.0 attack. - hostPort = "10081" - } - } + const appPort = getAppPort(service.svc.spec.ports) ?? ""; + const hostPort = getHostPort(service.svc.spec.ports) ?? ""; return ( <> @@ -167,7 +154,7 @@ function Service(props) {
@@ -185,7 +172,7 @@ function Service(props) {

) : null } - {svcPort && + {service.svc.spec.ports && <> http://127.0.0.1:{hostPort} { + const port = getAppPort(undefined) + + expect(port).toBeUndefined(); +}); + +test('should return undefined for host port', () => { + const port = getHostPort(undefined) + + expect(port).toBeUndefined(); +}); + +test('should return "80" for app port', () => { + const ports = [{}]; + const port = getAppPort(ports) + + expect(port).toEqual("80"); +}); + +test('should return "5000" for app port', () => { + const ports = [{"port": 5000}]; + const port = getAppPort(ports) + + expect(port).toEqual("5000"); +}); + +test('should return "5000" for host port', () => { + const ports = [{"port": 5000}]; + const port = getHostPort(ports) + + expect(port).toEqual("5000"); +}); + +test('should return "10081" for host port', () => { + const ports = [{"port": 80}]; + const port = getHostPort(ports) + + expect(port).toEqual("10081"); +}); + +test('should return "10090 for host port', () => { + const ports = [{"port": 90}]; + const port = getHostPort(ports) + + expect(port).toEqual("10090"); +}); + +test('should return "10200 for host port', () => { + const ports = [{"port": 200}]; + const port = getHostPort(ports) + + expect(port).toEqual("10200"); +});