Skip to content

Commit

Permalink
Code Smells and additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slaurenz committed Mar 24, 2022
1 parent 3511856 commit 98ddd47
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import eu.europa.ec.dgc.gateway.connector.model.QueryParameter;
import eu.europa.ec.dgc.gateway.connector.model.TrustedIssuer;
import eu.europa.ec.dgc.signing.SignedCertificateMessageParser;
import eu.europa.ec.dgc.signing.SignedMessageParser;
import eu.europa.ec.dgc.signing.SignedStringMessageParser;
import eu.europa.ec.dgc.utils.CertificateUtils;
import feign.FeignException;
Expand Down Expand Up @@ -158,7 +159,7 @@ boolean checkTrustAnchorSignature(TrustListItemDto trustListItem, List<X509Certi
SignedCertificateMessageParser parser = new SignedCertificateMessageParser(
trustListItem.getSignature(), trustListItem.getRawData());

if (parser.getParserState() != SignedCertificateMessageParser.ParserState.SUCCESS) {
if (parser.getParserState() != SignedMessageParser.ParserState.SUCCESS) {
log.error("Could not parse trustListItem CMS. ParserState: {}", parser.getParserState());
return false;
} else if (!parser.isSignatureVerified()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public <T extends Serializable> void setQueryParameter(QueryParameter<T> queryPa
* result in a list of "CSCA" and "UPLOAD" certificates with at least one matching property.
*/
public <T extends Serializable> void setQueryParameter(QueryParameter<T> queryParameter, List<T> values) {
if (!queryParameter.getArrayValue() && values.size() > 1) {
if (Boolean.FALSE.equals(queryParameter.getArrayValue()) && values.size() > 1) {
throw new IllegalArgumentException("Only one value is allowed for non-array query parameters.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package eu.europa.ec.dgc.gateway.connector;

import eu.europa.ec.dgc.gateway.connector.client.DgcGatewayConnectorRestClient;
import eu.europa.ec.dgc.gateway.connector.model.QueryParameter;
import eu.europa.ec.dgc.gateway.connector.model.TrustedIssuer;
import eu.europa.ec.dgc.testdata.TrustedIssuerTestHelper;
import feign.FeignException;
Expand All @@ -37,6 +38,7 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.ResponseEntity;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -91,4 +93,30 @@ private Request dummyRequest() {
return Request.create(Request.HttpMethod.GET, "url", new HashMap<>(), null, new RequestTemplate());
}

@Test
void setQueryParameters() throws Exception {
Map<String,String> param = new HashMap<>();
param.put("country","DE");

when(restClientMock.downloadTrustedIssuers(param))
.thenReturn(ResponseEntity.ok(
List.of(trustedIssuerTestHelper.createTrustedIssuer("DE"))));

connector.setQueryParameter(QueryParameter.COUNTRY_CODE, "DE");
List<TrustedIssuer> result = connector.getTrustedIssuers();

Assertions.assertEquals(1, result.size());
Assertions.assertEquals("DE", result.get(0).getCountry());

connector.setQueryParameter(QueryParameter.WITH_FEDERATION, List.of(true,false));

}

@Test
public void setWrongQueryFormat() {
assertThrows(IllegalArgumentException.class, () -> {
connector.setQueryParameter(QueryParameter.WITH_FEDERATION, List.of(true,false));
});
}

}

0 comments on commit 98ddd47

Please sign in to comment.