Init unit tests
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
parent
bf6f91520f
commit
2ff99d29bc
15
pom.xml
15
pom.xml
@ -100,7 +100,13 @@
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
</dependency>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -124,6 +130,13 @@
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.c4-soft.springaddons</groupId>
|
||||
<artifactId>spring-addons-keycloak</artifactId>
|
||||
<version>4.1.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -0,0 +1,81 @@
|
||||
package net.libertacasa.pubsh.web;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.forwardedUrl;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
|
||||
import com.c4_soft.springaddons.security.oauth2.test.annotations.Claims;
|
||||
import com.c4_soft.springaddons.security.oauth2.test.annotations.OpenIdClaims;
|
||||
import com.c4_soft.springaddons.security.oauth2.test.annotations.StringClaim;
|
||||
import com.c4_soft.springaddons.security.oauth2.test.annotations.keycloak.WithMockKeycloakAuth;
|
||||
|
||||
//@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
class WebApplicationTest {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private MockMvc mvc;
|
||||
|
||||
@Test
|
||||
public void getRoot() throws Exception {
|
||||
mvc.perform(MockMvcRequestBuilders.get("/"))
|
||||
.andExpect(status().isFound())
|
||||
.andExpect(redirectedUrl("/portal"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPortalNoAuth() throws Exception {
|
||||
mvc.perform(MockMvcRequestBuilders.get("/portal"))
|
||||
.andExpect(status().isFound())
|
||||
.andExpect(redirectedUrl("/sso/login"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAdminNoAuth() throws Exception {
|
||||
mvc.perform(MockMvcRequestBuilders.get("/admin"))
|
||||
.andExpect(status().isFound())
|
||||
.andExpect(redirectedUrl("/sso/login"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithMockKeycloakAuth("TotallyLegitUserWithZeroAdministrativePermissions")
|
||||
public void getAdminWrongAuth() throws Exception {
|
||||
mvc.perform(MockMvcRequestBuilders.get("/admin"))
|
||||
.andExpect(status().isForbidden());
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithMockKeycloakAuth(
|
||||
authorities = { "devel-user" },
|
||||
claims = @OpenIdClaims(
|
||||
sub = "12345",
|
||||
email = "regular-user@example.com",
|
||||
emailVerified = true,
|
||||
//nickName = "TotallyLegitUserWithSuperPowers",
|
||||
//preferredUsername = "TotallyLegitUserWithSuperPowers",
|
||||
otherClaims = @Claims(stringClaims = @StringClaim(name = "username", value = "regular-user"))))
|
||||
public void getPortalWithAuth() throws Exception {
|
||||
mvc.perform(MockMvcRequestBuilders.get("/portal"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(startsWith("<!DOCTYPE html>")))
|
||||
.andExpect(content().string(containsString("Hello, <span>regular-user</span>.")))
|
||||
.andExpect(content().string(containsString("Generate new throw-away shell:")));
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package net.libertacasa.pubsh.web;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class WebApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
11
src/test/resources/application.properties
Normal file
11
src/test/resources/application.properties
Normal file
@ -0,0 +1,11 @@
|
||||
spring.datasource.driver-class-name=org.h2.Driver
|
||||
spring.datasource.jdbc-url=jdbc:h2:mem:pubshweb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
|
||||
spring.jpa.show-sql=true
|
||||
spring.jpa.generate-ddl=true
|
||||
# This is a bogus endpoint, the results are mocked, but the Keycloak library does not know that:
|
||||
keycloak.auth-server-url=http://127.0.0.9:98765/
|
||||
keycloak.realm=local-devel
|
||||
keycloak.resource=portal-app
|
||||
keycloak.public-client=true
|
||||
### VERY BAD, TO-DO: mock Docker results:
|
||||
lysergic.docker.endpoint=tcp://sweetsuse:2375
|
14
src/test/resources/schema.sql
Normal file
14
src/test/resources/schema.sql
Normal file
@ -0,0 +1,14 @@
|
||||
CREATE TABLE scheduled_tasks (
|
||||
task_name varchar(40) not null,
|
||||
task_instance varchar(100) not null,
|
||||
task_data blob,
|
||||
execution_time timestamp(6) not null,
|
||||
picked BOOLEAN not null,
|
||||
picked_by varchar(50),
|
||||
last_success timestamp(6) null,
|
||||
last_failure timestamp(6) null,
|
||||
consecutive_failures INT,
|
||||
last_heartbeat timestamp(6) null,
|
||||
version BIGINT not null,
|
||||
PRIMARY KEY (task_name, task_instance)
|
||||
);
|
Loading…
Reference in New Issue
Block a user