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

Fix Sonar issues #754

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
package app.coronawarn.server.services.distribution.config;

import app.coronawarn.server.common.protocols.external.exposurenotification.SignatureInfo;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.validation.constraints.Max;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ private String loadChecksum() {

protected String createS3Key(Path file, Path rootFolder) {
Path relativePath = rootFolder.relativize(file);
return relativePath.toString().replaceAll("\\\\", "/");
return relativePath.toString().replace("\\\\", "/");
}

/**
* Value for the <code>content-type</code> header.
*
*
* @return Either <a href="https://www.iana.org/assignments/media-types/application/zip">zip</a> or
* <a href="https://www.iana.org/assignments/media-types/application/json">json</a>.
*/
Expand All @@ -108,7 +108,7 @@ public String getContentType() {
/**
* Indicates if a local file is a Key-file or not. Only the Key files are stored in the Date / Hour tree structure.
* One file per sub-folder (days: 1-31 / hours: 0-23). The index files are not stored in folders ending with a digit.
*
*
* @return <code>true</code> if and only if the {@link #s3Key} ends with a digit, false otherwise.
*/
public boolean isKeyFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,23 @@ public class ApiExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public void unknownException(Exception ex, WebRequest wr) {
logger.error("Unable to handle {}", wr.getDescription(false), ex);
logger.error("Unable to handle {}", getFormattedDescription(wr), ex);
}

@ExceptionHandler({HttpMessageNotReadableException.class, ServletRequestBindingException.class,
InvalidProtocolBufferException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
public void bindingExceptions(Exception ex, WebRequest wr) {
logger.error("Binding failed {}", wr.getDescription(false), ex);
logger.error("Binding failed {}", getFormattedDescription(wr), ex);
}

@ExceptionHandler({InvalidDiagnosisKeyException.class, ConstraintViolationException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
public void diagnosisKeyExceptions(Exception ex, WebRequest wr) {
logger.error("Erroneous Submission Payload {}", wr.getDescription(false), ex);
logger.error("Erroneous Submission Payload {}", getFormattedDescription(wr), ex);
}

private String getFormattedDescription(WebRequest wr) {
return wr.getDescription(false).replaceAll("[\n|\r|\t]", "_");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@
import app.coronawarn.server.services.submission.verification.TanVerifier;

/**
* This test serves more like a dev tool which helps with debugging production issues.
* It inserts keys parsed from a proto buf file whos content was captured by the mobile
* client during requests to the server. The content of the current test resource file
* can be quickly replaced during the investigation of an issue.
* This test serves more like a dev tool which helps with debugging production issues. It inserts keys parsed from a
* proto buf file whos content was captured by the mobile client during requests to the server. The content of the
* current test resource file can be quickly replaced during the investigation of an issue.
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({ "disable-ssl-client-verification", "disable-ssl-client-verification-verify-hostname" })
@ActiveProfiles({"disable-ssl-client-verification", "disable-ssl-client-verification-verify-hostname"})
@Sql(scripts = {"classpath:db/clean_db_state.sql"},
executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
public class SubmissionPersistenceIT {
executionPhase = ExecutionPhase.BEFORE_TEST_METHOD)
class SubmissionPersistenceIT {

private static final Logger logger = LoggerFactory.getLogger(SubmissionPersistenceIT.class);

Expand Down Expand Up @@ -97,8 +96,8 @@ public void setUpMocks() {
@Disabled("Because the content of the .pb file becomes old and retention time passes, this test will fail. "
+ "Enable when debugging of a new payload is required.")
@ParameterizedTest
@ValueSource(strings = { "src/test/resources/payload/mobile-client-payload.pb" })
public void testKeyInsertionWithMobileClientProtoBuf(String testFile) throws IOException {
@ValueSource(strings = {"src/test/resources/payload/mobile-client-payload.pb"})
void testKeyInsertionWithMobileClientProtoBuf(String testFile) throws IOException {
Path path = Paths.get(testFile);
InputStream input = new FileInputStream(path.toFile());
SubmissionPayload payload = SubmissionPayload.parseFrom(input);
Expand Down