-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from groldan/flyway/modularity_upgrade
Add dependency on flyway-database-postgresql after flyway 10.x upgrade
- Loading branch information
Showing
10 changed files
with
248 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
...acts/api/src/test/java/org/geoserver/acl/app/AbstractAccesControlListApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* (c) 2023 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.acl.app; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.geoserver.acl.api.model.GrantType; | ||
import org.geoserver.acl.api.model.Rule; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpMethod; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
|
||
import java.util.List; | ||
|
||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
abstract class AbstractAccesControlListApplicationTest { | ||
|
||
protected final String adminUsername = "admin"; | ||
protected final String adminUserPassword = "s3cr3t"; | ||
|
||
protected final String testUsername = "testuser"; | ||
protected final String testUserPassword = "changeme"; | ||
|
||
@DynamicPropertySource | ||
static void registerTestUser(DynamicPropertyRegistry registry) { | ||
// define a non-admin test user | ||
registry.add("geoserver.acl.security.internal.users.testuser.enabled", () -> "true"); | ||
registry.add("geoserver.acl.security.internal.users.testuser.admin", () -> "false"); | ||
registry.add("geoserver.acl.security.internal.users.testuser.password", () -> "changeme"); | ||
} | ||
|
||
@Autowired TestRestTemplate baseClient; | ||
|
||
// client to be used, may have login credentials | ||
TestRestTemplate client; | ||
|
||
@BeforeEach | ||
void setup() { | ||
client = baseClient; | ||
} | ||
|
||
@Test | ||
void getRulesUnauthorizedIfNotLoggedIn() { | ||
var response = get("/api/rules", String.class); | ||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); | ||
} | ||
|
||
@Test | ||
void getRulesLoggedInAsNonAdminUser() { | ||
loginAsUser(); | ||
var response = get("/api/rules", String.class); | ||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); | ||
} | ||
|
||
@Test | ||
void createAllowRule() { | ||
loginAsAdmin(); | ||
var response = | ||
createRule( | ||
""" | ||
{ | ||
"priority": 0, | ||
"access": "ALLOW" | ||
} | ||
"""); | ||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED); | ||
assertThat(response.getBody().getPriority()).isPositive(); | ||
assertThat(response.getBody().getAccess()).isEqualTo(GrantType.ALLOW); | ||
} | ||
|
||
@Test | ||
void createDenyRule() { | ||
loginAsAdmin(); | ||
var response = | ||
createRule( | ||
""" | ||
{ | ||
"priority": 0, | ||
"access": "DENY" | ||
} | ||
"""); | ||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.CREATED); | ||
assertThat(response.getBody().getPriority()).isPositive(); | ||
assertThat(response.getBody().getAccess()).isEqualTo(GrantType.DENY); | ||
} | ||
|
||
protected void loginAsAdmin() { | ||
login(adminUsername, adminUserPassword); | ||
} | ||
|
||
protected void loginAsUser() { | ||
login(testUsername, testUserPassword); | ||
} | ||
|
||
protected void login(String user, String pwd) { | ||
client = client.withBasicAuth(user, pwd); | ||
} | ||
|
||
protected <T> ResponseEntity<T> get(String url, Class<T> responseType) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setAccept(List.of(MediaType.APPLICATION_JSON)); | ||
HttpEntity<String> entity = new HttpEntity<>(headers); | ||
|
||
return client.exchange(url, HttpMethod.GET, entity, responseType); | ||
} | ||
|
||
private ResponseEntity<Rule> createRule(String json) { | ||
return post("/api/rules", json, Rule.class); | ||
} | ||
|
||
protected <T> ResponseEntity<T> post( | ||
String url, String requestBodyJson, Class<T> responseType, Object... urlVariables) { | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
headers.setAccept(List.of(MediaType.APPLICATION_JSON)); | ||
HttpEntity<String> entity = new HttpEntity<>(requestBodyJson, headers); | ||
|
||
return client.postForEntity(url, entity, responseType, urlVariables); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/artifacts/api/src/test/java/org/geoserver/acl/app/AccesControlListApplicationIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* (c) 2023 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.acl.app; | ||
|
||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
@Testcontainers(disabledWithoutDocker = true) | ||
class AccesControlListApplicationIT extends AbstractAccesControlListApplicationTest { | ||
|
||
private static final DockerImageName POSTGIS_IMAGE_NAME = | ||
DockerImageName.parse("postgis/postgis").asCompatibleSubstituteFor("postgres"); | ||
|
||
@Container | ||
static PostgreSQLContainer<?> postgis = new PostgreSQLContainer<>(POSTGIS_IMAGE_NAME); | ||
|
||
/** Set up the properties defined in values.yml and used as place-holders in application.yml */ | ||
@DynamicPropertySource | ||
static void registerPostgresProperties(DynamicPropertyRegistry registry) { | ||
registry.add("pg.host", () -> postgis.getHost()); | ||
registry.add("pg.port", () -> postgis.getFirstMappedPort()); | ||
registry.add("pg.db", () -> postgis.getDatabaseName()); | ||
registry.add("pg.schema", () -> "acltest"); | ||
registry.add("pg.username", postgis::getUsername); | ||
registry.add("pg.password", postgis::getPassword); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/artifacts/api/src/test/java/org/geoserver/acl/app/AccesControlListApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* (c) 2023 Open Source Geospatial Foundation - all rights reserved | ||
* This code is licensed under the GPL 2.0 license, available at the root | ||
* application directory. | ||
*/ | ||
package org.geoserver.acl.app; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
@ActiveProfiles("dev") | ||
class AccesControlListApplicationTest extends AbstractAccesControlListApplicationTest { | ||
|
||
@BeforeEach | ||
void setUp() throws Exception {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.