Skip to content

Commit e35de47

Browse files
committed
Fix: wrong key used to access log-cache root endpoint
1 parent 0e3d9ab commit e35de47

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/logcache/v1/_ReactorLogCacheClient.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.cloudfoundry.logcache.v1.ReadRequest;
2525
import org.cloudfoundry.logcache.v1.ReadResponse;
2626
import org.cloudfoundry.reactor.ConnectionContext;
27+
import org.cloudfoundry.reactor.RootProvider;
2728
import org.cloudfoundry.reactor.TokenProvider;
2829
import org.immutables.value.Value;
2930
import reactor.core.publisher.Mono;
@@ -70,7 +71,7 @@ Map<String, String> getRequestTags() {
7071

7172
@Value.Default
7273
Mono<String> getRoot() {
73-
final Mono<String> cached = getConnectionContext().getRootProvider().getRoot("log-cache", getConnectionContext())
74+
final Mono<String> cached = getConnectionContext().getRootProvider().getRoot("log_cache", getConnectionContext())
7475
.onErrorResume(IllegalArgumentException.class, e -> deriveLogCacheUrl());
7576

7677
return getConnectionContext().getCacheDuration()

cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/logcache/v1/ReactorLogCacheClientTest.java

+70-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2021 the original author or authors.
2+
* Copyright 2013-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,7 +18,14 @@
1818

1919
import static io.netty.handler.codec.http.HttpMethod.GET;
2020
import static io.netty.handler.codec.http.HttpResponseStatus.OK;
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
import static org.mockito.ArgumentMatchers.any;
23+
import static org.mockito.ArgumentMatchers.eq;
24+
import static org.mockito.Mockito.mock;
25+
import static org.mockito.Mockito.when;
2126

27+
import java.io.IOException;
28+
import java.net.URI;
2229
import java.time.Duration;
2330
import java.util.Collections;
2431
import org.cloudfoundry.logcache.v1.Envelope;
@@ -34,18 +41,80 @@
3441
import org.cloudfoundry.logcache.v1.Metric;
3542
import org.cloudfoundry.logcache.v1.ReadRequest;
3643
import org.cloudfoundry.logcache.v1.ReadResponse;
44+
import org.cloudfoundry.reactor.ConnectionContext;
45+
import org.cloudfoundry.reactor.DefaultConnectionContext;
3746
import org.cloudfoundry.reactor.InteractionContext;
47+
import org.cloudfoundry.reactor.RootProvider;
3848
import org.cloudfoundry.reactor.TestRequest;
3949
import org.cloudfoundry.reactor.TestResponse;
4050
import org.junit.jupiter.api.Test;
51+
import reactor.core.publisher.Mono;
4152
import reactor.test.StepVerifier;
4253

4354
class ReactorLogCacheClientTest extends AbstractLogCacheApiTest {
55+
private static final String API_ROOT = "http://api.my.rapid.server.com";
56+
private static final String LOGCACHE = "http://log-cache.my.rlog-cached.server.com";
4457

4558
private final ReactorLogCacheEndpoints logCacheEndpoints =
4659
new ReactorLogCacheEndpoints(
4760
CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER, Collections.emptyMap());
4861

62+
@Test
63+
void getRootFromFallback() throws IOException {
64+
URI webServerUri = URI.create(this.root.block(Duration.ofSeconds(5)));
65+
Mono<String> apiRoot = Mono.just(API_ROOT);
66+
RootProvider rootProvider = mock(RootProvider.class);
67+
when(rootProvider.getRoot(eq("log_cache"), any()))
68+
.thenReturn(Mono.error(new IllegalArgumentException())); // trigger fallback
69+
when(rootProvider.getRoot(any())).thenReturn(apiRoot);
70+
ConnectionContext connectionContext =
71+
DefaultConnectionContext.builder()
72+
.rootProvider(rootProvider)
73+
.apiHost(webServerUri.getHost())
74+
.port(webServerUri.getPort())
75+
.secure(false)
76+
.build();
77+
ReactorLogCacheClient examinee =
78+
ReactorLogCacheClient.builder()
79+
.connectionContext(connectionContext)
80+
.tokenProvider(TOKEN_PROVIDER)
81+
.build();
82+
Mono<String> logCacheRoot = examinee.getRoot();
83+
String rootString = logCacheRoot.block(Duration.ofSeconds(15));
84+
assertThat(rootString).isEqualTo(LOGCACHE);
85+
}
86+
87+
@Test
88+
void getRootFromEndpoint() {
89+
mockRequest(
90+
InteractionContext.builder()
91+
.request(TestRequest.builder().method(GET).path("/").build())
92+
.response(
93+
TestResponse.builder()
94+
.status(OK)
95+
.payload("fixtures/GET_response.json")
96+
.build())
97+
.build());
98+
URI webServerUri = URI.create(this.root.block(Duration.ofSeconds(5)));
99+
ConnectionContext connectionContext =
100+
DefaultConnectionContext.builder()
101+
.apiHost(webServerUri.getHost())
102+
.port(webServerUri.getPort())
103+
.secure(false)
104+
.build();
105+
ReactorLogCacheClient examinee =
106+
ReactorLogCacheClient.builder()
107+
.connectionContext(connectionContext)
108+
.tokenProvider(TOKEN_PROVIDER)
109+
.build();
110+
Mono<String> logCacheRoot = examinee.getRoot();
111+
String rootString = logCacheRoot.block(Duration.ofSeconds(5));
112+
assertThat(rootString)
113+
.isEqualTo(
114+
"http://cache-for-logging.cf.lod-cfcli3.cfrt-sof.sapcloud.io:"
115+
+ webServerUri.getPort());
116+
}
117+
49118
@Test
50119
void info() {
51120
mockRequest(

cloudfoundry-client-reactor/src/test/resources/fixtures/GET_response.json

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
"uaa": {
2626
"href": "https://uaa.run.pivotal.io"
2727
},
28+
"log_cache": {
29+
"href": "https://cache-for-logging.cf.lod-cfcli3.cfrt-sof.sapcloud.io"
30+
},
2831
"logging": {
2932
"href": "wss://doppler.run.pivotal.io:443"
3033
}

0 commit comments

Comments
 (0)