Skip to content
Draft
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 @@ -345,8 +345,9 @@ public CompletableFuture<AnsConnection> connectAsync(String serverUrl) {
.exceptionally(e -> {
Throwable cause = e instanceof CompletionException && e.getCause() != null
? e.getCause() : e;
LOGGER.warn("SCITT preflight failed: {}", cause.getMessage());
return ScittPreVerifyResult.parseError("Preflight failed: " + cause.getMessage());
String detail = describe(cause);
LOGGER.warn("SCITT preflight to {}:{} failed: {}", hostname, port, detail, cause);
return ScittPreVerifyResult.parseError("Preflight failed: " + detail);
});
} else {
scittFuture = CompletableFuture.completedFuture(ScittPreVerifyResult.notPresent());
Expand Down Expand Up @@ -390,6 +391,15 @@ public void clearCapturedCertificates(String host) {
});
}

/**
* Renders a throwable for diagnostics. Many TLS/IO exceptions carry a null message, which
* would otherwise surface as "null" and hide the failing class. Falls back to the class name.
*/
private static String describe(Throwable t) {
String message = t.getMessage();
return message != null ? t.getClass().getName() + ": " + message : t.getClass().getName();
}

private void assertScittResult(ScittPreVerifyResult scittPreResult, boolean scittVerified) {
// Reject invalid SCITT headers regardless of mode (prevents garbage header attacks)
if (policy.rejectsInvalidScittHeaders() && scittPreResult.isPresent() && !scittVerified) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ public Builder enableRetry(int maxRetries) {
* @throws NullPointerException if required fields are not set
*/
public AnsConfiguration build() {
if (this.environment == null) {
throw new IllegalStateException("Environment is required");
if (this.environment == null && this.baseUrl == null) {
throw new IllegalStateException("Either an environment or a base URL is required");
}
return new AnsConfiguration(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,25 @@ void shouldThrowExceptionWhenCredentialsProviderIsNull() {
}

@Test
@DisplayName("Should throw when environment is not set")
void shouldThrowWhenEnvironmentNotSet() {
@DisplayName("Should throw when neither environment nor base URL is set")
void shouldThrowWhenEnvironmentAndBaseUrlNotSet() {
assertThatThrownBy(() -> AnsConfiguration.builder()
.credentialsProvider(testProvider)
.build())
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Environment is required");
.hasMessageContaining("environment or a base URL");
}

@Test
@DisplayName("Should allow custom base URL without an environment")
void shouldAllowBaseUrlWithoutEnvironment() {
AnsConfiguration config = AnsConfiguration.builder()
.baseUrl("http://localhost:18080")
.credentialsProvider(testProvider)
.build();

assertThat(config.getBaseUrl()).isEqualTo("http://localhost:18080");
assertThat(config.getEnvironment()).isNull();
}

@Test
Expand Down
Loading