This is an automated email from the ASF dual-hosted git repository.

tenthe pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/streampipes.git


The following commit(s) were added to refs/heads/dev by this push:
     new 09c0ef60f8 test: Update prometheus endpoint test (#4537)
09c0ef60f8 is described below

commit 09c0ef60f8fe5a91e7d355e0b10a45bb1c8f4a8c
Author: Philipp Zehnder <[email protected]>
AuthorDate: Tue Jun 16 07:46:15 2026 +0200

    test: Update prometheus endpoint test (#4537)
---
 .devcontainer/docker-compose.yml                   |  1 +
 docker-compose.yml                                 |  1 +
 .../apache/streampipes/commons/constants/Envs.java |  1 +
 .../commons/environment/DefaultEnvironment.java    |  5 +++
 .../commons/environment/Environment.java           |  2 +
 .../rest/impl/ResetEndpointEnabledCondition.java   | 34 +++++++++++++++
 .../streampipes/rest/impl/ResetResource.java       |  5 +++
 .../tests/monitoring/prometheusEndpoint.spec.ts    |  4 +-
 .../resetResourceAuthorization.spec.ts             | 51 ++++++++++++++++++++++
 9 files changed, 103 insertions(+), 1 deletion(-)

diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml
index b5ef0d57f2..ddb11f0560 100644
--- a/.devcontainer/docker-compose.yml
+++ b/.devcontainer/docker-compose.yml
@@ -46,6 +46,7 @@ services:
       SP_CORE_EXTENSION_TRANSPORT_MODE: nats
       SP_EXTENSION_TRANSPORT_MODE: nats
       SP_EXTENSION_REQUEST_TOPIC_PREFIX: sp.extensions.request
+      SP_RESET_ENDPOINT_ENABLED: "true"
       # Keep StreamPipes debug mode disabled in the devcontainer. When enabled,
       # StreamPipes rewrites broker hostnames to localhost, but NATS runs as 
the
       # sibling Compose service "nats" and must be reached via nats:4222.
diff --git a/docker-compose.yml b/docker-compose.yml
index a9b74eaac1..89e628eb9d 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -37,6 +37,7 @@ services:
     environment:
       - SP_PRIORITIZED_PROTOCOL=nats
       - SP_SETUP_PROMETHEUS_ENDPOINT=true
+      - SP_RESET_ENDPOINT_ENABLED=true
     depends_on:
       - couchdb
     volumes:
diff --git 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/Envs.java
 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/Envs.java
index c608e4d486..3cb48ac964 100644
--- 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/Envs.java
+++ 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/constants/Envs.java
@@ -47,6 +47,7 @@ public enum Envs {
   SP_ENCRYPTION_PASSCODE("SP_ENCRYPTION_PASSCODE", 
DefaultEnvValues.DEFAULT_ENCRYPTION_PASSCODE),
   SP_OAUTH_ENABLED("SP_OAUTH_ENABLED", "false"),
   SP_OAUTH_REDIRECT_URI("SP_OAUTH_REDIRECT_URI"),
+  SP_RESET_ENDPOINT_ENABLED("SP_RESET_ENDPOINT_ENABLED", "false"),
   SP_DEBUG("SP_DEBUG", "false"),
   SP_MAX_WAIT_TIME_AT_SHUTDOWN("SP_MAX_WAIT_TIME_AT_SHUTDOWN"),
 
diff --git 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/DefaultEnvironment.java
 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/DefaultEnvironment.java
index edcd692de4..e0e00d694c 100644
--- 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/DefaultEnvironment.java
+++ 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/DefaultEnvironment.java
@@ -192,6 +192,11 @@ public class DefaultEnvironment implements Environment {
     return new StringEnvironmentVariable(Envs.SP_OAUTH_REDIRECT_URI);
   }
 
+  @Override
+  public BooleanEnvironmentVariable getResetEndpointEnabled() {
+    return new BooleanEnvironmentVariable(Envs.SP_RESET_ENDPOINT_ENABLED);
+  }
+
   @Override
   public List<OAuthConfiguration> getOAuthConfigurations() {
     return new OAuthConfigurationParser().parse(System.getenv());
diff --git 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/Environment.java
 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/Environment.java
index 56a7d98c4d..c1d50e3057 100644
--- 
a/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/Environment.java
+++ 
b/streampipes-commons/src/main/java/org/apache/streampipes/commons/environment/Environment.java
@@ -102,6 +102,8 @@ public interface Environment {
 
   StringEnvironmentVariable getOAuthRedirectUri();
 
+  BooleanEnvironmentVariable getResetEndpointEnabled();
+
   List<OAuthConfiguration> getOAuthConfigurations();
 
   // Messaging
diff --git 
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/ResetEndpointEnabledCondition.java
 
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/ResetEndpointEnabledCondition.java
new file mode 100644
index 0000000000..81a007c103
--- /dev/null
+++ 
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/ResetEndpointEnabledCondition.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.rest.impl;
+
+import org.apache.streampipes.commons.environment.Environments;
+
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+public class ResetEndpointEnabledCondition implements Condition {
+
+  @Override
+  public boolean matches(ConditionContext context,
+                         AnnotatedTypeMetadata metadata) {
+    return 
Environments.getEnvironment().getResetEndpointEnabled().getValueOrDefault();
+  }
+}
diff --git 
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/ResetResource.java
 
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/ResetResource.java
index eae52cbaf0..26e8431326 100644
--- 
a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/ResetResource.java
+++ 
b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/ResetResource.java
@@ -26,12 +26,15 @@ import org.apache.streampipes.model.message.Notifications;
 import org.apache.streampipes.model.message.SuccessMessage;
 import org.apache.streampipes.rest.ResetManagement;
 import 
org.apache.streampipes.rest.core.base.impl.AbstractAuthGuardedRestResource;
+import org.apache.streampipes.rest.security.AuthConstants;
 import org.apache.streampipes.storage.api.system.IExtensionsServiceStorage;
 import org.apache.streampipes.storage.management.StorageDispatcher;
 
 import io.swagger.v3.oas.annotations.Operation;
+import org.springframework.context.annotation.Conditional;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -40,6 +43,8 @@ import java.util.ArrayList;
 
 @RestController
 @RequestMapping("/api/v2/reset")
+@Conditional(ResetEndpointEnabledCondition.class)
+@PreAuthorize(AuthConstants.IS_ADMIN_ROLE)
 public class ResetResource extends AbstractAuthGuardedRestResource {
 
   private final WorkerRestClient workerRestClient;
diff --git a/ui/cypress/tests/monitoring/prometheusEndpoint.spec.ts 
b/ui/cypress/tests/monitoring/prometheusEndpoint.spec.ts
index 2df2ae84d9..846aeb1204 100644
--- a/ui/cypress/tests/monitoring/prometheusEndpoint.spec.ts
+++ b/ui/cypress/tests/monitoring/prometheusEndpoint.spec.ts
@@ -40,7 +40,9 @@ describe('Prometheus actuator endpoint', () => {
                 auth,
             }).then(response => {
                 expect(response.status).to.eq(200);
-                expect(response.body).to.contain('# HELP');
+                expect(response.body).to.contain(
+                    'sp_core_pipeline_count_total',
+                );
                 expect(response.body).to.not.contain('No static resource');
             });
         });
diff --git a/ui/cypress/tests/userManagement/resetResourceAuthorization.spec.ts 
b/ui/cypress/tests/userManagement/resetResourceAuthorization.spec.ts
new file mode 100644
index 0000000000..c3e5c409bd
--- /dev/null
+++ b/ui/cypress/tests/userManagement/resetResourceAuthorization.spec.ts
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+import { UserBuilder } from '../../support/builder/UserBuilder';
+import { UserRole } from '../../../src/app/core/auth/user-role.enum';
+import { UserUtils } from '../../support/utils/UserUtils';
+
+describe('Reset resource authorization', () => {
+    beforeEach('Setup Test', () => {
+        cy.initStreamPipesTest();
+    });
+
+    it('does not allow non-admin users to reset the system', () => {
+        const user = UserBuilder.create('[email protected]')
+            .setName('non-admin')
+            .setPassword('non-admin')
+            .addRole(UserRole.ROLE_PIPELINE_USER)
+            .build();
+
+        UserUtils.addUser(user);
+        UserUtils.switchUser(user);
+
+        cy.window().then(win => {
+            cy.request({
+                method: 'POST',
+                url: '/streampipes-backend/api/v2/reset',
+                auth: {
+                    bearer: win.localStorage.getItem('auth-token'),
+                },
+                failOnStatusCode: false,
+            }).then(response => {
+                expect(response.status).to.eq(403);
+            });
+        });
+    });
+});

Reply via email to