Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
add KeyControllerV2 unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ubhaller committed Jul 15, 2021
1 parent 6595383 commit d81d335
Show file tree
Hide file tree
Showing 10 changed files with 647 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,19 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>Jar Tests Package</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

package ch.admin.bag.covidcertificate.backend.verifier.data;

import static ch.admin.bag.covidcertificate.backend.verifier.data.util.TestUtil.getDefaultCsca;
import static ch.admin.bag.covidcertificate.backend.verifier.data.util.TestUtil.getEcDsc;
import static ch.admin.bag.covidcertificate.backend.verifier.data.util.TestUtil.getRsaDsc;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import ch.admin.bag.covidcertificate.backend.verifier.model.CertSource;
import ch.admin.bag.covidcertificate.backend.verifier.model.cert.Algorithm;
import ch.admin.bag.covidcertificate.backend.verifier.model.cert.CertFormat;
import ch.admin.bag.covidcertificate.backend.verifier.model.cert.ClientCert;
import ch.admin.bag.covidcertificate.backend.verifier.model.cert.db.DbCsca;
import ch.admin.bag.covidcertificate.backend.verifier.model.cert.db.DbDsc;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -208,41 +209,4 @@ void findMaxDscsTest() {
assertTrue(verifierDataService.findDscs(maxDscPkId, CertFormat.IOS, null).isEmpty());
assertEquals(1, verifierDataService.findDscs(maxDscPkId - 1, CertFormat.IOS, null).size());
}

private DbCsca getDefaultCsca(int idSuffix, String origin) {
var dbCsca = new DbCsca();
dbCsca.setKeyId("keyid_" + idSuffix);
dbCsca.setCertificateRaw("cert");
dbCsca.setOrigin(origin);
dbCsca.setSubjectPrincipalName("admin_ch");
return dbCsca;
}

private DbDsc getRsaDsc(int idSuffix, String origin, long fkCsca) {
final var dbDsc = new DbDsc();
dbDsc.setKeyId("keyid_" + idSuffix);
dbDsc.setFkCsca(fkCsca);
dbDsc.setCertificateRaw("cert");
dbDsc.setOrigin(origin);
dbDsc.setUse("sig");
dbDsc.setAlg(Algorithm.RS256);
dbDsc.setN("n");
dbDsc.setE("e");
dbDsc.setSubjectPublicKeyInfo("pk");
return dbDsc;
}

private DbDsc getEcDsc(int idSuffix, String origin, long fkCsca) {
final var dbDsc = new DbDsc();
dbDsc.setKeyId("keyid_" + idSuffix);
dbDsc.setFkCsca(fkCsca);
dbDsc.setCertificateRaw("cert");
dbDsc.setOrigin(origin);
dbDsc.setUse("sig");
dbDsc.setAlg(Algorithm.ES256);
dbDsc.setCrv("crv");
dbDsc.setX("x");
dbDsc.setY("y");
return dbDsc;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.data.util;

import ch.admin.bag.covidcertificate.backend.verifier.model.cert.Algorithm;
import ch.admin.bag.covidcertificate.backend.verifier.model.cert.db.DbCsca;
import ch.admin.bag.covidcertificate.backend.verifier.model.cert.db.DbDsc;

public class TestUtil {

private TestUtil() {}

public static DbCsca getDefaultCsca(int idSuffix, String origin) {
var dbCsca = new DbCsca();
dbCsca.setKeyId("keyid_" + idSuffix);
dbCsca.setCertificateRaw("cert");
dbCsca.setOrigin(origin);
dbCsca.setSubjectPrincipalName("admin_ch");
return dbCsca;
}

public static DbDsc getRsaDsc(int idSuffix, String origin, long fkCsca) {
final var dbDsc = new DbDsc();
dbDsc.setKeyId("keyid_" + idSuffix);
dbDsc.setFkCsca(fkCsca);
dbDsc.setCertificateRaw("cert");
dbDsc.setOrigin(origin);
dbDsc.setUse("sig");
dbDsc.setAlg(Algorithm.RS256);
dbDsc.setN("n");
dbDsc.setE("e");
dbDsc.setSubjectPublicKeyInfo("pk");
return dbDsc;
}

public static DbDsc getEcDsc(int idSuffix, String origin, long fkCsca) {
final var dbDsc = new DbDsc();
dbDsc.setKeyId("keyid_" + idSuffix);
dbDsc.setFkCsca(fkCsca);
dbDsc.setCertificateRaw("cert");
dbDsc.setOrigin(origin);
dbDsc.setUse("sig");
dbDsc.setAlg(Algorithm.ES256);
dbDsc.setCrv("crv");
dbDsc.setX("x");
dbDsc.setY("y");
return dbDsc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class ActiveCertsResponse {
example = "172800000")
private Duration validDuration = Duration.ofHours(48);

public ActiveCertsResponse() {}

public ActiveCertsResponse(List<String> activeKeyIds) {
if (activeKeyIds == null) {
activeKeyIds = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
public class CertsResponse {
private List<ClientCert> certs = new ArrayList<>();

public CertsResponse() {}

public CertsResponse(List<ClientCert> certs) {
if (certs == null) {
certs = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.68</version>
</dependency>

<dependency>
<groupId>ch.admin.bag.covidcertificate</groupId>
<artifactId>ch-covidcertificate-backend-verifier-data</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.ws.controller;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;

@ActiveProfiles({"actuator-security"})
@SpringBootTest(
properties = {
"ws.monitor.prometheus.user=prometheus",
"ws.monitor.prometheus.password=prometheus",
"management.endpoints.enabled-by-default=true",
"management.endpoints.web.exposure.include=*"
})
@TestInstance(Lifecycle.PER_CLASS)
public class KeyControllerV2JsonTest extends KeyControllerV2Test {

@BeforeAll
public void setup() {
super.setup();
this.acceptMediaType = MediaType.APPLICATION_JSON;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.ws.controller;

import ch.admin.bag.covidcertificate.backend.verifier.ws.security.signature.JwsMessageConverter;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

@ActiveProfiles({"actuator-security"})
@SpringBootTest(
properties = {
"ws.monitor.prometheus.user=prometheus",
"ws.monitor.prometheus.password=prometheus",
"management.endpoints.enabled-by-default=true",
"management.endpoints.web.exposure.include=*"
})
@TestInstance(Lifecycle.PER_CLASS)
public class KeyControllerV2JwsTest extends KeyControllerV2Test {

@BeforeAll
public void setup() {
super.setup();
this.acceptMediaType = JwsMessageConverter.JWS_MEDIA_TYPE;
}
}
Loading

0 comments on commit d81d335

Please sign in to comment.