Skip to content

Commit

Permalink
Improve DataflowOAuthIT with check on /about
Browse files Browse the repository at this point in the history
Adds a negative test to DataflowOAuthIT to ensure /about cannot be accessed without credentials.
  • Loading branch information
corneil authored Nov 6, 2024
1 parent 0b7db9c commit f923d87
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.util.StringUtils;

import static org.awaitility.Awaitility.with;
import static org.assertj.core.api.Assertions.assertThat;

@Oauth
@ActiveProfiles({TagNames.PROFILE_OAUTH})
Expand Down Expand Up @@ -58,23 +59,31 @@ void securedSetup() throws Exception {
.await()
.ignoreExceptions()
.atMost(90, TimeUnit.SECONDS)
.until(() -> {
log.debug("Checking auth using curl");
.untilAsserted(() -> {
log.info("Checking auth using curl");
ExecResult cmdResult = execInToolsContainer("curl", "-v", "-u", "janne:janne", "http://dataflow:9393/about");
String response = cmdResult.getStdout();
if (StringUtils.hasText(response)) {
log.debug("Response is {}", response);
log.info("Response is {}", response);
}
boolean ok = response.contains("\"authenticated\":true") && response.contains("\"username\":\"janne\"");
log.info("Check for oauth {}", ok);
if (!ok) {
stderr.set(cmdResult.getStderr());
}
else {
stderr.set("");
}
return ok;
stderr.set(cmdResult.getStderr());
assertThat(response).contains("\"authenticated\":true");
assertThat(response).contains("\"username\":\"janne\"");
stderr.set("");
});
log.info("Checking without credentials using curl");
ExecResult cmdResult = execInToolsContainer("curl", "-v", "-f", "http://dataflow:9393/about");
String response = cmdResult.getStdout();
if (StringUtils.hasText(response)) {
log.info("Response is {}", response);
}
response = cmdResult.getStderr();
if(StringUtils.hasText(response)) {
log.warn("Error is {}", response);
}
stderr.set(cmdResult.getStderr());
assertThat(cmdResult.getExitCode()).isNotZero();
stderr.set("");
}
finally {
String msg = stderr.get();
Expand Down

0 comments on commit f923d87

Please sign in to comment.