Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respond with 400 instead of 500 when CSTG request validation fails #633

Merged
merged 3 commits into from
Jun 20, 2024

Conversation

caroline-ttd
Copy link
Contributor

No description provided.

@@ -453,6 +453,10 @@ else if(emailHash != null) {
input = InputUtil.normalizePhoneHash(phoneHash);
}

if (this.phoneSupport ? !checkTokenInputV1(input, rc) : !checkTokenInput(input, rc)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expression this.phoneSupport ? !checkTokenInputV1(input, rc) : !checkTokenInput(input, rc) appears 6 times in this file and ideally should be wrapped in a method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only difference between checkTokenInputV1 and checkTokenInput is the error message returned.

Can we remove checkTokenInputV1 and do the this.phoneSupport check in checkTokenInput?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the checkTokenInputV1 and did the this.phoneSupport check in checkTokenInput. Also invert the method.

}

@Test
void cstgInvalidPhoneHashInput(Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible to eliminate some of the duplication? the tests are identical other than the input. Can the input be parameterized?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good idea, I used the @ParameterizedTest

@@ -453,6 +453,10 @@ else if(emailHash != null) {
input = InputUtil.normalizePhoneHash(phoneHash);
}

if (checkTokenInput(input, rc)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (checkTokenInput) makes it seem like it succeeded. How about we rename this method to checkForInvalidTokenInput?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rename checkTokenInput to checkForInvalidTokenInput. true for invalid input, false for valid input.

@caroline-ttd caroline-ttd merged commit a645e2a into main Jun 20, 2024
4 checks passed
@caroline-ttd caroline-ttd deleted the ccm-UID2-3590-call-check-token-input-cstg branch June 20, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants