-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix Discovery Eureka response if the service is not registred to…
… allow reconnect by Enabler (#3795) --------- Signed-off-by: Pavel Jareš <[email protected]> Signed-off-by: Pablo Hernán Carle <[email protected]> Co-authored-by: Pablo Carle <[email protected]> Co-authored-by: Pablo Hernán Carle <[email protected]>
- Loading branch information
1 parent
13f89ff
commit 9f58010
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...overy-service/src/main/java/org/zowe/apiml/discovery/config/DiscoveryErrorController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.discovery.config; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.springframework.boot.autoconfigure.web.ServerProperties; | ||
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController; | ||
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver; | ||
import org.springframework.boot.web.servlet.error.ErrorAttributes; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Primary | ||
@Controller | ||
@RequestMapping(value = "${server.error.path:${error.path:/error}}") | ||
public class DiscoveryErrorController extends BasicErrorController { | ||
|
||
public DiscoveryErrorController(ErrorAttributes errorAttributes, ServerProperties serverProperties, List<ErrorViewResolver> errorViewResolvers) { | ||
super(errorAttributes, serverProperties.getError(), errorViewResolvers); | ||
} | ||
|
||
@Override | ||
@RequestMapping // NOSONAR - No security risk, the controller cleans body for specified endpoint patterns | ||
public ResponseEntity<Map<String, Object>> error(HttpServletRequest request) { | ||
HttpStatus status = getStatus(request); | ||
String originalUrl = String.valueOf(request.getAttribute("jakarta.servlet.error.request_uri")); | ||
if ((status == HttpStatus.NOT_FOUND) && StringUtils.startsWith(originalUrl, "/eureka/apps/")) { | ||
return new ResponseEntity<>(status); | ||
} | ||
return super.error(request); | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
discovery-service/src/test/java/org/zowe/apiml/discovery/eureka/EurekaEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.discovery.eureka; | ||
|
||
import io.restassured.http.ContentType; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.TestInstance.Lifecycle; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.zowe.apiml.discovery.functional.DiscoveryFunctionalTest; | ||
import org.zowe.apiml.util.config.SslContext; | ||
import org.zowe.apiml.util.config.SslContextConfigurer; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.core.IsEqual.equalTo; | ||
|
||
@ActiveProfiles("https") | ||
@TestInstance(Lifecycle.PER_CLASS) | ||
public class EurekaEndpointTest extends DiscoveryFunctionalTest { | ||
|
||
@Value("${server.ssl.keyPassword}") | ||
char[] password; | ||
@Value("${server.ssl.keyStore}") | ||
String client_cert_keystore; | ||
@Value("${server.ssl.keyStore}") | ||
String keystore; | ||
|
||
@BeforeEach | ||
void setup() throws Exception { | ||
SslContextConfigurer configurer = new SslContextConfigurer(password, client_cert_keystore, keystore); | ||
SslContext.prepareSslAuthentication(configurer); | ||
} | ||
|
||
@BeforeAll | ||
void init() { | ||
SslContext.reset(); | ||
} | ||
|
||
@AfterAll | ||
void tearDown() { | ||
SslContext.reset(); | ||
} | ||
|
||
@Override | ||
protected String getProtocol() { | ||
return "https"; | ||
} | ||
|
||
@Test | ||
void givenInvalidService_whenRenewInstance_thenReturnEmptyBody() { | ||
given() | ||
.config(SslContext.clientCertApiml) | ||
.contentType(ContentType.JSON) | ||
.log().all() | ||
.when() | ||
.put(getDiscoveryUriWithPath("/eureka/apps/unknown-service-id/unknown-instance-id")) | ||
.then() | ||
.statusCode(HttpStatus.NOT_FOUND.value()) | ||
.body(equalTo("")); | ||
} | ||
|
||
} |