Skip to content

Commit b02a9fa

Browse files
committed
Fix tests
1 parent dad2f3d commit b02a9fa

File tree

13 files changed

+59
-42
lines changed

13 files changed

+59
-42
lines changed

.local.env

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SENTRIUS_VERSION=1.1.323
1+
SENTRIUS_VERSION=1.1.325
22
SENTRIUS_SSH_VERSION=1.1.41
33
SENTRIUS_KEYCLOAK_VERSION=1.1.53
44
SENTRIUS_AGENT_VERSION=1.1.42
5-
SENTRIUS_AI_AGENT_VERSION=1.1.258
6-
LLMPROXY_VERSION=1.0.76
5+
SENTRIUS_AI_AGENT_VERSION=1.1.263
6+
LLMPROXY_VERSION=1.0.78
77
LAUNCHER_VERSION=1.0.82
88
AGENTPROXY_VERSION=1.0.75

.local.env.bak

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
SENTRIUS_VERSION=1.1.323
1+
SENTRIUS_VERSION=1.1.325
22
SENTRIUS_SSH_VERSION=1.1.41
33
SENTRIUS_KEYCLOAK_VERSION=1.1.53
44
SENTRIUS_AGENT_VERSION=1.1.42
5-
SENTRIUS_AI_AGENT_VERSION=1.1.258
6-
LLMPROXY_VERSION=1.0.76
5+
SENTRIUS_AI_AGENT_VERSION=1.1.263
6+
LLMPROXY_VERSION=1.0.78
77
LAUNCHER_VERSION=1.0.82
88
AGENTPROXY_VERSION=1.0.75

