Skip to content

Commit

Permalink
Fix e2e tests failing to get API keys
Browse files Browse the repository at this point in the history
As of DependencyTrack/hyades-apiserver#725, API keys are no longer created automatically when creating teams.

Adds a request to explicitly create a key.

Signed-off-by: nscuro <[email protected]>
  • Loading branch information
nscuro committed Jun 14, 2024
1 parent 17b7de7 commit 57b2dd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import org.dependencytrack.apiserver.model.Analysis;
import org.dependencytrack.apiserver.model.ApiKey;
import org.dependencytrack.apiserver.model.BomProcessingResponse;
import org.dependencytrack.apiserver.model.BomUploadRequest;
import org.dependencytrack.apiserver.model.ConfigProperty;
Expand Down Expand Up @@ -74,6 +75,12 @@ String login(@FormParam("username") final String username,
@Consumes(MediaType.APPLICATION_JSON)
Team createTeam(final CreateTeamRequest request);

@PUT
@Path("/team/{uuid}/key")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.WILDCARD)
ApiKey createApiKey(@PathParam("uuid") final UUID teamUuid);

@POST
@Path("/permission/{permission}/team/{uuid}")
@Produces(MediaType.WILDCARD)
Expand Down
6 changes: 5 additions & 1 deletion e2e/src/test/java/org/dependencytrack/e2e/AbstractE2ET.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.dependencytrack.apiserver.ApiServerClient;
import org.dependencytrack.apiserver.CompositeDecoder;
import org.dependencytrack.apiserver.CompositeEncoder;
import org.dependencytrack.apiserver.model.ApiKey;
import org.dependencytrack.apiserver.model.CreateTeamRequest;
import org.dependencytrack.apiserver.model.Team;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -286,6 +287,9 @@ private ApiServerClient initializeApiServerClient() {
logger.info("Creating e2e team");
final Team team = client.createTeam(new CreateTeamRequest("e2e"));

logger.info("Creating API key for e2e team");
final ApiKey apiKey = client.createApiKey(team.uuid());

// TODO: Should assigned permissions be configurable per test case?
logger.info("Assigning permissions to e2e team");
for (final String permission : Set.of(
Expand All @@ -302,7 +306,7 @@ private ApiServerClient initializeApiServerClient() {
}

logger.info("Authenticating as e2e team");
ApiServerAuthInterceptor.setApiKey(team.apiKeys().getFirst().key());
ApiServerAuthInterceptor.setApiKey(apiKey.key());

return client;
}
Expand Down

0 comments on commit 57b2dd4

Please sign in to comment.