Skip to content

Commit

Permalink
Auth works when resolving a target platform over a composite mirror.
Browse files Browse the repository at this point in the history
RemoteMetadataRepositoryManager now passes the effective URI to the
MavenAuthenticator instead of the original one. This fixes eclipse-tycho#3501.

This commit also includes the test that was used to reproduce the bug:

- testTargetDefinitionAuthMirror: tries to resolve a target definition
from a composite p2 repository accessed over an authenticated composite
mirror.

Also, several other tests have been created just for completion:

- testAuthMirror: tries to access a composite p2 repository over an
authenticated composite mirror.
- testMirror: tries to access a composite p2 repository over a composite
mirror with no authentication.
- testRepositoryEncrypted: tries to access an authenticated composite p2
repository whose password is encrypted.
- testTargetDefinition: tries to resolve a target platform from a
composite p2 repository.
- testTargetDefinitionEncrypted: tries to resolve a target definition
from an authenticated composite p2 repository whose password is
encrypted.
- testTargetDefinitionMirror: tries to resolve a target definition from
a composite p2 repository accessed over a composite mirror with no
authentication.
  • Loading branch information
kevloral committed Mar 17, 2024
1 parent 803f7eb commit df0fd65
Show file tree
Hide file tree
Showing 8 changed files with 193 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public IMetadataRepository loadRepository(URI location, IProgressMonitor monitor
public IMetadataRepository loadRepository(URI location, int flags, IProgressMonitor monitor)
throws ProvisionException, OperationCanceledException {
URI effectiveLocation = translateAndPrepareLoad(location);
authenticator.enterLoad(location);
authenticator.enterLoad(effectiveLocation);
try {
IMetadataRepository loadedRepository = delegate.loadRepository(effectiveLocation, flags, monitor);
failIfRepositoryContainsPartialIUs(loadedRepository, effectiveLocation);
Expand Down
12 changes: 12 additions & 0 deletions tycho-its/projects/issue2331/bundle/platform.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.5"?>

<target name="platform">
<locations>
<location includeAllPlatforms="false" includeMode="planner"
type="InstallableUnit">
<unit id='org.eclipse.osgi' version='3.4.3.R34x_v20081215-1030' />
<repository id="test-server" location="[url]" />
</location>
</locations>
</target>
12 changes: 7 additions & 5 deletions tycho-its/projects/issue2331/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>bundle</module>
<module>product</module>
</modules>

<build>
<plugins>
<plugin>
Expand All @@ -41,6 +36,10 @@
<profiles>
<profile>
<id>repository</id>
<modules>
<module>bundle</module>
<module>product</module>
</modules>
<repositories>
<repository>
<id>test-server</id>
Expand All @@ -52,6 +51,9 @@

<profile>
<id>target-definition</id>
<modules>
<module>bundle</module>
</modules>
<build>
<plugins>
<plugin>
Expand Down
18 changes: 18 additions & 0 deletions tycho-its/projects/issue2331/settings-auth-mirror.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<settings>
<servers>
<server>
<id>test-auth-mirror</id>
<username>mirror-user</username>
<password>mirror-password</password>
</server>
</servers>
<mirrors>
<mirror>
<id>test-auth-mirror</id>
<url>${p2.authMirror}</url>
<mirrorOf>test-server</mirrorOf>
<layout>p2</layout>
<mirrorOfLayouts>p2</mirrorOfLayouts>
</mirror>
</mirrors>
</settings>
9 changes: 9 additions & 0 deletions tycho-its/projects/issue2331/settings-encrypted.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<settings>
<servers>
<server>
<id>test-server</id>
<username>test-user</username>
<password>{Gnn5SYwzVmUHEaxkXS/F3PJlVeqCXstNJ61EtCTqNEU=}</password>
</server>
</servers>
</settings>
11 changes: 11 additions & 0 deletions tycho-its/projects/issue2331/settings-mirror.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<settings>
<mirrors>
<mirror>
<id>test-mirror</id>
<url>${p2.mirror}</url>
<mirrorOf>test-server</mirrorOf>
<layout>p2</layout>
<mirrorOfLayouts>p2</mirrorOfLayouts>
</mirror>
</mirrors>
</settings>
3 changes: 3 additions & 0 deletions tycho-its/projects/issue2331/settings-security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<settingsSecurity>
<master>{d0cIDW8DS4wHiBuKkPDps5v0kZ/OAX1REXQFCZRmS2g=}</master>
</settingsSecurity>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
import org.eclipse.tycho.test.util.HttpServer;
import org.eclipse.tycho.test.util.ResourceUtil;
import org.eclipse.tycho.test.util.TargetDefinitionUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -28,18 +29,69 @@ public class PasswordProtectedCompositeP2RepositoryTest extends AbstractTychoInt
private HttpServer server;
private String p2RepoUrl;

private HttpServer mirror;
private String p2MirrorUrl;

private HttpServer authMirror;
private String p2AuthMirrorUrl;

@Before
public void startServer() throws Exception {
server = HttpServer.startServer("test-user", "test-password");
p2RepoUrl = server.addServer("foo", ResourceUtil.resolveTestResource("repositories/issue_2331_reproducer"))
+ "/bundles";

mirror = HttpServer.startServer();
p2MirrorUrl = mirror.addServer("bar", ResourceUtil.resolveTestResource("repositories/issue_2331_reproducer"))
+ "/bundles";

authMirror = HttpServer.startServer("mirror-user", "mirror-password");
p2AuthMirrorUrl = authMirror.addServer("bar",
ResourceUtil.resolveTestResource("repositories/issue_2331_reproducer")) + "/bundles";
}

@After
public void stopServer() throws Exception {
authMirror.stop();
mirror.stop();
server.stop();
}

/**
* Tries to access a composite p2 repository over an authenticated composite
* mirror.
*
* @throws Exception
*/
@Test
public void testAuthMirror() throws Exception {
Verifier verifier = createVerifier("settings-auth-mirror.xml");
verifier.setSystemProperty("p2.authMirror", p2AuthMirrorUrl);
verifier.addCliOption("-P=repository");
verifier.executeGoal("package");
verifier.verifyErrorFreeLog();
}

/**
* Tries to access a composite p2 repository over a composite mirror with no
* authentication.
*
* @throws Exception
*/
@Test
public void testMirror() throws Exception {
Verifier verifier = createVerifier("settings-mirror.xml");
verifier.setSystemProperty("p2.mirror", p2MirrorUrl);
verifier.addCliOption("-P=repository");
verifier.executeGoal("package");
verifier.verifyErrorFreeLog();
}

/**
* Tries to access a composite p2 repository.
*
* @throws Exception
*/
@Test
public void testRepository() throws Exception {
Verifier verifier = createVerifier("settings.xml");
Expand All @@ -48,6 +100,85 @@ public void testRepository() throws Exception {
verifier.verifyErrorFreeLog();
}

/**
* Tries to access an authenticated composite p2 repository whose password is
* encrypted.
*
* @throws Exception
*/
@Test
public void testRepositoryEncrypted() throws Exception {
Verifier verifier = createVerifier("settings-encrypted.xml", "settings-security.xml");
verifier.addCliOption("-P=repository");
verifier.executeGoal("package");
verifier.verifyErrorFreeLog();
}

/**
* Tries to resolve a target platform from a composite p2 repository.
*
* @throws Exception
*/
@Test
public void testTargetDefinition() throws Exception {
Verifier verifier = createVerifier("settings.xml");
File platformFile = new File(verifier.getBasedir(), "bundle/platform.target");
TargetDefinitionUtil.setRepositoryURLs(platformFile, p2RepoUrl);
verifier.addCliOption("-P=target-definition");
verifier.executeGoal("package");
verifier.verifyErrorFreeLog();
}

/**
* Tries to resolve a target definition from a composite p2 repository accessed
* over a composite mirror with no authentication.
*
* @throws Exception
*/
@Test
public void testTargetDefinitionMirror() throws Exception {
Verifier verifier = createVerifier("settings-mirror.xml");
File platformFile = new File(verifier.getBasedir(), "bundle/platform.target");
TargetDefinitionUtil.setRepositoryURLs(platformFile, p2RepoUrl);
verifier.setSystemProperty("p2.mirror", p2MirrorUrl);
verifier.addCliOption("-P=target-definition");
verifier.executeGoal("package");
verifier.verifyErrorFreeLog();
}

/**
* Tries to resolve a target definition from a composite p2 repository accessed
* over an authenticated composite mirror.
*
* @throws Exception
*/
@Test
public void testTargetDefinitionAuthMirror() throws Exception {
Verifier verifier = createVerifier("settings-auth-mirror.xml");
File platformFile = new File(verifier.getBasedir(), "bundle/platform.target");
TargetDefinitionUtil.setRepositoryURLs(platformFile, p2RepoUrl);
verifier.setSystemProperty("p2.authMirror", p2AuthMirrorUrl);
verifier.addCliOption("-P=target-definition");
verifier.executeGoal("package");
verifier.verifyErrorFreeLog();
}

/**
* Tries to resolve a target definition from an authenticated composite p2
* repository whose password is encrypted.
*
* @throws Exception
*/
@Test
public void testTargetDefinitionEncrypted() throws Exception {
Verifier verifier = createVerifier("settings-encrypted.xml", "settings-security.xml");
File platformFile = new File(verifier.getBasedir(), "bundle/platform.target");
TargetDefinitionUtil.setRepositoryURLs(platformFile, p2RepoUrl);
verifier.addCliOption("-P=target-definition");
verifier.executeGoal("package");
verifier.verifyErrorFreeLog();
}

private Verifier createVerifier(String settingsFile) throws Exception {
return createVerifier(settingsFile, null);
}
Expand All @@ -60,7 +191,7 @@ private Verifier createVerifier(String settingsFile, String settingsSecurityFile
// see
// org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher#SYSTEM_PROPERTY_SEC_LOCATION
systemProperties.setProperty("settings.security",
new File("projects/target.httpAuthentication/" + settingsSecurityFile).getAbsolutePath());
new File("projects/issue2331/" + settingsSecurityFile).getAbsolutePath());
}
return verifier;
}
Expand Down

0 comments on commit df0fd65

Please sign in to comment.