Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port: add hackage and nixpkgs analyzers #729

Merged
merged 2 commits into from
Jun 16, 2024
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
8 changes: 7 additions & 1 deletion src/main/java/org/dependencytrack/model/RepositoryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public enum RepositoryType {
GO_MODULES,
CPAN,
GITHUB,
HACKAGE,
NIXPKGS,
UNSUPPORTED;

/**
Expand Down Expand Up @@ -68,8 +70,12 @@ public static RepositoryType resolve(PackageURL packageURL) {
return GO_MODULES;
} else if ("cpan".equals(type)) { // Not defined in StandardTypes
return CPAN;
} else if (PackageURL.StandardTypes.GITHUB.equals(type)) { // Not defined in StandardTypes
} else if (PackageURL.StandardTypes.GITHUB.equals(type)) {
return GITHUB;
} else if ("hackage".equals(type)) { // Not defined in StandardTypes
return HACKAGE;
} else if ("nixpkgs".equals(type)) { // Not defined in StandardTypes
return NIXPKGS;
}
return UNSUPPORTED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public void loadDefaultRepositories() {
qm.createRepository(RepositoryType.CARGO, "crates.io", "https://crates.io", true, false, false, null, null);
qm.createRepository(RepositoryType.GO_MODULES, "proxy.golang.org", "https://proxy.golang.org", true, false, false, null, null);
qm.createRepository(RepositoryType.GITHUB, "github.com", "https://github.com", true, false, false, null, null);
qm.createRepository(RepositoryType.HACKAGE, "hackage.haskell", "https://hackage.haskell.org/", true, false, false, null, null);
qm.createRepository(RepositoryType.NIXPKGS, "nixos.org", "https://channels.nixos.org/nixpkgs-unstable/packages.json.br", true, false, false, null, null);
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/dependencytrack/model/RepositoryTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,15 @@ public void testResolveGitHub() throws Exception {
Assert.assertEquals(RepositoryType.GITHUB, RepositoryType.resolve(purl));
}

@Test
public void testResolveHackage() throws Exception {
final var purl = new PackageURL("pkg:hackage/[email protected]");
Assert.assertEquals(RepositoryType.HACKAGE, RepositoryType.resolve(purl));
}

@Test
public void testResolveNixpkgs() throws Exception {
final var purl = new PackageURL("pkg:nixpkgs/[email protected]");
Assert.assertEquals(RepositoryType.NIXPKGS, RepositoryType.resolve(purl));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void testLoadDefaultRepositories() throws Exception {
Method method = generator.getClass().getDeclaredMethod("loadDefaultRepositories");
method.setAccessible(true);
method.invoke(generator);
Assert.assertEquals(15, qm.getAllRepositories().size());
Assert.assertEquals(17, qm.getAllRepositories().size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ public void getRepositoriesTest() {
.header(X_API_KEY, apiKey)
.get(Response.class);
Assert.assertEquals(200, response.getStatus(), 0);
Assert.assertEquals(String.valueOf(15), response.getHeaderString(TOTAL_COUNT_HEADER));
Assert.assertEquals(String.valueOf(17), response.getHeaderString(TOTAL_COUNT_HEADER));
JsonArray json = parseJsonArray(response);
Assert.assertNotNull(json);
Assert.assertEquals(15, json.size());
Assert.assertEquals(17, json.size());
for (int i = 0; i < json.size(); i++) {
Assert.assertNotNull(json.getJsonObject(i).getString("type"));
Assert.assertNotNull(json.getJsonObject(i).getString("identifier"));
Expand Down Expand Up @@ -191,17 +191,17 @@ public void createRepositoryTest() throws Exception {

response = jersey.target(V1_REPOSITORY).request().header(X_API_KEY, apiKey).get(Response.class);
Assert.assertEquals(200, response.getStatus(), 0);
Assert.assertEquals(String.valueOf(16), response.getHeaderString(TOTAL_COUNT_HEADER));
Assert.assertEquals(String.valueOf(18), response.getHeaderString(TOTAL_COUNT_HEADER));
JsonArray json = parseJsonArray(response);
Assert.assertNotNull(json);
Assert.assertEquals(16, json.size());
Assert.assertEquals("MAVEN", json.getJsonObject(12).getString("type"));
Assert.assertEquals("test", json.getJsonObject(12).getString("identifier"));
Assert.assertEquals("www.foobar.com", json.getJsonObject(12).getString("url"));
Assert.assertTrue(json.getJsonObject(12).getInt("resolutionOrder") > 0);
Assert.assertTrue(json.getJsonObject(12).getBoolean("authenticationRequired"));
Assert.assertEquals("testuser", json.getJsonObject(12).getString("username"));
Assert.assertTrue(json.getJsonObject(12).getBoolean("enabled"));
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.assertEquals("testuser", json.getJsonObject(13).getString("username"));
Assert.assertTrue(json.getJsonObject(13).getBoolean("enabled"));
}

@Test
Expand All @@ -220,16 +220,16 @@ public void createRepositoryAuthFalseTest() {

response = jersey.target(V1_REPOSITORY).request().header(X_API_KEY, apiKey).get(Response.class);
Assert.assertEquals(200, response.getStatus(), 0);
Assert.assertEquals(String.valueOf(16), response.getHeaderString(TOTAL_COUNT_HEADER));
Assert.assertEquals(String.valueOf(18), response.getHeaderString(TOTAL_COUNT_HEADER));
JsonArray json = parseJsonArray(response);
Assert.assertNotNull(json);
Assert.assertEquals(16, json.size());
Assert.assertEquals("MAVEN", json.getJsonObject(12).getString("type"));
Assert.assertEquals("test", json.getJsonObject(12).getString("identifier"));
Assert.assertEquals("www.foobar.com", json.getJsonObject(12).getString("url"));
Assert.assertTrue(json.getJsonObject(12).getInt("resolutionOrder") > 0);
Assert.assertFalse(json.getJsonObject(12).getBoolean("authenticationRequired"));
Assert.assertTrue(json.getJsonObject(12).getBoolean("enabled"));
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.assertFalse(json.getJsonObject(13).getBoolean("authenticationRequired"));
Assert.assertTrue(json.getJsonObject(13).getBoolean("enabled"));

}

Expand Down