Skip to content

Commit

Permalink
Fetch and provide auth header when uploading model JAR
Browse files Browse the repository at this point in the history
The Gateway has been updated to (correctly) validate that the user has an active, valid session when hitting restricted endpoints. As a consequence, the E2E tests now provide an `Authorization` header when uploading mission model JARs
  • Loading branch information
Mythicaeda committed Jun 27, 2024
1 parent 2b8a594 commit 75a2615
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,38 @@

public class GatewayRequests implements AutoCloseable {
private final APIRequestContext request;
private static String token;

public GatewayRequests(Playwright playwright) {
public GatewayRequests(Playwright playwright) throws IOException {
request = playwright.request().newContext(
new APIRequest.NewContextOptions()
.setBaseURL(BaseURL.GATEWAY.url));
login();
}

private void login() throws IOException {
if(token != null) return;
final var response = request.post("/auth/login", RequestOptions.create()
.setHeader("Content-Type", "application/json")
.setData(Json.createObjectBuilder()
.add("username", "AerieE2eTests")
.add("password", "password")
.build()
.toString()));
// Process Response
if(!response.ok()){
throw new IOException(response.statusText());
}
try(final var reader = Json.createReader(new StringReader(response.text()))){
final JsonObject bodyJson = reader.readObject();
if(!bodyJson.getBoolean("success")){
System.err.println("Login failed");
throw new RuntimeException(bodyJson.toString());
}
token = bodyJson.getString("token");
}
}

@Override
public void close() {
request.dispose();
Expand Down Expand Up @@ -54,7 +80,9 @@ public int uploadJarFile(String jarPath) throws IOException {
"application/java-archive",
buffer);

final var response = request.post("/file", RequestOptions.create().setMultipart(FormData.create().set("file", payload)));
final var response = request.post("/file", RequestOptions.create()
.setHeader("Authorization", "Bearer "+token)
.setMultipart(FormData.create().set("file", payload)));

// Process Response
if(!response.ok()){
Expand All @@ -69,5 +97,4 @@ public int uploadJarFile(String jarPath) throws IOException {
return bodyJson.getInt("id");
}
}

}

0 comments on commit 75a2615

Please sign in to comment.