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

Adjust submission payload validation checks #832

Merged
merged 1 commit into from
Sep 30, 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 @@ -92,8 +92,7 @@ public boolean isValid(SubmissionPayload submissionPayload, ConstraintValidatorC
return checkStartIntervalNumberIsAtMidNight(exposureKeys, validatorContext);
} else {
return checkStartIntervalNumberIsAtMidNight(exposureKeys, validatorContext)
&& checkKeyCollectionSize(exposureKeys, validatorContext)
&& checkUniqueStartIntervalNumbers(exposureKeys, validatorContext);
&& checkKeyCollectionSize(exposureKeys, validatorContext);
}
}

Expand All @@ -111,22 +110,6 @@ private boolean checkKeyCollectionSize(List<TemporaryExposureKey> exposureKeys,
return true;
}

private boolean checkUniqueStartIntervalNumbers(List<TemporaryExposureKey> exposureKeys,
ConstraintValidatorContext validatorContext) {
Integer[] startIntervalNumbers = exposureKeys.stream()
.mapToInt(TemporaryExposureKey::getRollingStartIntervalNumber).boxed().toArray(Integer[]::new);
long distinctSize = Arrays.stream(startIntervalNumbers)
.distinct()
.count();

if (distinctSize < exposureKeys.size()) {
addViolation(validatorContext, String.format(
"Duplicate StartIntervalNumber found. StartIntervalNumbers: %s", startIntervalNumbers));
return false;
}
return true;
}

private boolean keysHaveFlexibleRollingPeriod(List<TemporaryExposureKey> exposureKeys) {
return exposureKeys.stream()
.anyMatch(temporaryExposureKey -> temporaryExposureKey.getRollingPeriod() < maxRollingPeriod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ private Collection<TemporaryExposureKey> buildPayloadWithTooManyKeys() {
}

@Test
void check400ResponseStatusForKeysWithFixedRollingPeriodAndDuplicateStartIntervals() {
void check200ResponseStatusForKeysWithFixedRollingPeriodAndDuplicateStartIntervals() {
int rollingStartIntervalNumber = createRollingStartIntervalNumber(2);
var keysWithDuplicateStartIntervalNumber = Lists.list(
buildTemporaryExposureKey(VALID_KEY_DATA_1, rollingStartIntervalNumber, 1),
buildTemporaryExposureKey(VALID_KEY_DATA_2, rollingStartIntervalNumber, 2));

ResponseEntity<Void> actResponse = executor.executePost(keysWithDuplicateStartIntervalNumber);

assertThat(actResponse.getStatusCode()).isEqualTo(BAD_REQUEST);
assertThat(actResponse.getStatusCode()).isEqualTo(OK);
}

@Test
Expand Down