Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • fair-data-austria-db-repository/fda-services
1 result
Select Git revision
Show changes
Commits on Source (119)
Showing
with 378 additions and 108 deletions
METADATA_DB=fda
METADATA_USERNAME=postgres
METADATA_PASSWORD=postgres
METADATA_USERNAME=root
METADATA_PASSWORD=dbrepo
BROKER_USERNAME=fda
BROKER_PASSWORD=fda
BROKER_CONSUMERS=2
WEBSITE=http://example.com
TOKEN_MAX=5
LOGO=/path/to/logo.png
MAIL_FROM="Database Repository <noreply@example.com>"
MAIL_REPLY_TO="Admin <somebody@example.com>"
MAIL_VERIFY=false
......@@ -17,5 +16,5 @@ SMTP_PASSWORD=
JWT_ISSUER=dbrepo
JWT_SECRET=secret
JWT_EXPIRATION=86400000
EUREKA_SERVER=http://discovery-service:9090/eureka/
SHARED_FILESYSTEM=/tmp
LOG_LEVEL=trace # error, warning, info, debug, trace
METADATA_DB=fda
METADATA_USERNAME=postgres
METADATA_PASSWORD=postgres
METADATA_USERNAME=root
METADATA_PASSWORD=dbrepo
BROKER_USERNAME=fda
BROKER_PASSWORD=fda
BROKER_CONSUMERS=2
WEBSITE=http://example.com
TOKEN_MAX=5
LOGO=/path/to/logo.png
MAIL_FROM="Database Repository <noreply@example.com>"
MAIL_REPLY_TO="Admin <somebody@example.com>"
MAIL_VERIFY=false
......@@ -17,5 +16,5 @@ SMTP_PASSWORD=
JWT_ISSUER=dbrepo
JWT_SECRET=secret
JWT_EXPIRATION=86400000
EUREKA_SERVER=http://discovery-service:9090/eureka/
SHARED_FILESYSTEM=C:\tmp
LOG_LEVEL=trace # error, warning, info, debug, trace
before_script:
- "docker version"
- "docker compose version"
- "docker system prune -f"
- "mvn --version"
- "df / -h"
- "grep -rnw '@Test' | wc -l"
variables:
HOSTALIASES: ./hosts
......@@ -19,6 +21,7 @@ image: "docker/compose:latest"
stages:
- build-backend
- build-frontend
- test-backend
- build-docker
- release
......@@ -90,6 +93,69 @@ build-backend-metadata:
script:
- "make build-backend-metadata"
test-backend-authentication:
stage: test-backend
needs:
- build-backend-authentication
script:
- "make test-authentication-service"
test-backend-identifier:
stage: test-backend
needs:
- build-backend-authentication
script:
- "make test-identifier-service"
test-backend-container:
stage: test-backend
needs:
- build-backend-container
script:
- "make test-container-service"
test-backend-database:
stage: test-backend
needs:
- build-backend-database
script:
- "make test-database-service"
test-backend-discovery:
stage: test-backend
needs:
- build-backend-discovery
script:
- "make test-discovery-service"
test-backend-query:
stage: test-backend
needs:
- build-backend-query
script:
- "make test-query-service"
test-backend-table:
stage: test-backend
needs:
- build-backend-table
script:
- "make test-table-service"
test-backend-metadata:
stage: test-backend
needs:
- build-backend-metadata
script:
- "make test-metadata-service"
test-backend-gateway:
stage: test-backend
needs:
- build-backend-gateway
script:
- "make test-gateway-service"
build-docker:
stage: build-docker
needs:
......@@ -104,6 +170,7 @@ build-docker:
- build-backend-table
- build-backend-metadata
script:
- cp .env.unix.example .env
- make build-docker
build-frontend:
......@@ -119,6 +186,7 @@ release-latest:
refs:
- dev
script:
- cp .env.unix.example .env
- docker login -p "${DOCKER_PASSWORD}" -u "${DOCKER_USERNAME}"
- TAG=latest make release
......@@ -130,6 +198,7 @@ release-version:
refs:
- master
script:
- cp .env.unix.example .env
- docker login -p "${DOCKER_PASSWORD}" -u "${DOCKER_USERNAME}"
- TAG=1.1 make release
......
......@@ -193,31 +193,35 @@ pull-metadata:
test-backend: test-authentication-service test-container-service test-database-service test-discovery-service test-gateway-service test-query-service test-table-service test-identifier-service test-metadata-service
test-backend-auth:
test-authentication-service: build-backend-metadata-db
mvn -f ./fda-authentication-service/pom.xml clean test verify
test-identifier-service:
test-identifier-service: build-backend-metadata-db
mvn -f ./fda-identifier-service/pom.xml clean test verify
test-container-service:
test-container-service: build-backend-metadata-db
docker system prune -f
docker pull mysql:8.0
mvn -f ./fda-container-service/pom.xml clean test verify
test-database-service:
test-database-service: build-backend-metadata-db
docker system prune -f
docker pull rabbitmq:3-management-alpine
mvn -f ./fda-database-service/pom.xml clean test verify
test-discovery-service:
test-discovery-service: build-backend-metadata-db
mvn -f ./fda-discovery-service/pom.xml clean test verify
test-gateway-service:
test-gateway-service: build-backend-metadata-db
mvn -f ./fda-gateway-service/pom.xml clean test verify
test-query-service:
test-query-service: build-backend-metadata-db
mvn -f ./fda-query-service/pom.xml clean test verify
test-table-service:
test-table-service: build-backend-metadata-db
mvn -f ./fda-table-service/pom.xml clean test verify
test-metadata-service:
test-metadata-service: build-backend-metadata-db
mvn -f ./fda-metadata-service/pom.xml clean test verify
coverage-frontend: clean build-frontend
......
File moved
......@@ -54,8 +54,6 @@ services:
image: dbrepo/discovery-service:latest
networks:
core:
ports:
- "9090:9090"
env_file:
- .env
logging:
......@@ -86,8 +84,6 @@ services:
networks:
userdb:
core:
ports:
- "9092:9092"
env_file:
- .env
volumes:
......@@ -109,8 +105,6 @@ services:
image: dbrepo/container-service:latest
networks:
core:
ports:
- "9091:9091"
env_file:
- .env
volumes:
......@@ -128,8 +122,6 @@ services:
image: dbrepo/authentication-service:latest
networks:
core:
ports:
- "9097:9097"
env_file:
- .env
depends_on:
......@@ -150,8 +142,6 @@ services:
networks:
core:
userdb:
ports:
- "9093:9093"
env_file:
- .env
volumes:
......@@ -172,8 +162,6 @@ services:
networks:
core:
userdb:
ports:
- "9094:9094"
env_file:
- .env
volumes:
......@@ -196,8 +184,6 @@ services:
image: dbrepo/identifier-service:latest
networks:
core:
ports:
- "9096:9096"
env_file:
- .env
volumes:
......@@ -219,8 +205,6 @@ services:
core:
env_file:
- .env
ports:
- "9099:9099"
depends_on:
metadata-db:
condition: service_started
......@@ -236,8 +220,6 @@ services:
core:
userdb:
command: sh -c "/wait && flask run" # docker-compose should not test the implementation
ports:
- "5000:5000"
volumes:
- ${SHARED_FILESYSTEM}:/tmp
- /var/run/docker.sock:/var/run/docker.sock
......@@ -254,8 +236,6 @@ services:
image: dbrepo/units-service:latest
networks:
core:
ports:
- "5010:5010"
volumes:
- /tmp:/tmp
- /var/run/docker.sock:/var/run/docker.sock
......@@ -273,8 +253,6 @@ services:
networks:
core:
ports:
- "5672:5672"
- "9098:9098"
- "15672:15672"
env_file:
- .env
......@@ -301,9 +279,6 @@ services:
depends_on:
discovery-service:
condition: service_healthy
ports:
- 9200:9200
- 9600:9600
volumes:
- search-service-data:/usr/share/elasticsearch/data
logging:
......
......@@ -11,7 +11,7 @@ volumes:
networks:
public:
name: core
name: public
driver: bridge
ipam:
config:
......@@ -23,7 +23,7 @@ networks:
config:
- subnet: 172.28.0.0/16
core:
name: public
name: core
driver: bridge
ipam:
config:
......@@ -40,9 +40,11 @@ services:
networks:
core:
volumes:
- metadata-db-data:/var/lib/postgresql/data
- metadata-db-data:/var/lib/mysql
ports:
- "5432:5432"
- "3306:3306"
env_file:
- .env
logging:
driver: json-file
......@@ -56,6 +58,8 @@ services:
core:
ports:
- "9090:9090"
env_file:
- .env
environment:
SPRING_PROFILES_ACTIVE: docker
logging:
......@@ -73,6 +77,8 @@ services:
SPRING_PROFILES_ACTIVE: docker
ports:
- "9095:9095"
env_file:
- .env
depends_on:
fda-discovery-service:
condition: service_healthy
......@@ -92,6 +98,8 @@ services:
SPRING_PROFILES_ACTIVE: docker
ports:
- "9092:9092"
env_file:
- .env
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
......@@ -116,6 +124,8 @@ services:
SPRING_PROFILES_ACTIVE: docker
ports:
- "9091:9091"
env_file:
- .env
volumes:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
......@@ -136,6 +146,8 @@ services:
SPRING_PROFILES_ACTIVE: docker
ports:
- "9097:9097"
env_file:
- .env
depends_on:
fda-discovery-service:
condition: service_healthy
......@@ -157,6 +169,8 @@ services:
userdb:
ports:
- "9093:9093"
env_file:
- .env
environment:
SPRING_PROFILES_ACTIVE: docker
volumes:
......@@ -185,6 +199,8 @@ services:
multipart.location: /tmp
ports:
- "9094:9094"
env_file:
- .env
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- "/tmp:/tmp"
......@@ -210,6 +226,8 @@ services:
SPRING_PROFILES_ACTIVE: docker
ports:
- "9096:9096"
env_file:
- .env
volumes:
- "/tmp:/tmp"
depends_on:
......@@ -232,6 +250,8 @@ services:
SPRING_PROFILES_ACTIVE: docker
ports:
- "9099:9099"
env_file:
- .env
depends_on:
fda-metadata-db:
condition: service_started
......@@ -252,6 +272,8 @@ services:
hostname: analyse-service
ports:
- "5000:5000"
env_file:
- .env
volumes:
- "/tmp:/tmp"
- /var/run/docker.sock:/var/run/docker.sock
......@@ -269,16 +291,18 @@ services:
image: fda-units-service
networks:
core:
environment:
EUREKA_SERVER: http://fda-discovery-service:9090/eureka/
ports:
- "5010:5010"
env_file:
- .env
volumes:
- "/tmp:/tmp"
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
fda-discovery-service:
condition: service_healthy
fda-metadata-db:
condition: service_healthy
logging:
driver: json-file
......@@ -295,6 +319,8 @@ services:
ports:
- "5672:5672"
- "15672:15672"
env_file:
- .env
depends_on:
fda-discovery-service:
condition: service_healthy
......@@ -322,6 +348,8 @@ services:
ports:
- 9200:9200
- 9600:9600
env_file:
- .env
volumes:
- search-service-data:/usr/share/elasticsearch/data
logging:
......@@ -335,8 +363,11 @@ services:
image: fda-ui
networks:
core:
public:
ports:
- "3000:3000"
env_file:
- .env
volumes:
- "/tmp:/tmp"
depends_on:
......
......@@ -22,8 +22,8 @@ RUN mvn -q clean package -DskipTests
FROM openjdk:11-jre-slim as runtime
ENV METADATA_DB=fda
ENV METADATA_USERNAME=postgres
ENV METADATA_PASSWORD=postgres
ENV METADATA_USERNAME=root
ENV METADATA_PASSWORD=dbrepo
ENV BROKER_USERNAME=fda
ENV BROKER_PASSWORD=fda
ENV WEBSITE=http://example.com
......@@ -39,6 +39,7 @@ ENV SMTP_HOST=""
ENV SMTP_PORT=""
ENV SMTP_USERNAME=""
ENV SMTP_PASSWORD=""
ENV LOG_LEVEL=debug
VOLUME /tmp
......@@ -47,8 +48,8 @@ RUN chmod +x /usr/bin/service_ready
HEALTHCHECK --interval=10s --timeout=5s --retries=12 CMD service_ready
COPY --from=build ./rest-service/target/rest-service-*.jar ./rest-service.jar
COPY --from=build ./rest-service/target/rest-service-*.jar ./authentication-service.jar
EXPOSE 9097
ENTRYPOINT ["java", "-Dlog4j2.formatMsgNoLookups=true", "-jar", "./rest-service.jar"]
ENTRYPOINT ["java", "-Dlog4j2.formatMsgNoLookups=true", "-jar", "./authentication-service.jar"]
......@@ -117,6 +117,11 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${mariadb.version}</version>
</dependency>
<!-- IDE -->
<dependency>
<groupId>org.projectlombok</groupId>
......
......@@ -67,10 +67,7 @@ public class TokenEndpoint {
TokenNotEligableException {
log.debug("endpoint create developer token, principal={}", principal);
/* check */
final List<Token> tokens = tokenService.findAll(principal)
.stream()
.filter(t -> Objects.isNull(t.getDeleted()))
.collect(Collectors.toList());
final List<Token> tokens = tokenService.findAll(principal);
log.trace("found all tokens {}", tokens);
if (tokens.size() >= authenticationConfig.getTokenCount()) {
log.error("Failed to create token, already exceeded maximum quota of {}", authenticationConfig.getTokenCount());
......@@ -84,16 +81,17 @@ public class TokenEndpoint {
.body(dto);
}
@DeleteMapping("/{hash}")
@DeleteMapping("/{id}")
@Transactional
@Timed(value = "token.delete", description = "Time needed to delete the developer tokens")
@Operation(summary = "Delete developer token", security = @SecurityRequirement(name = "bearerAuth"))
public void delete(@NotNull @PathVariable("hash") String hash,
public void delete(@NotNull @PathVariable("id") Long id,
@NotNull Principal principal) throws TokenNotFoundException, UserNotFoundException {
log.debug("endpoint delete developer token, hash={}, principal={}", hash, principal);
final Token token = tokenService.findOne(hash);
log.debug("endpoint delete developer token, id={}, principal={}", id, principal);
final Token token = tokenService.findOne(id);
log.trace("found token {}", token);
tokenService.delete(token.getTokenHash(), principal);
log.info("Deleted token with id {}", id);
}
}
\ No newline at end of file
......@@ -2,18 +2,20 @@ app.version: '@project.version@'
spring:
main.banner-mode: off
datasource:
url: jdbc:postgresql://metadata-db:5432/fda
driver-class-name: org.postgresql.Driver
username: postgres
password: postgres
url: jdbc:mariadb://metadata-db:3306/fda
driver-class-name: org.mariadb.jdbc.Driver
username: "${METADATA_USERNAME}"
password: "${METADATA_PASSWORD}"
jpa:
show-sql: false
database-platform: org.hibernate.dialect.PostgreSQLDialect
database-platform: org.hibernate.dialect.MariaDBDialect
hibernate:
ddl-auto: validate
use-new-id-generator-mappings: false
open-in-view: false
properties:
hibernate:
default_schema: fda
jdbc:
time_zone: UTC
application:
......@@ -37,7 +39,7 @@ logging:
pattern.console: "%d %highlight(%-5level) %msg%n"
level:
root: warn
at.tuwien.: trace
at.tuwien.: "${LOG_LEVEL}"
org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver: debug
eureka:
instance.hostname: authentication-service
......
......@@ -2,18 +2,20 @@ app.version: '@project.version@'
spring:
main.banner-mode: off
datasource:
url: jdbc:postgresql://localhost:5432/fda
driver-class-name: org.postgresql.Driver
username: postgres
password: postgres
url: jdbc:mariadb://localhost:3306/fda
driver-class-name: org.mariadb.jdbc.Driver
username: root
password: dbrepo
jpa:
show-sql: false
database-platform: org.hibernate.dialect.PostgreSQLDialect
database-platform: org.hibernate.dialect.MariaDBDialect
hibernate:
ddl-auto: validate
use-new-id-generator-mappings: false
open-in-view: false
properties:
hibernate:
default_schema: fda
jdbc:
time_zone: UTC
application:
......
......@@ -2,18 +2,20 @@ app.version: '@project.version@'
spring:
main.banner-mode: off
datasource:
url: "jdbc:postgresql://metadata-db:5432/${METADATA_DB}"
driver-class-name: org.postgresql.Driver
url: "jdbc:mariadb://metadata-db:3306/${METADATA_DB}"
driver-class-name: org.mariadb.jdbc.Driver
username: "${METADATA_USERNAME}"
password: "${METADATA_PASSWORD}"
jpa:
show-sql: false
database-platform: org.hibernate.dialect.PostgreSQLDialect
database-platform: org.hibernate.dialect.MariaDBDialect
hibernate:
ddl-auto: validate
use-new-id-generator-mappings: false
open-in-view: false
properties:
hibernate:
default_schema: "${METADATA_DB}"
jdbc:
time_zone: UTC
application:
......@@ -40,7 +42,7 @@ logging:
pattern.console: "%d %highlight(%-5level) %msg%n"
level:
root: warn
at.tuwien.: trace
at.tuwien.: "${LOG_LEVEL}"
org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver: debug
eureka:
instance.hostname: authentication-service
......
package at.tuwien;
import at.tuwien.api.auth.SignupRequestDto;
import at.tuwien.api.user.UserDetailsDto;
import at.tuwien.entities.user.RoleType;
import at.tuwien.entities.user.TimeSecret;
import at.tuwien.entities.user.Token;
import at.tuwien.entities.user.User;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.test.context.TestPropertySource;
import java.security.Principal;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
@TestPropertySource(locations = "classpath:application.properties")
public abstract class BaseUnitTest {
......@@ -38,9 +44,21 @@ public abstract class BaseUnitTest {
.emailVerified(USER_1_VERIFIED)
.themeDark(USER_1_THEME_DARK)
.created(USER_1_CREATED)
.roles(List.of(RoleType.ROLE_RESEARCHER))
.lastModified(USER_1_LAST_MODIFIED)
.build();
public final static UserDetails USER_1_DETAILS = UserDetailsDto.builder()
.username(USER_1_USERNAME)
.email(USER_1_EMAIL)
.password(USER_1_PASSWORD)
.authorities(List.of(new SimpleGrantedAuthority("ROLE_RESEARCHER")))
.build();
public final static Principal USER_1_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_1_DETAILS,
USER_1_PASSWORD, USER_1_DETAILS.getAuthorities());
public final static Long USER_2_ID = 2L;
public final static String USER_2_EMAIL = "jane.doe@example.com";
public final static String USER_2_USERNAME = "jdoe2";
......@@ -59,37 +77,64 @@ public abstract class BaseUnitTest {
.emailVerified(USER_2_VERIFIED)
.themeDark(USER_2_THEME_DARK)
.created(USER_2_CREATED)
.roles(List.of(RoleType.ROLE_RESEARCHER))
.lastModified(USER_2_LAST_MODIFIED)
.build();
public final static Long TOKEN_1_ID = 1L;
public final static Boolean TOKEN_1_PROCESSED = false;
public final static String TOKEN_1_TOKEN = "mysecrettokenrandomlygenerated";
public final static Instant TOKEN_1_VALID_TO = Instant.now()
public final static UserDetails USER_2_DETAILS = UserDetailsDto.builder()
.username(USER_2_USERNAME)
.email(USER_2_EMAIL)
.password(USER_2_PASSWORD)
.authorities(List.of(new SimpleGrantedAuthority("ROLE_RESEARCHER")))
.build();
public final static Principal USER_2_PRINCIPAL = new UsernamePasswordAuthenticationToken(USER_2_DETAILS,
USER_2_PASSWORD, USER_2_DETAILS.getAuthorities());
public final static Long TIME_SECRET_1_ID = 1L;
public final static Boolean TIME_SECRET_1_PROCESSED = false;
public final static String TIME_SECRET_1_TOKEN = "mysecrettokenrandomlygenerated";
public final static Instant TIME_SECRET_1_VALID_TO = Instant.now()
.plus(1, ChronoUnit.DAYS);
public final static Long TOKEN_2_ID = 2L;
public final static Boolean TOKEN_2_PROCESSED = true;
public final static String TOKEN_2_TOKEN = "blahblahblah";
public final static Instant TOKEN_2_VALID_TO = Instant.now()
public final static Long TIME_SECRET_2_ID = 2L;
public final static Boolean TIME_SECRET_2_PROCESSED = true;
public final static String TIME_SECRET_2_TOKEN = "blahblahblah";
public final static Instant TIME_SECRET_2_VALID_TO = Instant.now()
.plus(1, ChronoUnit.DAYS);
public final static TimeSecret TOKEN_1 = TimeSecret.builder()
.id(TOKEN_1_ID)
public final static TimeSecret TIME_SECRET_1 = TimeSecret.builder()
.id(TIME_SECRET_1_ID)
.uid(USER_1_ID)
.user(USER_1)
.token(TOKEN_1_TOKEN)
.processed(TOKEN_1_PROCESSED)
.validTo(TOKEN_1_VALID_TO)
.token(TIME_SECRET_1_TOKEN)
.processed(TIME_SECRET_1_PROCESSED)
.validTo(TIME_SECRET_1_VALID_TO)
.build();
public final static TimeSecret TOKEN_2 = TimeSecret.builder()
.id(TOKEN_2_ID)
public final static TimeSecret TIME_SECRET_2 = TimeSecret.builder()
.id(TIME_SECRET_2_ID)
.uid(USER_2_ID)
.user(USER_2)
.token(TOKEN_2_TOKEN)
.processed(TOKEN_2_PROCESSED)
.validTo(TOKEN_2_VALID_TO)
.token(TIME_SECRET_2_TOKEN)
.processed(TIME_SECRET_2_PROCESSED)
.validTo(TIME_SECRET_2_VALID_TO)
.build();
public final static Long TOKEN_1_ID = 1L;
public final static Instant TOKEN_1_EXPIRES = Instant.now().plus(100000000, ChronoUnit.MILLIS);
public final static Token TOKEN_1 = Token.builder()
.id(TOKEN_1_ID)
.expires(TOKEN_1_EXPIRES)
.build();
public final static Long TOKEN_2_ID = 2L;
public final static Instant TOKEN_2_EXPIRES = Instant.now().plus(100000000, ChronoUnit.MILLIS);
public final static Token TOKEN_2 = Token.builder()
.id(TOKEN_2_ID)
.expires(TOKEN_2_EXPIRES)
.build();
}
package at.tuwien.config;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.codehaus.plexus.util.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityManager;
import java.io.File;
import java.io.IOException;
@Log4j2
@Component
public class H2Utils {
@Autowired
private EntityManager entityManager;
@Transactional
public void runQuery(String query) {
log.debug("query={}", query);
entityManager.createNativeQuery(query)
.executeUpdate();
}
@Transactional
public void runScript(String scriptName) {
try {
runQuery(FileUtils.fileRead(new File("./src/test/resources/" + scriptName)));
} catch (IOException e) {
log.error("Failed to load script {}", scriptName);
throw new RuntimeException("Failed to load script", e);
}
}
}
......@@ -41,10 +41,10 @@ public class AuthenticationServiceIntegrationTest extends BaseUnitTest {
public void beforeEach() {
final User u1 = userRepository.save(USER_1);
final User u2 = userRepository.save(USER_2);
TOKEN_1.setUser(u1);
tokenRepository.save(TOKEN_1);
TOKEN_2.setUser(u2);
tokenRepository.save(TOKEN_2);
TIME_SECRET_1.setUser(u1);
tokenRepository.save(TIME_SECRET_1);
TIME_SECRET_2.setUser(u2);
tokenRepository.save(TIME_SECRET_2);
}
@Test
......
......@@ -4,6 +4,7 @@ import at.tuwien.BaseUnitTest;
import at.tuwien.config.ReadyConfig;
import at.tuwien.exception.SecretInvalidException;
import at.tuwien.repositories.TimeSecretRepository;
import at.tuwien.repositories.UserRepository;
import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
......@@ -20,31 +21,33 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class TokenServiceIntegrationTest extends BaseUnitTest {
public class TimeSecretUnitTest extends BaseUnitTest {
@MockBean
private ReadyConfig readyConfig;
@Autowired
private TimeSecretService tokenService;
private TimeSecretService timeSecretService;
@Autowired
private TimeSecretRepository tokenRepository;
private TimeSecretRepository timeSecretRepository;
@Autowired
private UserRepository userRepository;
@BeforeEach
public void beforeEach() {
tokenRepository.save(TOKEN_1);
userRepository.save(USER_1);
timeSecretRepository.save(TIME_SECRET_1);
}
@Test
public void updateVerification_succeeds() throws SecretInvalidException {
/* mock */
/* test */
tokenService.invalidate(TOKEN_1_TOKEN);
timeSecretService.invalidate(TIME_SECRET_1_TOKEN);
assertThrows(SecretInvalidException.class, () -> {
tokenService.invalidate(TOKEN_1_TOKEN);
timeSecretService.invalidate(TIME_SECRET_1_TOKEN);
});
}
......
package at.tuwien.service;
import at.tuwien.BaseUnitTest;
import at.tuwien.auth.JwtUtils;
import at.tuwien.config.H2Utils;
import at.tuwien.config.ReadyConfig;
import at.tuwien.entities.user.Token;
import at.tuwien.exception.TokenNotEligableException;
import at.tuwien.exception.UserNotFoundException;
import at.tuwien.repositories.TokenRepository;
import at.tuwien.repositories.UserRepository;
import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import javax.servlet.ServletException;
import static org.junit.jupiter.api.Assertions.assertThrows;
@Log4j2
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class TokenIntegrationTest extends BaseUnitTest {
@MockBean
private ReadyConfig readyConfig;
@Autowired
private TokenService tokenService;
@Autowired
private UserRepository userRepository;
@Autowired
private TokenRepository tokenRepository;
@Autowired
private JwtUtils jwtUtils;
@Autowired
private H2Utils h2Utils;
@BeforeEach
public void beforeEach() {
userRepository.save(USER_1);
h2Utils.runScript("post-init.sql");
}
@Test
public void check_succeeds() throws ServletException, UserNotFoundException, TokenNotEligableException {
/* mock */
tokenService.create(USER_1_PRINCIPAL);
final Token token = tokenService.create(USER_1_PRINCIPAL);
/* test */
tokenService.check(token.getToken());
}
@Test
public void check_revoked_fails() throws UserNotFoundException, TokenNotEligableException {
/* mock */
final Token token = tokenService.create(USER_1_PRINCIPAL);
/* test */
assertThrows(ServletException.class, () -> {
tokenService.check(token.getToken());
});
}
@Test
public void create_userNotFound_fails() {
/* test */
assertThrows(UserNotFoundException.class, () -> {
tokenService.create(USER_2_PRINCIPAL);
});
}
}
......@@ -9,10 +9,13 @@ spring.cloud.config.discovery.enabled = false
spring.cloud.config.enabled = false
# disable datasource
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE;INIT=runscript from './src/test/resources/pre-init.sql'
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=false
# disable mail health check
management.health.mail.enabled=false
\ No newline at end of file
-- Modified for H2
-- Assume id=1 is invalid
-- Assume id=2 is still valid token
CREATE VIEW IF NOT EXISTS mdb_invalid_tokens AS
(SELECT `id`, `token_hash`, `creator`, `created`, `expires`, `last_used` FROM FDA.`mdb_tokens` WHERE `id` = 1);
\ No newline at end of file