Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Test to verify GatewayServiceResource realm boundary security issue

Rich Turnerb8a4789deb5f
diff --git a/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy b/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
index 092ae25a9..30332ed21 100644
--- a/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
@@ -1529,6 +1529,40 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
}
}
+ def "Verify GatewayResource realm boundary checks"() {
+ given: "some polling conditions and services from the container"
+ def gatewayService = container.getService(GatewayService.class)
+ def managerTestSetup = container.getService(SetupService.class).getTaskOfType(ManagerTestSetup.class)
+
+ and: "an authenticated user in the building realm"
+ def accessToken = authenticate(
+ container,
+ managerTestSetup.realmBuildingName,
+ KEYCLOAK_CLIENT_ID,
+ "testuser2",
+ "testuser2"
+ )
+
+ and: "the gateway service resource"
+ def gatewayResource = getClientApiTarget(serverUri(serverPort), managerTestSetup.realmBuildingName, accessToken).proxy(GatewayServiceResource.class)
+
+ when: "a fake tunnel for a fake gateway ID in the smart city realm is injected into the gateway service"
+ [email protected]("fake-tunnel-id",
+ new GatewayTunnelInfo(managerTestSetup.realmCityName, "fake-gateway-id", GatewayTunnelInfo.Type.HTTPS, "127.0.0.1", 443)
+ )
+
+ and: "the building user then retrieves the list of tunnels for the fake gateway ID"
+ def activeTunnels = gatewayResource.getGatewayActiveTunnelInfos(null, managerTestSetup.realmBuildingName, "fake-gateway-id")
+
+ then: "the smart city user should not be able to see any tunnels for the fake gateway ID in the building realm"
+ assert activeTunnels.length == 0
+
+ cleanup: "the fake tunnel is removed"
+ if (gatewayService != null) {
+ [email protected]("fake-tunnel-id")
+ }
+ }
+
/**
* This test requires a manager instance with tunnelling configured, so is manual for now unfortunately.
* Change the test url and key path to match the instance to connect to.