-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Handle Docker 407 (Proxy Authentication Required) with clear error message #47180
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
base: 3.3.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2012-2025 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.actuate.autoconfigure.metrics.cache; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.actuate.metrics.cache.JCacheCacheMeterBinderProvider; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class JCacheCacheMeterBinderProviderBackOffTests { | ||
|
||
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() | ||
.withConfiguration(AutoConfigurations.of(CacheMetricsAutoConfiguration.class)); | ||
|
||
@Test | ||
void backsOffWhenUserProvidesProvider() { | ||
JCacheCacheMeterBinderProvider custom = new JCacheCacheMeterBinderProvider(); | ||
this.contextRunner.withBean(JCacheCacheMeterBinderProvider.class, () -> custom).run((context) -> { | ||
var bean = context.getBean(JCacheCacheMeterBinderProvider.class); | ||
assertThat(bean).isSameAs(custom); | ||
}); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,14 +146,35 @@ private Response execute(HttpUriRequest request) { | |
try { | ||
ClassicHttpResponse response = this.client.executeOpen(this.host, request, null); | ||
int statusCode = response.getCode(); | ||
|
||
if (statusCode >= 400 && statusCode <= 500) { | ||
byte[] content = readContent(response); | ||
response.close(); | ||
|
||
if (statusCode == 407) { | ||
response.close(); | ||
|
||
String detail = null; | ||
Message json = deserializeMessage(content); | ||
if (json != null && org.springframework.util.StringUtils.hasText(json.getMessage())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
detail = json.getMessage(); | ||
} | ||
else { | ||
detail = new String(content, java.nio.charset.StandardCharsets.UTF_8); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
String msg = "Proxy authentication required for host: " + this.host.toHostString() + ", uri: " | ||
+ request.getUri() | ||
+ (org.springframework.util.StringUtils.hasText(detail) ? " - " + detail : ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
throw new ProxyAuthenticationException(msg); | ||
} | ||
|
||
Errors errors = (statusCode != 500) ? deserializeErrors(content) : null; | ||
Message message = deserializeMessage(content); | ||
throw new DockerEngineException(this.host.toHostString(), request.getUri(), statusCode, | ||
response.getReasonPhrase(), errors, message); | ||
} | ||
|
||
return new HttpClientResponse(response); | ||
} | ||
catch (IOException | URISyntaxException ex) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2012-2025 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.buildpack.platform.docker.transport; | ||
|
||
public class ProxyAuthenticationException extends RuntimeException { | ||
|
||
public ProxyAuthenticationException(String message) { | ||
super(message); | ||
} | ||
|
||
public ProxyAuthenticationException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2012-2025 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.buildpack.platform.docker.transport; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class ProxyAuthenticationExceptionTests { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need tests for |
||
|
||
@Test | ||
void constructsWithMessage() { | ||
ProxyAuthenticationException ex = new ProxyAuthenticationException("Proxy auth failed"); | ||
assertThat(ex.getMessage()).isEqualTo("Proxy auth failed"); | ||
} | ||
|
||
@Test | ||
void constructsWithMessageAndCause() { | ||
Exception cause = new Exception("boom"); | ||
ProxyAuthenticationException ex = new ProxyAuthenticationException("Proxy auth failed", cause); | ||
assertThat(ex.getCause()).isSameAs(cause); | ||
assertThat(ex.getMessage()).isEqualTo("Proxy auth failed"); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong to me as the response will now only be closed when the status code is 407.