Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/main/java/io/seqera/tower/cli/commands/AbstractApiCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import io.seqera.tower.ApiClient;
import io.seqera.tower.ApiException;
import io.seqera.tower.ApiResponse;
import io.seqera.tower.Pair;
import io.seqera.tower.api.ActionsApi;
import io.seqera.tower.api.AvatarsApi;
import io.seqera.tower.api.ComputeEnvsApi;
Expand Down Expand Up @@ -78,6 +80,7 @@
import picocli.CommandLine;

import javax.ws.rs.client.Entity;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import java.io.IOException;
import java.net.URLConnection;
Expand Down Expand Up @@ -318,6 +321,17 @@ public ClientConfig getDefaultClientConfig() {
return config;
}

@Override
public <T> ApiResponse<T> invokeAPI(String operation, String path, String method, List<Pair> queryParams, Object body, Map<String, String> headerParams, Map<String, String> cookieParams, Map<String, Object> formParams, String accept, String contentType, String[] authNames, GenericType<T> returnType, boolean isBodyNullable) throws ApiException {
// Some operations are missing their security requirement in the OpenAPI spec (e.g. the workflow
// star endpoints), so the generated SDK passes no auth names and skips authentication entirely,
// sending the request unauthenticated. Fall back to the only scheme this client uses.
if (authNames == null || authNames.length == 0) {
authNames = new String[]{"BearerAuth"};
}
return super.invokeAPI(operation, path, method, queryParams, body, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType, isBodyNullable);
}

@Override
protected void applyDebugSetting(ClientConfig clientConfig) {
if (app().verbose) {
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/io/seqera/tower/cli/runs/RunsCmdTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,34 @@ void testUnstarNotStarred(MockServerClient mock) {
assertEquals(1, out.exitCode);
}

@Test
void testStarSendsAuthorization(MockServerClient mock) {
mock.when(
request().withMethod("POST").withPath("/workflow/5dAZoXrcmZXRO4/star"), exactly(1)
).respond(
response().withStatusCode(200).withBody("{\"workflowId\":\"5dAZoXrcmZXRO4\"}").withContentType(MediaType.APPLICATION_JSON)
);

exec(mock, "runs", "star", "-i", "5dAZoXrcmZXRO4");

mock.verify(request().withMethod("POST").withPath("/workflow/5dAZoXrcmZXRO4/star")
.withHeader("Authorization", "Bearer " + token()), VerificationTimes.atLeast(1));
}

@Test
void testUnstarSendsAuthorization(MockServerClient mock) {
mock.when(
request().withMethod("DELETE").withPath("/workflow/5dAZoXrcmZXRO4/star"), exactly(1)
).respond(
response().withStatusCode(204)
);

exec(mock, "runs", "unstar", "-i", "5dAZoXrcmZXRO4");

mock.verify(request().withMethod("DELETE").withPath("/workflow/5dAZoXrcmZXRO4/star")
.withHeader("Authorization", "Bearer " + token()), VerificationTimes.atLeast(1));
}

@Test
void testCancelForbidden(MockServerClient mock) {
mock.when(
Expand Down
Loading