From 90204cdfcf8944f6d302d3733de6824817a5c7c1 Mon Sep 17 00:00:00 2001 From: Valentijn Scholten Date: Wed, 8 Jan 2025 16:17:08 +0100 Subject: [PATCH] add Repository Config test Signed-off-by: Valentijn Scholten --- .../resources/v1/RepositoryResourceTest.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/dependencytrack/resources/v1/RepositoryResourceTest.java b/src/test/java/org/dependencytrack/resources/v1/RepositoryResourceTest.java index 13b3669ca..5e6e1bdde 100644 --- a/src/test/java/org/dependencytrack/resources/v1/RepositoryResourceTest.java +++ b/src/test/java/org/dependencytrack/resources/v1/RepositoryResourceTest.java @@ -28,6 +28,7 @@ import org.dependencytrack.persistence.DefaultObjectGenerator; import org.dependencytrack.persistence.QueryManager; import org.glassfish.jersey.server.ResourceConfig; +import org.json.JSONObject; import org.junit.Assert; import org.junit.Before; import org.junit.ClassRule; @@ -268,7 +269,6 @@ public void createRepositoryAuthFalseTest() { } - //TODO VS Add create repository with config advisory mirroring @Test public void updateRepositoryTest() throws Exception { Repository repository = new Repository(); @@ -304,4 +304,48 @@ public void updateRepositoryTest() throws Exception { } } + + @Test + public void updateRepositoryTestAdvisoryMirroring() throws Exception { + Repository repository = new Repository(); + repository.setAuthenticationRequired(true); + repository.setEnabled(true); + repository.setUsername("testuser"); + repository.setPassword("testPassword"); + repository.setInternal(true); + repository.setIdentifier("composer_repo"); + repository.setUrl("www.foobar.com"); + repository.setType(RepositoryType.COMPOSER); + Response response = jersey.target(V1_REPOSITORY).request().header(X_API_KEY, apiKey) + .put(Entity.entity(repository, MediaType.APPLICATION_JSON)); + Assert.assertEquals(201, response.getStatus()); + + try (QueryManager qm = new QueryManager()) { + List repositoryList = qm.getRepositories(RepositoryType.COMPOSER).getList(Repository.class); + for (Repository repository1 : repositoryList) { + if (repository1.getIdentifier().equals("composer_repo")) { + Assert.assertNull(repository1.getConfig()); + repository1.setConfig("{\"advisoryMirroringEnabled\": true, \"advisoryAliasSyncEnabled\": true}"); + response = jersey.target(V1_REPOSITORY).request().header(X_API_KEY, apiKey) + .post(Entity.entity(repository1, MediaType.APPLICATION_JSON)); + Assert.assertEquals(200, response.getStatus()); + break; + } + } + + repositoryList = qm.getRepositories(RepositoryType.COMPOSER).getList(Repository.class); + for (Repository repository1 : repositoryList) { + if (repository1.getIdentifier().equals("composer_repo")) { + Assert.assertNotNull(repository1.getConfig()); + JSONObject jsonConfig = new JSONObject(repository1.getConfig()); + Assert.assertTrue(jsonConfig.optBoolean("advisoryMirroringEnabled")); + Assert.assertTrue(jsonConfig.optBoolean("advisoryAliasSyncEnabled")); + break; + } + } + } + + } + + }