Skip to content
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
2 changes: 2 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ Changes log
(such as a `Negotiate` token): the whole header was dropped. Issue #191.
- The `realm` and `charset` parameters of an HTTP Basic challenge are now recognized whatever
their case (`Realm=`, `Charset=`), as required by RFC 9110. Issue #1455.
- `ChallengeScheme.valueOf()` returned `HTTP_OAUTH` for the names of the Bearer and MAC schemes
(`HTTP_Bearer`, `HTTP_MAC`) instead of `HTTP_OAUTH_BEARER` and `HTTP_OAUTH_MAC`. Issue #1618.
- Misc
- Fixed JDK HTTP client accessibility in core and WebSocket tests in Eclipse and VS Code,
without adding a production module dependency.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public final class ChallengeScheme {
Map.entry(HTTP_DIGEST.getName().toLowerCase(), HTTP_DIGEST),
Map.entry(HTTP_NTLM.getName().toLowerCase(), HTTP_NTLM),
Map.entry(HTTP_OAUTH.getName().toLowerCase(), HTTP_OAUTH),
Map.entry(HTTP_OAUTH_BEARER.getName().toLowerCase(), HTTP_OAUTH),
Map.entry(HTTP_OAUTH_MAC.getName().toLowerCase(), HTTP_OAUTH));
Map.entry(HTTP_OAUTH_BEARER.getName().toLowerCase(), HTTP_OAUTH_BEARER),
Map.entry(HTTP_OAUTH_MAC.getName().toLowerCase(), HTTP_OAUTH_MAC));

/**
* Returns the challenge scheme associated with a scheme name. If an existing constant exists,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,12 @@ public static void update(
challengeResponse.setOpaque(challengeRequest.getOpaque());

// Credentials charset advertised by the server (RFC 7617, section 2.1)
String charset = challengeRequest.getParameters().getFirstValue(CHARSET_PARAMETER, true);
String charset =
challengeRequest.getParameters().getFirstValue(CHARSET_PARAMETER, true);
if (ChallengeScheme.HTTP_BASIC.equals(challengeResponse.getScheme())
&& charset != null
&& challengeResponse.getParameters().getFirstValue(CHARSET_PARAMETER, true) == null) {
&& challengeResponse.getParameters().getFirstValue(CHARSET_PARAMETER, true)
== null) {
challengeResponse.getParameters().add(CHARSET_PARAMETER, charset);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ void valueOf_isCaseInsensitive() {
assertSame(ChallengeScheme.HTTP_BASIC, ChallengeScheme.valueOf("http_basic"));
}

/** Issue #1618: the Bearer and MAC schemes used to be mapped to HTTP_OAUTH. */
@Test
void valueOf_oauthBearerAndMac_returnTheirOwnConstants() {
assertSame(ChallengeScheme.HTTP_OAUTH_BEARER, ChallengeScheme.valueOf("HTTP_Bearer"));
assertSame(ChallengeScheme.HTTP_OAUTH_BEARER, ChallengeScheme.valueOf("http_bearer"));
assertSame(ChallengeScheme.HTTP_OAUTH_MAC, ChallengeScheme.valueOf("HTTP_MAC"));
assertSame(ChallengeScheme.HTTP_OAUTH, ChallengeScheme.valueOf("HTTP_OAuth"));
}

/**
* Every constant must be found again by its name, so that a missing or mistaken entry in the
* lookup table is detected. HTTP_AWS_IAM and HTTP_AWS_QUERY are deliberately resolved to
* HTTP_AWS_S3.
*/
@Test
void valueOf_everyConstant_isFoundByItsName() throws IllegalAccessException {
int checked = 0;
for (java.lang.reflect.Field field : ChallengeScheme.class.getFields()) {
if (field.getType() != ChallengeScheme.class
|| !java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
continue;
}
ChallengeScheme constant = (ChallengeScheme) field.get(null);
if (constant == ChallengeScheme.HTTP_AWS_IAM
|| constant == ChallengeScheme.HTTP_AWS_QUERY) {
continue;
}
assertSame(constant, ChallengeScheme.valueOf(constant.getName()), field.getName());
checked++;
}
assertEquals(12, checked);
}

@Test
void valueOf_unknownName_createsNewInstance() {
ChallengeScheme scheme = ChallengeScheme.valueOf("CUSTOM_SCHEME");
Expand Down
Loading