1818
1919import static org .assertj .core .api .Assertions .assertThat ;
2020
21+ import com .fasterxml .jackson .core .JsonProcessingException ;
22+ import com .fasterxml .jackson .databind .ObjectMapper ;
2123import java .time .Duration ;
2224import java .util .function .Consumer ;
2325import org .cloudfoundry .AbstractIntegrationTest ;
26+ import org .cloudfoundry .reactor .ConnectionContext ;
2427import org .cloudfoundry .uaa .serverinformation .AutoLoginRequest ;
2528import org .cloudfoundry .uaa .serverinformation .GetAutoLoginAuthenticationCodeRequest ;
2629import org .cloudfoundry .uaa .serverinformation .GetAutoLoginAuthenticationCodeResponse ;
2730import org .cloudfoundry .uaa .serverinformation .GetInfoRequest ;
2831import org .junit .jupiter .api .Test ;
32+ import org .junit .jupiter .api .condition .DisabledIf ;
2933import org .springframework .beans .factory .annotation .Autowired ;
34+ import org .springframework .http .converter .json .Jackson2ObjectMapperBuilder ;
3035import reactor .core .publisher .Mono ;
3136import reactor .test .StepVerifier ;
3237
@@ -42,6 +47,8 @@ public final class ServerInformationTest extends AbstractIntegrationTest {
4247
4348 @ Autowired private String username ;
4449
50+ @ Autowired private ConnectionContext context ;
51+
4552 @ Test
4653 public void autoLogin () {
4754 getAuthenticationCode (
@@ -83,6 +90,7 @@ public void getAutoLoginAuthenticationCode() {
8390 }
8491
8592 @ Test
93+ @ DisabledIf (value = "tasSpecificUaaVersion" )
8694 public void getInfo () {
8795 this .uaaClient
8896 .serverInformation ()
@@ -124,4 +132,46 @@ private static Mono<GetAutoLoginAuthenticationCodeResponse> requestAuthenticatio
124132 .username (username )
125133 .build ());
126134 }
135+
136+ /**
137+ * TAS has a specific line of UAA releases 77.20.x, where x >= 8.
138+ * The latest OSS release of that line is <a href="https://github.com/cloudfoundry/uaa/releases/v77.20.7">v77.20.7</a>.
139+ * In those proprietary releases, the UAA info response has extra properties and crashes some tests.
140+ * We do not want to include those extra fields into the OSS releases of CF-java-client. To have our
141+ * integration tests succeed, we exclude these specific UAA releases.
142+ */
143+ private boolean tasSpecificUaaVersion () {
144+ ObjectMapper mapper = Jackson2ObjectMapperBuilder .json ().build ();
145+
146+ Boolean hasTasSpecificUaaVersion =
147+ context .getRootProvider ()
148+ .getRoot ("uaa" , context )
149+ .map (url -> context .getHttpClient ().baseUrl (url ))
150+ .flatMap (
151+ client ->
152+ client .get ()
153+ .uri ("/info" )
154+ .responseContent ()
155+ .aggregate ()
156+ .asString ())
157+ .map (
158+ r -> {
159+ try {
160+ return mapper .readTree (r ).at ("/app/version" ).asText ();
161+ } catch (JsonProcessingException e ) {
162+ throw new RuntimeException ("Can't parse" );
163+ }
164+ })
165+ .map (
166+ version -> {
167+ String [] versionParts = version .split ("\\ ." );
168+ int major = Integer .parseInt (versionParts [0 ]);
169+ int minor = Integer .parseInt (versionParts [1 ]);
170+ int patch = Integer .parseInt (versionParts [2 ]);
171+ return major == 77 && minor == 20 && patch > 8 ;
172+ })
173+ .onErrorReturn (false )
174+ .block ();
175+ return Boolean .TRUE .equals (hasTasSpecificUaaVersion );
176+ }
127177}
0 commit comments