-
-
Notifications
You must be signed in to change notification settings - Fork 595
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metadata Repositories: Support Bearer Token Authentication NuGet
Signed-off-by: Valentijn Scholten <[email protected]>
- Loading branch information
1 parent
7de8f33
commit 80198f8
Showing
1 changed file
with
20 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,17 @@ | |
*/ | ||
package org.dependencytrack.tasks.repositories; | ||
|
||
import com.github.packageurl.PackageURL; | ||
import static org.dependencytrack.tasks.repositories.NugetMetaAnalyzer.SUPPORTED_DATE_FORMATS; | ||
import static org.mockserver.model.HttpRequest.request; | ||
import static org.mockserver.model.HttpResponse.response; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.text.DateFormat; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import org.apache.http.HttpHeaders; | ||
import org.dependencytrack.model.Component; | ||
import org.dependencytrack.model.RepositoryType; | ||
|
@@ -29,16 +39,7 @@ | |
import org.mockserver.client.MockServerClient; | ||
import org.mockserver.integration.ClientAndServer; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.text.DateFormat; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import static org.dependencytrack.tasks.repositories.NugetMetaAnalyzer.SUPPORTED_DATE_FORMATS; | ||
import static org.mockserver.model.HttpRequest.request; | ||
import static org.mockserver.model.HttpResponse.response; | ||
import com.github.packageurl.PackageURL; | ||
|
||
public class NugetMetaAnalyzerTest { | ||
|
||
|
@@ -71,8 +72,8 @@ public void testAnalyzer() throws Exception { | |
|
||
|
||
// This test is to check if the analyzer is excluding pre-release versions | ||
// The test is transitent depending on the current version of the package | ||
// retrieved from the repository at the time of running. | ||
// The test is transitent depending on the current version of the package | ||
// retrieved from the repository at the time of running. | ||
// When it was created, the latest release version was 9.0.0-preview.1.24080.9 | ||
@Test | ||
public void testAnalyzerExcludingPreRelease() throws Exception { | ||
|
@@ -91,8 +92,8 @@ public void testAnalyzerExcludingPreRelease() throws Exception { | |
} | ||
|
||
// This test is to check if the analyzer is including pre-release versions | ||
// The test is transitent depending on the current version of the package | ||
// retrieved from the repository at the time of running. | ||
// The test is transitent depending on the current version of the package | ||
// retrieved from the repository at the time of running. | ||
// When it was created, the latest release version was 9.0.0-preview.1.24080.9 | ||
@Test | ||
public void testAnalyzerIncludingPreRelease() throws Exception { | ||
|
@@ -125,7 +126,7 @@ public void testAnalyzerWithPrivatePackageRepository() throws Exception { | |
.withHeader(HttpHeaders.CONTENT_TYPE, "application/json") | ||
.withBody(mockIndexResponse) | ||
); | ||
String encodedBasicHeader = "Basic OnBhc3N3b3Jk"; | ||
String encodedAuthHeader = "Bearer OnBhc3N3b3Jk"; | ||
|
||
String mockVersionResponse = readResourceFileToString("/unit/tasks/repositories/https---localhost-1080-v3-flat2" + | ||
"-nunitprivate-index.json"); | ||
|
@@ -134,7 +135,7 @@ public void testAnalyzerWithPrivatePackageRepository() throws Exception { | |
request() | ||
.withMethod("GET") | ||
.withPath("/v3/flat2/nunitprivate/index.json") | ||
.withHeader("Authorization", encodedBasicHeader) | ||
.withHeader("Authorization", encodedAuthHeader) | ||
) | ||
.respond( | ||
response() | ||
|
@@ -150,7 +151,7 @@ public void testAnalyzerWithPrivatePackageRepository() throws Exception { | |
request() | ||
.withMethod("GET") | ||
.withPath("/v3/registrations2/nunitprivate/5.0.2.json") | ||
.withHeader("Authorization", encodedBasicHeader) | ||
.withHeader("Authorization", encodedAuthHeader) | ||
) | ||
.respond( | ||
response() | ||
|
@@ -161,7 +162,7 @@ public void testAnalyzerWithPrivatePackageRepository() throws Exception { | |
Component component = new Component(); | ||
component.setPurl(new PackageURL("pkg:nuget/[email protected]")); | ||
NugetMetaAnalyzer analyzer = new NugetMetaAnalyzer(); | ||
analyzer.setRepositoryUsernameAndPassword(null, "password"); | ||
analyzer.setRepositoryUsernameAndPassword(null, "OnBhc3N3b3Jk"); | ||
analyzer.setRepositoryBaseUrl("http://localhost:1080"); | ||
MetaModel metaModel = analyzer.analyze(component); | ||
Assert.assertEquals("5.0.2", metaModel.getLatestVersion()); | ||
|