Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
- **Tests**: `UserResourceTest.createUser` checks that GET after delete returns 404. `UserResourceIntegrationTest` no longer repeats that create and delete on a real server ([#313](https://github.com/sitmun/sitmun-backend-core/issues/313)).
- **Tests**: `ServiceCheckStoreTest`, `AffectedApplicationsTest`, `ServiceHealthFilterTest`, `ServiceAccessSummaryTest`, and `ServiceCheckDispatcherTest` load `ServiceCheckSliceConfiguration` on the suite database, so Liquibase runs once for that slice. Connections do not autocommit, so the transactional slice removes its rows ([#317](https://github.com/sitmun/sitmun-backend-core/issues/317)).
- **Tests**: `AuthenticationControllerLdapEnabledTest` starts the in-memory LDAP directory once for the class. The role-lookup case still returns HTTP 401 and no cookie only when `LdapUserAuthoritiesPopulator` rejects the user ([#319](https://github.com/sitmun/sitmun-backend-core/issues/319)).
- **Tests**: A JDBC URL `jdbc:h2:mem:testdb;MODE=NOT_A_MODE` is rejected with an SQLException that names the unknown mode. `POST /api/connections/test` returns HTTP 400 for that URL. `GET /api/connections/{id}/test` no longer repeats the same rejection ([#314](https://github.com/sitmun/sitmun-backend-core/issues/314)).
- **Tests**: Database connection, role, territory, territory group type, and user repository tests use MockMvc on the shared context. They no longer boot an embedded server ([#316](https://github.com/sitmun/sitmun-backend-core/issues/316)).

### Security
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.sitmun.administration.controller;

import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
Expand Down Expand Up @@ -32,24 +33,6 @@ void failIfDatabaseConnectionDriverNotFound() throws Exception {
.andExpect(jsonPath("$.message").value("java.lang.ClassNotFoundException: org.h2.DriverX"));
}

@Test
@WithMockUser(roles = "ADMIN")
@DisplayName("GET returns 400 when the JDBC URL has no driver")
void failIfDatabaseConnectionException() throws Exception {
when(repository.findById(0))
.thenReturn(
Optional.of(
DatabaseConnection.builder()
.driver("org.h2.Driver")
.url("jdb:h2:mem:testdb")
.name("sa")
.password("password")
.build()));
mvc.perform(get("/api/connections/0/test"))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.message").value("No suitable driver found for jdb:h2:mem:testdb"));
}

@Test
@WithMockUser(roles = "ADMIN")
@DisplayName("GET returns valid true")
Expand Down Expand Up @@ -106,15 +89,15 @@ void failPostTestIfDatabaseConnectionDriverNotFound() throws Exception {

@Test
@WithMockUser(roles = "ADMIN")
@DisplayName("POST returns 400 when the JDBC URL has no driver")
@DisplayName("POST returns 400 when the JDBC URL is malformed")
void failPostTestIfDatabaseConnectionException() throws Exception {
mvc.perform(
post("/api/connections/test")
.contentType(MediaType.APPLICATION_JSON)
.content(
"{ \"driver\" : \"org.h2.Driver\", \"url\" : \"jdb:h2:mem:testdb\", \"user\" : \"sa\", \"password\" : null }"))
"{ \"driver\" : \"org.h2.Driver\", \"url\" : \"jdbc:h2:mem:testdb;MODE=NOT_A_MODE\", \"user\" : \"sa\", \"password\" : null }"))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.message").value("No suitable driver found for jdb:h2:mem:testdb"));
.andExpect(jsonPath("$.message", containsString("Unknown mode \"NOT_A_MODE\"")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ void malformedJdbcUrlThrowsSqlException() {
DatabaseConnection connection =
DatabaseConnection.builder()
.driver("org.h2.Driver")
.url("jdb:h2:mem:testdb")
.url("jdbc:h2:mem:testdb;MODE=NOT_A_MODE")
.user("sa")
.password(null)
.build();
sut.testDriver(connection);
assertThrows(SQLException.class, () -> sut.testConnection(connection));
SQLException exception = assertThrows(SQLException.class, () -> sut.testConnection(connection));
assertTrue(exception.getMessage().contains("Unknown mode \"NOT_A_MODE\""));
}
}
Loading