You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by pz...@apache.org on 2026/03/02 17:03:35 UTC
(knox) branch master updated: KNOX-3269 - Support APIKEY and CLIENTID as services without URLs or params in topology generation (#1167)
This is an automated email from the ASF dual-hosted git repository.
pzampino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new feb7dd11f KNOX-3269 - Support APIKEY and CLIENTID as services without URLs or params in topology generation (#1167)
feb7dd11f is described below
commit feb7dd11f12e24e0038d8e4b3a9094223c5b2356
Author: Phil Zampino <pz...@apache.org>
AuthorDate: Mon Mar 2 12:03:29 2026 -0500
KNOX-3269 - Support APIKEY and CLIENTID as services without URLs or params in topology generation (#1167)
---
.../simple/SimpleDescriptorHandlerTest.java | 83 +++++++++++++++-------
.../topology/simple/SimpleDescriptorHandler.java | 9 ++-
2 files changed, 64 insertions(+), 28 deletions(-)
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandlerTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandlerTest.java
index c33500c4b..9bab863e7 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandlerTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandlerTest.java
@@ -832,39 +832,68 @@ public class SimpleDescriptorHandlerTest {
@Test
public void shouldAllowKnoxServiceWithoutUrlsAndParams() throws Exception {
- File providerConfig = File.createTempFile("testKnoxProvider", ".xml");
- FileUtils.write(providerConfig, TEST_PROVIDER_CONFIG, StandardCharsets.UTF_8);
+ doTestShouldAllowServiceWithoutUrlsAndParams("KNOX");
+ }
- File topologyFile = null;
- try {
- final File destDir = new File(System.getProperty("java.io.tmpdir")).getCanonicalFile();
- final GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
- EasyMock.expect(gc.getReadOnlyOverrideTopologyNames()).andReturn(Collections.emptyList()).anyTimes();
+ @Test
+ public void shouldAllowAPIKeyServiceWithoutUrlsAndParams() throws Exception {
+ doTestShouldAllowServiceWithoutUrlsAndParams("APIKEY");
+ }
- final SimpleDescriptorImpl testDescriptor = new SimpleDescriptorImpl();
- testDescriptor.setProviderConfig(providerConfig.getAbsolutePath());
+ @Test
+ public void shouldAllowClientIDServiceWithoutUrlsAndParams() throws Exception {
+ doTestShouldAllowServiceWithoutUrlsAndParams("CLIENTID");
+ }
- final SimpleDescriptor.Service knoxService = EasyMock.createNiceMock(SimpleDescriptor.Service.class);
- EasyMock.expect(knoxService.getName()).andReturn("KNOX").anyTimes();
- EasyMock.expect(knoxService.getURLs()).andReturn(null).anyTimes();
- EasyMock.expect(knoxService.getParams()).andReturn(null).anyTimes();
- List<SimpleDescriptor.Service> serviceMocks = Collections.singletonList(knoxService);
- testDescriptor.setServices(serviceMocks);
- EasyMock.replay(gc, knoxService);
+ @Test
+ public void shouldAllowHealthServiceWithoutUrlsAndParams() throws Exception {
+ doTestShouldAllowServiceWithoutUrlsAndParams("HEALTH");
+ }
- final Map<String, File> handleResult = SimpleDescriptorHandler.handle(gc, testDescriptor, destDir, destDir);
- topologyFile = handleResult.get(SimpleDescriptorHandler.RESULT_TOPOLOGY);
- assertTrue(topologyFile.exists());
- assertTrue(new TopologyValidator(topologyFile.getAbsolutePath()).validateTopology());
+ @Test
+ public void shouldAllowMetadataServiceWithoutUrlsAndParams() throws Exception {
+ doTestShouldAllowServiceWithoutUrlsAndParams("KNOX-METADATA");
+ }
- final Document topologyXml = XmlUtils.readXml(topologyFile);
- assertThat(topologyXml, hasXPath("/topology/service/role", is(equalTo("KNOX"))));
- } finally {
- providerConfig.delete();
- if (topologyFile != null) {
- topologyFile.delete();
+ @Test
+ public void shouldAllowKnoxSessionServiceWithoutUrlsAndParams() throws Exception {
+ doTestShouldAllowServiceWithoutUrlsAndParams("KNOX-SESSION");
+ }
+
+ private void doTestShouldAllowServiceWithoutUrlsAndParams(final String serviceName) throws Exception {
+ File providerConfig = File.createTempFile("testKnoxProvider", ".xml");
+ FileUtils.write(providerConfig, TEST_PROVIDER_CONFIG, StandardCharsets.UTF_8);
+
+ File topologyFile = null;
+ try {
+ final File destDir = new File(System.getProperty("java.io.tmpdir")).getCanonicalFile();
+ final GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+ EasyMock.expect(gc.getReadOnlyOverrideTopologyNames()).andReturn(Collections.emptyList()).anyTimes();
+
+ final SimpleDescriptorImpl testDescriptor = new SimpleDescriptorImpl();
+ testDescriptor.setProviderConfig(providerConfig.getAbsolutePath());
+
+ final SimpleDescriptor.Service knoxService = EasyMock.createNiceMock(SimpleDescriptor.Service.class);
+ EasyMock.expect(knoxService.getName()).andReturn(serviceName).anyTimes();
+ EasyMock.expect(knoxService.getURLs()).andReturn(null).anyTimes();
+ EasyMock.expect(knoxService.getParams()).andReturn(null).anyTimes();
+ List<SimpleDescriptor.Service> serviceMocks = Collections.singletonList(knoxService);
+ testDescriptor.setServices(serviceMocks);
+ EasyMock.replay(gc, knoxService);
+
+ final Map<String, File> handleResult = SimpleDescriptorHandler.handle(gc, testDescriptor, destDir, destDir);
+ topologyFile = handleResult.get(SimpleDescriptorHandler.RESULT_TOPOLOGY);
+ assertTrue(topologyFile.exists());
+ assertTrue(new TopologyValidator(topologyFile.getAbsolutePath()).validateTopology());
+
+ final Document topologyXml = XmlUtils.readXml(topologyFile);
+ assertThat(topologyXml, hasXPath("/topology/service/role", is(equalTo(serviceName))));
+ } finally {
+ providerConfig.delete();
+ if (topologyFile != null) {
+ topologyFile.delete();
+ }
}
- }
}
@Test
diff --git a/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java b/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
index b3a735e7a..b4fbe0182 100644
--- a/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
+++ b/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
@@ -90,7 +90,14 @@ public class SimpleDescriptorHandler {
private static final Map<String, ServiceDiscovery> discoveryInstances = new HashMap<>();
- private static final Set<String> ALLOWED_SERVICES_WITHOUT_URLS_AND_PARAMS = Collections.unmodifiableSet(Stream.of("KNOX", "KNOX-METADATA", "KNOXSSOUT", "KNOX-SESSION", "HEALTH").collect(Collectors.toSet()));
+ private static final Set<String> ALLOWED_SERVICES_WITHOUT_URLS_AND_PARAMS =
+ Collections.unmodifiableSet(Stream.of("KNOX",
+ "KNOX-METADATA",
+ "KNOXSSOUT",
+ "KNOX-SESSION",
+ "APIKEY",
+ "CLIENTID",
+ "HEALTH").collect(Collectors.toSet()));
public static Map<String, File> handle(GatewayConfig config, File desc, File destDirectory, Service...gatewayServices) throws IOException {
return handle(config, SimpleDescriptorFactory.parse(desc.getAbsolutePath()), desc.getParentFile(), destDirectory, gatewayServices);