Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 161675ce2f534d30ae695472a30baad9fe25a9e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*******************************************************************************
 *  Copyright (c) 2021 Red Hat Inc. and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package org.eclipse.equinox.p2.tests.artifact.repository;

import java.nio.file.Files;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.artifact.processors.pgp.PGPSignatureVerifier;
import org.eclipse.equinox.internal.p2.artifact.repository.MirrorRequest;
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
import org.junit.Before;
import org.junit.Test;

public class PGPVerifierTest extends AbstractProvisioningTest {
	IArtifactRepository targetRepo = null;
	IArtifactRepository sourceRepo = null;

	@Override
	@Before
	public void setUp() throws Exception {
		super.setUp();
		PGPSignatureVerifier.keystore.clear();
	}

	private void loadPGPTestRepo(String repoName) throws Exception {
		sourceRepo = getArtifactRepositoryManager().loadRepository(
				getTestData("Test repository for PGP", "testData/pgp/" + repoName).toURI(), new NullProgressMonitor());
		targetRepo = createArtifactRepository(Files.createTempDirectory(PGPVerifierTest.class.getSimpleName()).toUri(),
				NO_PROPERTIES);
	}

	@Test
	public void testAllGood() throws Exception {
		IStatus mirrorStatus = performMirrorFrom("repoPGPOK");
		assertOK(mirrorStatus);
	}

	@Test
	public void testAllGoodWithEncodedProperties() throws Exception {
		IStatus mirrorStatus = performMirrorFrom("repoPGPOK_encoded");
		assertOK(mirrorStatus);
	}

	private IStatus performMirrorFrom(String repoName) throws Exception {
		loadPGPTestRepo(repoName);
		ArtifactKey key = new ArtifactKey("osgi.bundle", "blah", Version.create("1.0.0.123456"));
		MirrorRequest mirrorRequest = new MirrorRequest(key, targetRepo, NO_PROPERTIES, NO_PROPERTIES, getTransport());
		mirrorRequest.perform(sourceRepo, getMonitor());
		return mirrorRequest.getResult();
	}

	@Test
	public void testMissingPublicKey() throws Exception {
		IStatus mirrorStatus = performMirrorFrom("repoMissingPublicKey");
		assertNotOK(mirrorStatus);
		assertTrue(mirrorStatus.toString().contains("Public key not found"));
	}

	@Override
	protected void tearDown() throws Exception {
		getArtifactRepositoryManager().removeRepository(sourceRepo.getLocation());
		getArtifactRepositoryManager().removeRepository(targetRepo.getLocation());
		super.tearDown();
	}
}

Back to the top