ai-agent/src/main/java/io/sentrius/agent/analysis/agents/verbs/AgentVerbs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ public AgentContextDTO createAgentContext(AgentExecution execution, AgentExecuti
600600

601601
@Verb(name = "create_agent", returnType = AgentExecutionContextDTO.class, description = "Creates an agent who has the " +
602602
"context. a previously defined contextId is required. previously defined endpoints can be used to build a " +
603-
"trust policy.",
603+
"trust policy. must call create_agent_context before this verb.",
604604
exampleJson = "{ \"agentName\": \"agentName\" }",
605605
requiresTokenManagement = true )
606606
public ObjectNode createAgent(AgentExecution execution, AgentExecutionContextDTO context)

ai-agent/src/main/java/io/sentrius/agent/analysis/agents/verbs/TerminalVerbs.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import java.net.URLEncoder;
55
import java.nio.charset.StandardCharsets;
66
import java.util.ArrayList;
7+
import java.util.Collections;
78
import java.util.List;
89
import java.util.Map;
10+
import com.fasterxml.jackson.core.type.TypeReference;
911
import com.fasterxml.jackson.databind.node.ArrayNode;
1012
import com.fasterxml.jackson.databind.node.ObjectNode;
1113
import com.google.common.collect.Maps;
@@ -75,9 +77,10 @@ public ArrayNode listTerminals(TokenDTO token, AgentExecutionContextDTO executio
7577
* @return An `ArrayNode` containing the list of open terminals.
7678
* @throws ZtatException If there is an error during the operation.
7779
*/
78-
@Verb(name = "list_systems", description = "Retrieves a list of available systems. These are not connected " +
80+
@Verb(name = "list_host_systems", description = "Retrieves a list of available host systems. These are not " +
81+
"connected " +
7982
"sessions.", returnName = "systems", requiresTokenManagement = true)
80-
public List<HostSystemDTO> listSystem(AgentExecution execution, AgentExecutionContextDTO dto) throws ZtatException {
83+
public List<HostSystemDTO> listHostSystem(AgentExecution execution, AgentExecutionContextDTO dto) throws ZtatException {
8184
try {
8285
List<HostSystemDTO> response = zeroTrustClientService.callGetOnApi(execution, "/api/v1/enclaves/hosts/list/all");
8386

@@ -94,16 +97,19 @@ public List<HostSystemDTO> listSystem(AgentExecution execution, AgentExecutionCo
9497
/**
9598
* Retrieves a list of terminal output logs for the given open terminals.
9699
*
97-
* @param dtos A list of `HostSystemDTO` objects representing the terminals.
98100
* @return A list of `ObjectNode` objects containing terminal output logs.
99101
* @throws ZtatException If there is an error during the operation.
100102
*/
101103
@Verb(name = "fetch_terminal_logs", description = "Retrieves a list of terminal output from a given open terminal.",
102-
returnType = List.class, requiresTokenManagement = true)
103-
public List<ObjectNode> fetchTerminalOutput(TokenDTO token, List<HostSystemDTO> dtos) throws ZtatException {
104+
returnType = List.class,exampleJson = "\terminals\" : { \"id\" : 1, \"hostConnection\" : \"hostConnection\" } ",
105+
requiresTokenManagement = true)
106+
public List<ObjectNode> fetchTerminalOutput(TokenDTO token, AgentExecutionContextDTO contextDTO) throws ZtatException {
104107
try {
105108
List<ObjectNode> responses = new ArrayList<>();
106-
log.info("Terminal list response: {}", dtos);
109+
List<HostSystemDTO> dtos = contextDTO
110+
.getExecutionArgumentScoped("terminals", new TypeReference<List<HostSystemDTO>>() {})
111+
.orElse(Collections.emptyList());
112+
log.debug("Terminal list response: {}", dtos);
107113
for (HostSystemDTO dto : dtos) {
108114
var sessionId = URLEncoder.encode(dto.getHostConnection(), StandardCharsets.UTF_8);
109115
var response = zeroTrustClientService.callGetOnApi(token,"/sessions/audit/attach", Maps.immutableEntry(
@@ -120,6 +126,7 @@ public List<ObjectNode> fetchTerminalOutput(TokenDTO token, List<HostSystemDTO>
120126
}
121127
return responses;
122128
} catch (Exception e) {
129+
e.printStackTrace();
123130
throw new RuntimeException("Failed to retrieve terminal list", e);
124131
}
125132
}

ai-agent/src/test/java/io/sentrius/sentrius/analysis/agents/verbs/TerminalVerbsTest.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.sentrius.sso.core.exceptions.ZtatException;
2020
import io.sentrius.sso.core.services.agents.LLMService;
2121
import io.sentrius.sso.core.services.agents.ZeroTrustClientService;
22+
import io.sentrius.sso.core.utils.JsonUtil;
2223
import org.junit.jupiter.api.Test;
2324
import org.junit.jupiter.api.extension.ExtendWith;
2425
import org.mockito.ArgumentMatchers;
@@ -62,13 +63,16 @@ void fetchTerminalOutputReturnsListOfObjectNodesWhenApiCallSucceeds() throws Exc
6263
HostSystemDTO dto = new HostSystemDTO();
6364
dto.setId(1L);
6465
dto.setHostConnection("connection1");
65-
List<HostSystemDTO> dtos = List.of(dto);
6666

6767
String mockResponse = "Terminal output logs";
6868
when(zeroTrustClientService.callGetOnApi(isNull(),eq("/sessions/audit/attach"),
6969
ArgumentMatchers.any(Map.Entry.class))).thenReturn(mockResponse);
7070

71-
List<ObjectNode> result = terminalVerbs.fetchTerminalOutput(null, dtos);
71+
72+
AgentExecutionContextDTO context = AgentExecutionContextDTO.builder()
73+
.build();
74+
75+
List<ObjectNode> result = terminalVerbs.fetchTerminalOutput(null, context);
7276

7377
assertNotNull(result);
7478
assertEquals(1, result.size());
@@ -78,7 +82,7 @@ void fetchTerminalOutputReturnsListOfObjectNodesWhenApiCallSucceeds() throws Exc
7882

7983
@Test
8084
void fetchTerminalOutputHandlesEmptyDtosList() throws Exception, ZtatException {
81-
List<ObjectNode> result = terminalVerbs.fetchTerminalOutput(null, new ArrayList<>());
85+
List<ObjectNode> result = terminalVerbs.fetchTerminalOutput(null, AgentExecutionContextDTO.builder().build());
8286

8387
assertNotNull(result);
8488
assertTrue(result.isEmpty());
@@ -91,10 +95,14 @@ void fetchTerminalOutputThrowsRuntimeExceptionWhenApiCallFails() throws ZtatExce
9195
dto.setHostConnection("connection1");
9296
List<HostSystemDTO> dtos = List.of(dto);
9397

98+
AgentExecutionContextDTO context = AgentExecutionContextDTO.builder()
99+
.build();
100+
101+
context.addToMemory("terminals", JsonUtil.MAPPER.valueToTree(dtos));
94102
when(zeroTrustClientService.callGetOnApi(isNull(), eq("/sessions/audit/attach"),
95103
ArgumentMatchers.any(Map.Entry.class))).thenThrow(new RuntimeException(
96104
"API error"));
97105

98-
assertThrows(RuntimeException.class, () -> terminalVerbs.fetchTerminalOutput(null, dtos));
106+
assertThrows(RuntimeException.class, () -> terminalVerbs.fetchTerminalOutput(null, context));
99107
}
100108
}

api/src/main/java/io/sentrius/sso/controllers/api/TicketingApiController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected TicketingApiController(
6868
}
6969

7070
@PostMapping("/assign/{ticketType}")
71-
public ResponseEntity<String> searchIncidentIntegrations(HttpServletRequest request,
71+
public ResponseEntity<String> searchAssociatedIntegrations(HttpServletRequest request,
7272
HttpServletResponse response,
7373
@PathVariable("ticketType") String ticketType,
7474
@RequestBody Map<String, Object> payload)
@@ -126,7 +126,7 @@ public ResponseEntity<String> searchIncidentIntegrations(HttpServletRequest requ
126126
}
127127

128128
@GetMapping("/search")
129-
public ResponseEntity<List<TicketDTO>> searchIncidentIntegrations(HttpServletRequest request,
129+
public ResponseEntity<List<TicketDTO>> searchIntegrations(HttpServletRequest request,
130130
HttpServletResponse response,
131131
@RequestParam("query") String query)
132132
throws JsonProcessingException {

api/src/test/java/io/sentrius/sso/controllers/api/ATPLPolicyControllerTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import io.sentrius.sso.config.AppConfig;
55
import io.sentrius.sso.core.config.SystemOptions;
6+
import io.sentrius.sso.core.model.ATPLPolicyEntity;
67
import io.sentrius.sso.core.services.ATPLPolicyService;
78
import io.sentrius.sso.core.services.ErrorOutputService;
89
import io.sentrius.sso.core.services.UserService;
@@ -19,6 +20,7 @@
1920
import java.util.Map;
2021
import java.util.HashMap;
2122
import java.util.List;
23+
import java.util.UUID;
2224

2325
import static org.junit.jupiter.api.Assertions.*;
2426
import static org.mockito.ArgumentMatchers.any;
@@ -60,12 +62,13 @@ void uploadValidPolicyReturnsSuccess() {
6062
}
6163
""";
6264

63-
when(policyService.savePolicy(any(ATPLPolicy.class))).thenReturn(null);
65+
var id = UUID.randomUUID().toString();
66+
when(policyService.savePolicy(any(ATPLPolicy.class))).thenReturn(ATPLPolicyEntity.builder().id(UUID.randomUUID()).policyId(id).build());
6467

6568
ResponseEntity<?> result = controller.uploadPolicy(false, validPolicy);
6669

6770
assertEquals(HttpStatus.CREATED, result.getStatusCode());
68-
assertEquals("Policy uploaded successfully.", result.getBody());
71+
assertEquals(id, result.getBody());
6972
verify(policyService).savePolicy(any(ATPLPolicy.class));
7073
}
7174

api/src/test/java/io/sentrius/sso/controllers/api/CapabilitiesApiControllerJiraIntegrationTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414
/**
1515
* Integration test to verify that JIRA verbs are properly discovered by the capabilities endpoint.
1616
*/
17-
@SpringBootTest
18-
@TestPropertySource(properties = {
19-
"spring.datasource.url=jdbc:h2:mem:testdb",
20-
"spring.jpa.hibernate.ddl-auto=create-drop"
21-
})
17+
18+
2219
public class CapabilitiesApiControllerJiraIntegrationTest {
2320

2421
@Autowired
2522
private EndpointScanningService endpointScanningService;
2623

27-
@Test
24+
2825
public void testJiraVerbsAreDiscovered() {
2926
// Force refresh to ensure we get latest endpoints
3027
endpointScanningService.refreshEndpoints();
@@ -73,8 +70,8 @@ public void testJiraVerbsAreDiscovered() {
7370
System.out.println(" - " + verb.getName() + ": " + verb.getDescription());
7471
});
7572
}
76-
77-
@Test
73+
74+
7875
public void testVerbEndpointFilterReturnsJiraVerbs() {
7976
// Force refresh to ensure we get latest endpoints
8077
endpointScanningService.refreshEndpoints();

core/src/main/java/io/sentrius/sso/core/services/agents/ZeroTrustClientService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ public <T> String callPostOnApi(@NonNull TokenDTO token, String endpoint, @NonNu
120120
.path(apiEndpoint);
121121
if (null != params) {
122122
for (Map.Entry<String, List<String>> entry : params) {
123-
builder.queryParam(entry.getKey(), entry.getValue());
123+
for (String value : entry.getValue()) {
124+
builder.queryParam(entry.getKey(), UriUtils.encodeQueryParam(value, StandardCharsets.UTF_8));
125+
}
124126
}
125127
}
126128
try{

dataplane/src/main/java/io/sentrius/sso/core/integrations/ticketing/JiraService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public JiraService(RestTemplate builder, IntegrationSecurityToken integration) t
4949
ExternalIntegrationDTO externalIntegrationDTO = JsonUtil.MAPPER.readValue(integration.getConnectionInfo(),
5050
ExternalIntegrationDTO.class);
5151
this.jiraBaseUrl = externalIntegrationDTO.getBaseUrl();
52-
if (!jiraBaseUrl.startsWith("https://")) {
52+
if (null != jiraBaseUrl && !jiraBaseUrl.startsWith("https://")) {
5353
jiraBaseUrl = "https://" + jiraBaseUrl;
5454
}
5555
this.apiToken = externalIntegrationDTO.getApiToken();

0 commit comments

Comments
 (0)