diff --git a/src/test/java/org/dependencytrack/resources/v1/RepositoryResourceTest.java b/src/test/java/org/dependencytrack/resources/v1/RepositoryResourceTest.java index bf62d0bc44..d8a0249ac6 100644 --- a/src/test/java/org/dependencytrack/resources/v1/RepositoryResourceTest.java +++ b/src/test/java/org/dependencytrack/resources/v1/RepositoryResourceTest.java @@ -18,8 +18,9 @@ */ package org.dependencytrack.resources.v1; -import alpine.server.filters.ApiFilter; -import alpine.server.filters.AuthenticationFilter; +import java.util.Date; +import java.util.List; + import org.dependencytrack.JerseyTestRule; import org.dependencytrack.ResourceTest; import org.dependencytrack.model.Repository; @@ -33,13 +34,13 @@ import org.junit.ClassRule; import org.junit.Test; +import alpine.server.filters.ApiFilter; +import alpine.server.filters.AuthenticationFilter; import jakarta.json.JsonArray; import jakarta.json.JsonObject; import jakarta.ws.rs.client.Entity; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; -import java.util.Date; -import java.util.List; public class RepositoryResourceTest extends ResourceTest { @@ -173,7 +174,7 @@ public void getRepositoryMetaUntrackedComponentTest() { @Test - public void createRepositoryTest() { + public void createRepositoryTestWithBasicAuth() { Repository repository = new Repository(); repository.setAuthenticationRequired(true); repository.setEnabled(true); @@ -203,6 +204,35 @@ public void createRepositoryTest() { Assert.assertTrue(json.getJsonObject(13).getBoolean("enabled")); } + @Test + public void createRepositoryTestWithBearerAuth() { + Repository repository = new Repository(); + repository.setAuthenticationRequired(true); + repository.setEnabled(true); + repository.setPassword("testToken"); + repository.setInternal(true); + repository.setIdentifier("test"); + repository.setUrl("www.foobar.com"); + repository.setType(RepositoryType.MAVEN); + Response response = jersey.target(V1_REPOSITORY).request().header(X_API_KEY, apiKey) + .put(Entity.entity(repository, MediaType.APPLICATION_JSON)); + Assert.assertEquals(201, response.getStatus()); + + response = jersey.target(V1_REPOSITORY).request().header(X_API_KEY, apiKey).get(Response.class); + Assert.assertEquals(200, response.getStatus(), 0); + Assert.assertEquals(String.valueOf(18), response.getHeaderString(TOTAL_COUNT_HEADER)); + JsonArray json = parseJsonArray(response); + Assert.assertNotNull(json); + Assert.assertEquals(18, json.size()); + Assert.assertEquals("MAVEN", json.getJsonObject(13).getString("type")); + Assert.assertEquals("test", json.getJsonObject(13).getString("identifier")); + Assert.assertEquals("www.foobar.com", json.getJsonObject(13).getString("url")); + Assert.assertTrue(json.getJsonObject(13).getInt("resolutionOrder") > 0); + Assert.assertTrue(json.getJsonObject(13).getBoolean("authenticationRequired")); + Assert.assertNull(json.getJsonObject(13).getString("username")); + Assert.assertTrue(json.getJsonObject(13).getBoolean("enabled")); + } + @Test public void createNonInternalRepositoryTest() { Repository repository = new Repository(); @@ -262,7 +292,6 @@ public void createRepositoryAuthFalseTest() { Assert.assertTrue(json.getJsonObject(13).getInt("resolutionOrder") > 0); Assert.assertFalse(json.getJsonObject(13).getBoolean("authenticationRequired")); Assert.assertTrue(json.getJsonObject(13).getBoolean("enabled")); - } @Test @@ -298,6 +327,5 @@ public void updateRepositoryTest() throws Exception { } } } - } }