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

Fix for flaky test AuthenticationTokenTest.equals #1338

Closed
wants to merge 3 commits into from
Closed
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 @@ -449,8 +449,19 @@
}

private String createTokenAsString() {
String header = base64Encode(jsonHeader.toString().getBytes());
String payload = base64Encode(jsonPayload.toString().getBytes());
//Sort the header and payload to get a deterministic Token each time
//Ensure keys and values are correctly formatted as JSON strings
JSONObject jsonObject = new JSONObject();
List<String> headerlist = new ArrayList<>();
jsonHeader.keySet().forEach(key -> headerlist.add("\"" + key.toString() + "\":" + jsonObject.valueToString(jsonHeader.get(key))));

Check notice

Code scanning / CodeQL

Useless toString on String Note

Redundant call to 'toString' on a String object.
Collections.sort(headerlist);
String header = "{" + String.join(", ", headerlist) + "}";
List<String> payloadlist = new ArrayList<>();
jsonPayload.keySet().forEach(key -> payloadlist.add("\"" + key.toString() + "\":" + jsonObject.valueToString(jsonPayload.get(key))));

Check notice

Code scanning / CodeQL

Useless toString on String Note

Redundant call to 'toString' on a String object.
Collections.sort(payloadlist);
String payload = "{" + String.join(", ", payloadlist) + "}";
header = base64Encode(header.getBytes());
payload = base64Encode(payload.getBytes());
String headerAndPayload = header + DOT + payload;
String signature = calculateSignature(headerAndPayload);
return headerAndPayload + DOT + signature;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void getSubdomainFails() {
@Test
void getAppToken() {
token = XsuaaTokenComp.createInstance(jwtGenerator.createToken());
assertThat(token.getAppToken(), startsWith("eyJqa3UiOiJodHRwOi8vbG9jYWx"));
assertThat(token.getAppToken(), startsWith("eyJhbGciOiJSUzI1NiIsICJqa3U"));
}

@Test
Expand Down
Loading