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
4 changes: 2 additions & 2 deletions src/main/java/com/retailsvc/http/OpenApiServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ private static void validateSecurityWiring(Spec spec, Map<String, SchemeValidato
throw new IllegalStateException(
"security requirement references unknown scheme '" + name + "'");
}
if (scheme instanceof SecurityScheme.Unsupported u) {
if (scheme instanceof SecurityScheme.Unsupported(String type)) {
throw new IllegalStateException(
"scheme '" + name + "' uses unsupported type '" + u.type() + "'");
"scheme '" + name + "' uses unsupported type '" + type + "'");
}
if (!validators.containsKey(name)) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private static ExtractionResult extractBasic(HttpExchange exchange) {
byte[] decoded;
try {
decoded = Base64.getDecoder().decode(parts[1]);
} catch (IllegalArgumentException e) {
} catch (IllegalArgumentException _) {
return ExtractionResult.malformed();
}
String creds = new String(decoded, StandardCharsets.UTF_8);
Expand Down
34 changes: 13 additions & 21 deletions src/test/java/com/retailsvc/http/SecurityBootValidationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@ void missingValidatorThrows() {
List.of(),
List.of(Map.of("bearerAuth", List.of())));
Spec spec = Spec.from(r);
OpenApiServer.Builder builder = handlerBuilder(spec);

assertThatThrownBy(
() ->
OpenApiServer.builder()
.spec(spec)
.handlers(Map.of("getX", req -> Response.ok(Map.of())))
.port(0)
.build())
assertThatThrownBy(builder::build)
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("bearerAuth");
}
Expand All @@ -71,14 +66,9 @@ void unsupportedSchemeThrowsWhenReferenced() {
List.of(),
List.of(Map.of("oauth", List.of())));
Spec spec = Spec.from(r);
OpenApiServer.Builder builder = handlerBuilder(spec);

assertThatThrownBy(
() ->
OpenApiServer.builder()
.spec(spec)
.handlers(Map.of("getX", req -> Response.ok(Map.of())))
.port(0)
.build())
assertThatThrownBy(builder::build)
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("unsupported");
}
Expand All @@ -91,18 +81,20 @@ void unknownSchemeReferenceThrows() {
List.of(),
List.of(Map.of("missingScheme", List.of())));
Spec spec = Spec.from(r);
OpenApiServer.Builder builder = handlerBuilder(spec);

assertThatThrownBy(
() ->
OpenApiServer.builder()
.spec(spec)
.handlers(Map.of("getX", req -> Response.ok(Map.of())))
.port(0)
.build())
assertThatThrownBy(builder::build)
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("missingScheme");
}

private static OpenApiServer.Builder handlerBuilder(Spec spec) {
return OpenApiServer.builder()
.spec(spec)
.handlers(Map.of("getX", req -> Response.ok(Map.of())))
.port(0);
}

@Test
void externalAuthSkipsAllChecks() throws Exception {
Map<String, Object> r =
Expand Down
Loading