Skip to content

Commit

Permalink
Fixed deprecations for createTeam
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Schauer-Koeckeis <thomas.schauer-koeckeis@rohde-schwarz.com>
  • Loading branch information
Gepardgame committed Feb 3, 2025
1 parent 14f6f5a commit eff4bff
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ private void loadDefaultPersonas() {
new String(PasswordService.createHash("admin".toCharArray())), true, true, false);

LOGGER.debug("Creating team: Administrators");
final Team sysadmins = qm.createTeam("Administrators", false);
final Team sysadmins = qm.createTeam("Administrators");
LOGGER.debug("Creating team: Portfolio Managers");
final Team managers = qm.createTeam("Portfolio Managers", false);
final Team managers = qm.createTeam("Portfolio Managers");
LOGGER.debug("Creating team: Automation");
final Team automation = qm.createTeam("Automation", true);
final Team automation = qm.createTeam("Automation");
LOGGER.debug("Creating team: Badge Viewers");
final Team badges = qm.createTeam("Badge Viewers", true);
final Team badges = qm.createTeam("Badge Viewers");

final List<Permission> fullList = qm.getPermissions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public Response createTeam(Team jsonTeam) {
);

try (QueryManager qm = new QueryManager()) {
final Team team = qm.createTeam(jsonTeam.getName(), false);
final Team team = qm.createTeam(jsonTeam.getName());
super.logSecurityEvent(LOGGER, SecurityMarkers.SECURITY_AUDIT, "Team created: " + team.getName());
return Response.status(Response.Status.CREATED).entity(team).build();
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/dependencytrack/ResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public static void init() {
public void before() throws Exception {
// Add a test user and team with API key. Optional if this is used, but its available to all tests.
this.qm = new QueryManager();
team = qm.createTeam("Test Users", true);
this.apiKey = team.getApiKeys().get(0).getKey();
team = qm.createTeam("Test Users");
this.apiKey = qm.createApiKey(team).getKey();
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import alpine.Config;
import alpine.model.About;
import alpine.model.ApiKey;
import alpine.model.ConfigProperty;
import alpine.model.Team;
import alpine.server.filters.ApiFilter;
Expand Down Expand Up @@ -414,7 +415,8 @@ public void getAllFindingsWithAclEnabled() {
Project p1 = qm.createProject("Acme Example", null, "1.0", null, null, null, true, false);
Project p1_child = qm.createProject("Acme Example", null, "1.0", null, p1, null, true, false);
Project p2 = qm.createProject("Acme Example", null, "1.0", null, null, null, true, false);
Team team = qm.createTeam("Team Acme", true);
Team team = qm.createTeam("Team Acme");
ApiKey apiKey = qm.createApiKey(team);
p1.addAccessTeam(team);
Component c1 = createComponent(p1, "Component A", "1.0");
Component c2 = createComponent(p1, "Component B", "1.0");
Expand Down Expand Up @@ -444,7 +446,7 @@ public void getAllFindingsWithAclEnabled() {
qm.persist(aclToggle);
}
Response response = jersey.target(V1_FINDING).request()
.header(X_API_KEY, team.getApiKeys().get(0).getKey())
.header(X_API_KEY, apiKey.getKey())
.get(Response.class);
Assert.assertEquals(200, response.getStatus(), 0);
Assert.assertEquals(String.valueOf(3), response.getHeaderString(TOTAL_COUNT_HEADER));
Expand Down Expand Up @@ -546,7 +548,8 @@ public void getAllFindingsGroupedByVulnerabilityWithAclEnabled() {
Project p1 = qm.createProject("Acme Example", null, "1.0", null, null, null, true, false);
Project p1_child = qm.createProject("Acme Example", null, "1.0", null, p1, null, true, false);
Project p2 = qm.createProject("Acme Example", null, "1.0", null, null, null, true, false);
Team team = qm.createTeam("Team Acme", true);
Team team = qm.createTeam("Team Acme");
ApiKey apiKey = qm.createApiKey(team);
p1.addAccessTeam(team);
Component c1 = createComponent(p1, "Component A", "1.0");
Component c2 = createComponent(p1, "Component B", "1.0");
Expand Down Expand Up @@ -578,7 +581,7 @@ public void getAllFindingsGroupedByVulnerabilityWithAclEnabled() {
qm.persist(aclToggle);
}
Response response = jersey.target(V1_FINDING + "/grouped").request()
.header(X_API_KEY, team.getApiKeys().get(0).getKey())
.header(X_API_KEY, apiKey.getKey())
.get(Response.class);
Assert.assertEquals(200, response.getStatus(), 0);
Assert.assertEquals(String.valueOf(3), response.getHeaderString(TOTAL_COUNT_HEADER));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public void removeProjectFromRuleDuplicateProjectTest() {

@Test
public void addTeamToRuleTest(){
Team team = qm.createTeam("Team Example", false);
Team team = qm.createTeam("Team Example");
NotificationPublisher publisher = qm.getNotificationPublisher(DefaultNotificationPublishers.EMAIL.getPublisherName());
NotificationRule rule = qm.createNotificationRule("Example Rule", NotificationScope.PORTFOLIO, NotificationLevel.INFORMATIONAL, publisher);
Response response = jersey.target(V1_NOTIFICATION_RULE + "/" + rule.getUuid().toString() + "/team/" + team.getUuid().toString()).request()
Expand All @@ -454,7 +454,7 @@ public void addTeamToRuleTest(){

@Test
public void addTeamToRuleInvalidRuleTest(){
Team team = qm.createTeam("Team Example", false);
Team team = qm.createTeam("Team Example");
NotificationPublisher publisher = qm.getNotificationPublisher(DefaultNotificationPublishers.EMAIL.getPublisherName());
Response response = jersey.target(V1_NOTIFICATION_RULE + "/" + UUID.randomUUID().toString() + "/team/" + team.getUuid().toString()).request()
.header(X_API_KEY, apiKey)
Expand All @@ -480,7 +480,7 @@ public void addTeamToRuleInvalidTeamTest() {

@Test
public void addTeamToRuleDuplicateTeamTest() {
Team team = qm.createTeam("Team Example", false);
Team team = qm.createTeam("Team Example");
NotificationPublisher publisher = qm.getNotificationPublisher(DefaultNotificationPublishers.EMAIL.getPublisherName());
NotificationRule rule = qm.createNotificationRule("Example Rule", NotificationScope.PORTFOLIO, NotificationLevel.INFORMATIONAL, publisher);
List<Team> teams = new ArrayList<>();
Expand All @@ -496,7 +496,7 @@ public void addTeamToRuleDuplicateTeamTest() {

@Test
public void addTeamToRuleInvalidPublisherTest(){
Team team = qm.createTeam("Team Example", false);
Team team = qm.createTeam("Team Example");
NotificationPublisher publisher = qm.getNotificationPublisher(DefaultNotificationPublishers.SLACK.getPublisherName());
NotificationRule rule = qm.createNotificationRule("Example Rule", NotificationScope.PORTFOLIO, NotificationLevel.INFORMATIONAL, publisher);
Response response = jersey.target(V1_NOTIFICATION_RULE + "/" + rule.getUuid().toString() + "/team/" + team.getUuid().toString()).request()
Expand All @@ -510,7 +510,7 @@ public void addTeamToRuleInvalidPublisherTest(){

@Test
public void addTeamToRuleWithCustomEmailPublisherTest() {
final Team team = qm.createTeam("Team Example", false);
final Team team = qm.createTeam("Team Example");
final NotificationPublisher publisher = qm.createNotificationPublisher("foo", "description", SendMailPublisher.class, "template", "templateMimeType", false);
final NotificationRule rule = qm.createNotificationRule("Example Rule", NotificationScope.PORTFOLIO, NotificationLevel.INFORMATIONAL, publisher);
final Response response = jersey.target(V1_NOTIFICATION_RULE + "/" + rule.getUuid() + "/team/" + team.getUuid()).request()
Expand Down Expand Up @@ -554,7 +554,7 @@ public void addTeamToRuleWithCustomEmailPublisherTest() {

@Test
public void removeTeamFromRuleTest() {
Team team = qm.createTeam("Team Example", false);
Team team = qm.createTeam("Team Example");
NotificationPublisher publisher = qm.getNotificationPublisher(DefaultNotificationPublishers.EMAIL.getPublisherName());
NotificationRule rule = qm.createNotificationRule("Example Rule", NotificationScope.PORTFOLIO, NotificationLevel.INFORMATIONAL, publisher);
List<Team> teams = new ArrayList<>();
Expand All @@ -570,7 +570,7 @@ public void removeTeamFromRuleTest() {

@Test
public void removeTeamFromRuleInvalidRuleTest() {
Team team = qm.createTeam("Team Example", false);
Team team = qm.createTeam("Team Example");
NotificationPublisher publisher = qm.getNotificationPublisher(DefaultNotificationPublishers.EMAIL.getPublisherName());
Response response = jersey.target(V1_NOTIFICATION_RULE + "/" + UUID.randomUUID().toString() + "/team/" + team.getUuid().toString()).request()
.header(X_API_KEY, apiKey)
Expand All @@ -596,7 +596,7 @@ public void removeTeamFromRuleInvalidTeamTest() {

@Test
public void removeTeamFromRuleDuplicateTeamTest() {
Team team = qm.createTeam("Team Example", false);
Team team = qm.createTeam("Team Example");
NotificationPublisher publisher = qm.getNotificationPublisher(DefaultNotificationPublishers.EMAIL.getPublisherName());
NotificationRule rule = qm.createNotificationRule("Example Rule", NotificationScope.PORTFOLIO, NotificationLevel.INFORMATIONAL, publisher);
Response response = jersey.target(V1_NOTIFICATION_RULE + "/" + rule.getUuid().toString() + "/team/" + team.getUuid().toString()).request()
Expand All @@ -608,7 +608,7 @@ public void removeTeamFromRuleDuplicateTeamTest() {

@Test
public void removeTeamToRuleInvalidPublisherTest(){
Team team = qm.createTeam("Team Example", false);
Team team = qm.createTeam("Team Example");
NotificationPublisher publisher = qm.getNotificationPublisher(DefaultNotificationPublishers.SLACK.getPublisherName());
NotificationRule rule = qm.createNotificationRule("Example Rule", NotificationScope.PORTFOLIO, NotificationLevel.INFORMATIONAL, publisher);
Response response = jersey.target(V1_NOTIFICATION_RULE + "/" + rule.getUuid().toString() + "/team/" + team.getUuid().toString()).request()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void deleteGroupShouldIndicateNotFoundWhenGroupDoesNotExist() {
@Test
public void retrieveTeamsMappedToGroupShouldReturnTeamsMappedToSpecifiedGroup() {
final OidcGroup oidcGroup = qm.createOidcGroup("groupName");
final Team team = qm.createTeam("teamName", false);
final Team team = qm.createTeam("teamName");
qm.createMappedOidcGroup(team, oidcGroup);

final Response response = jersey.target(V1_OIDC + "/group/" + oidcGroup.getUuid() + "/team")
Expand Down Expand Up @@ -237,7 +237,7 @@ public void addMappingShouldIndicateNotFoundWhenTeamDoesNotExist() {

@Test
public void addMappingShouldIndicateNotFoundWhenGroupDoesNotExist() {
final Team team = qm.createTeam("teamName", false);
final Team team = qm.createTeam("teamName");

final MappedOidcGroupRequest request = new MappedOidcGroupRequest(team.getUuid().toString(), UUID.randomUUID().toString());

Expand All @@ -251,7 +251,7 @@ public void addMappingShouldIndicateNotFoundWhenGroupDoesNotExist() {

@Test
public void addMappingShouldIndicateConflictWhenMappingAlreadyExists() {
final Team team = qm.createTeam("teamName", false);
final Team team = qm.createTeam("teamName");
final OidcGroup group = qm.createOidcGroup("groupName");
qm.createMappedOidcGroup(team, group);

Expand All @@ -267,7 +267,7 @@ public void addMappingShouldIndicateConflictWhenMappingAlreadyExists() {

@Test
public void addMappingShouldReturnCreatedMapping() {
final Team team = qm.createTeam("teamName", false);
final Team team = qm.createTeam("teamName");
final OidcGroup group = qm.createOidcGroup("groupName");

final MappedOidcGroupRequest request = new MappedOidcGroupRequest(team.getUuid().toString(), group.getUuid().toString());
Expand All @@ -288,7 +288,7 @@ public void addMappingShouldReturnCreatedMapping() {

@Test
public void deleteMappingByUuidShouldDeleteMappingAndIndicateNoContent() {
final Team team = qm.createTeam("teamName", false);
final Team team = qm.createTeam("teamName");
final OidcGroup group = qm.createOidcGroup("groupName");
final MappedOidcGroup mapping = qm.createMappedOidcGroup(team, group);

Expand All @@ -314,7 +314,7 @@ public void deleteMappingByUuidShouldIndicateNotFoundWhenMappingDoesNotExist() {
@Test
public void deleteMappingShouldDeleteMappingAndIndicateNoContent() {
final OidcGroup oidcGroup = qm.createOidcGroup("groupName");
final Team team = qm.createTeam("teamName", false);
final Team team = qm.createTeam("teamName");
final MappedOidcGroup mapping = qm.createMappedOidcGroup(team, oidcGroup);

final Response response = jersey.target(V1_OIDC + "/group/" + oidcGroup.getUuid() + "/team/" + team.getUuid() + "/mapping").request()
Expand All @@ -338,7 +338,7 @@ public void deleteMappingShouldIndicateNotFoundWhenTeamDoesNotExist() {

@Test
public void deleteMappingShouldIndicateNotFoundWhenGroupDoesNotExist() {
final Team team = qm.createTeam("teamName", false);
final Team team = qm.createTeam("teamName");

final Response response = jersey.target(V1_OIDC + "/group/" + UUID.randomUUID() + "/team/" + team.getUuid() + "/mapping").request()
.header(X_API_KEY, apiKey)
Expand All @@ -350,7 +350,7 @@ public void deleteMappingShouldIndicateNotFoundWhenGroupDoesNotExist() {
@Test
public void deleteMappingShouldIndicateNotFoundWhenMappingDoesNotExist() {
final OidcGroup oidcGroup = qm.createOidcGroup("groupName");
final Team team = qm.createTeam("teamName", false);
final Team team = qm.createTeam("teamName");

final Response response = jersey.target(V1_OIDC + "/group/" + oidcGroup.getUuid() + "/team/" + team.getUuid() + "/mapping").request()
.header(X_API_KEY, apiKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void removePermissionFromUserNoChangesTest() {

@Test
public void addPermissionToTeamTest() {
Team team = qm.createTeam("team1", false);
Team team = qm.createTeam("team1");
String teamUuid = team.getUuid().toString();
qm.close();
Response response = jersey.target(V1_PERMISSION + "/PORTFOLIO_MANAGEMENT/team/" + teamUuid).request()
Expand All @@ -267,7 +267,7 @@ public void addPermissionToTeamInvalidTeamTest() {

@Test
public void addPermissionToTeamInvalidPermissionTest() {
Team team = qm.createTeam("team1", false);
Team team = qm.createTeam("team1");
String teamUuid = team.getUuid().toString();
qm.close();
Response response = jersey.target(V1_PERMISSION + "/BLAH/team/" + teamUuid).request()
Expand All @@ -281,7 +281,7 @@ public void addPermissionToTeamInvalidPermissionTest() {

@Test
public void addPermissionToTeamDuplicateTest() {
Team team = qm.createTeam("team1", false);
Team team = qm.createTeam("team1");
String teamUuid = team.getUuid().toString();
Permission permission = qm.getPermission(Permissions.PORTFOLIO_MANAGEMENT.name());
team.getPermissions().add(permission);
Expand All @@ -296,7 +296,7 @@ public void addPermissionToTeamDuplicateTest() {

@Test
public void removePermissionFromTeamTest() {
Team team = qm.createTeam("team1", false);
Team team = qm.createTeam("team1");
String teamUuid = team.getUuid().toString();
Permission permission = qm.getPermission(Permissions.PORTFOLIO_MANAGEMENT.name());
team.getPermissions().add(permission);
Expand Down Expand Up @@ -325,7 +325,7 @@ public void removePermissionFromTeamInvalidTeamTest() {

@Test
public void removePermissionFromTeamInvalidPermissionTest() {
Team team = qm.createTeam("team1", false);
Team team = qm.createTeam("team1");
String teamUuid = team.getUuid().toString();
qm.close();
Response response = jersey.target(V1_PERMISSION + "/BLAH/team/" + teamUuid).request()
Expand All @@ -339,7 +339,7 @@ public void removePermissionFromTeamInvalidPermissionTest() {

@Test
public void removePermissionFromTeamNoChangesTest() {
Team team = qm.createTeam("team1", false);
Team team = qm.createTeam("team1");
String teamUuid = team.getUuid().toString();
Response response = jersey.target(V1_PERMISSION + "/BOM_UPLOAD/team/" + teamUuid).request()
.header(X_API_KEY, apiKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public void getViolationsWithAclEnabledTest() {

final Response responseB = jersey.target(V1_POLICY_VIOLATION)
.request()
.header(X_API_KEY, team.getApiKeys().get(0).getKey())
.header(X_API_KEY, apiKey)
.get();
assertThat(responseB.getStatus()).isEqualTo(Response.Status.OK.getStatusCode());
assertThat(responseB.getHeaderString(TOTAL_COUNT_HEADER)).isEqualTo("2");
Expand Down Expand Up @@ -656,4 +656,4 @@ public void getViolationsWithInputFilter() {
assertThat(jsonArrayD).hasSize(1);
assertThat(jsonArrayD.getJsonObject(0).getString("uuid")).isEqualTo(violationD.getUuid().toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@

import jakarta.json.Json;
import jakarta.json.JsonArray;
import jakarta.json.JsonArrayBuilder;
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import jakarta.ws.rs.HttpMethod;
Expand Down Expand Up @@ -758,7 +757,7 @@ public void createProjectAsUserWithAclEnabledAndNotMemberOfTeamAdminTest() {

final String userJwt = new JsonWebToken().createToken(testUser);

final Team otherTeam = qm.createTeam("otherTeam", false);
final Team otherTeam = qm.createTeam("otherTeam");

final Response response = jersey.target(V1_PROJECT)
.request()
Expand Down
Loading

0 comments on commit eff4bff

Please sign in to comment.