Skip to content

Commit

Permalink
Defect env id null pointer (#1990)
Browse files Browse the repository at this point in the history
* Null check in case the environment is not returned correctly.

Signed-off-by: Aindriu Lavelle <aindriu.lavelle@aiven.io>

* Default to http so that those testing Klaw will not hit any immediate defects.

Signed-off-by: Aindriu Lavelle <aindriu.lavelle@aiven.io>

---------

Signed-off-by: Aindriu Lavelle <aindriu.lavelle@aiven.io>
  • Loading branch information
aindriu-aiven authored Nov 16, 2023
1 parent 8f620d3 commit e7655d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ private void removeAssociatedKafkaOrSchemaEnvironment(String envId, int tenantId
if (KafkaClustersType.KAFKA.value.equals(envType)
|| KafkaClustersType.SCHEMA_REGISTRY.value.equals(envType)) {
Env env = manageDatabase.getHandleDbRequests().getEnvDetails(envId, tenantId);
if (env.getAssociatedEnv() != null) {
if (env != null && env.getAssociatedEnv() != null) {
Env linkedEnv =
manageDatabase
.getHandleDbRequests()
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ klaw.saas.ssl.clusterapi.truststore.pwd=klaw
klaw.saas.plaintext.aclcommand=kafka-acls --authorizer-properties bootstrap.server=host:port --add --allow-principal User:'*' --operation All --allow-host hostname_ip --cluster Cluster:kafka-cluster --topic "*"

# comma separated instances of klaw when running in cluster
klaw.uiapi.servers=https://localhost:9097
klaw.uiapi.servers=http://localhost:9097

# Enable new Klaw React based user interface
# Make sure node, pnpm are installed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,27 @@ void addEnvRemoveAssociatedEnv() throws KlawValidationException, KlawException {
verify(handleDbRequestsJdbc, times(2)).addNewEnv(any(Env.class));
}

@Test
@WithMockUser(
username = "james",
authorities = {"ADMIN", "USER"})
void addEnvRemoveAssociatedEnvIncorrectIdSupplied()
throws KlawValidationException, KlawException {
EnvModel env = getTestSchemaEnvModel(null);
Env env1 = generateKafkaEnv("1", "Kafka");
env1.setType(KafkaClustersType.SCHEMA_REGISTRY.value);
env1.setAssociatedEnv(new EnvTag("2", "TST_SCH"));
when(handleDbRequestsJdbc.getEnvDetails(eq("1"), eq(101))).thenReturn(null);
when(handleDbRequestsJdbc.addNewEnv(any())).thenReturn(ApiResultStatus.SUCCESS.value);
when(handleDbRequestsJdbc.getNextSeqIdAndUpdate(eq(EntityType.ENVIRONMENT.name()), eq(101)))
.thenReturn(1);
ApiResponse response = service.addNewEnv(env);

assertThat(response.getMessage()).contains("success");
// 1 time for the env we are saving and 1 time for removing an existing mapping of a kafka env.
verify(handleDbRequestsJdbc, times(1)).addNewEnv(any(Env.class));
}

@ParameterizedTest(name = "actual={0} / search={1} / pageNo={2} / expectedNumberOfMatches={4}")
@MethodSource
@WithMockUser(
Expand Down

0 comments on commit e7655d6

Please sign in to comment.