1 /******************************************************************************* 2 * Copyright (c) 2007, 2008 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 *******************************************************************************/ 14 package org.eclipse.equinox.p2.tests.artifact.processors; 15 16 import static org.junit.Assert.assertEquals; 17 18 import java.io.ByteArrayOutputStream; 19 import java.io.IOException; 20 import java.io.InputStream; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.NullProgressMonitor; 23 import org.eclipse.equinox.internal.p2.core.helpers.FileUtils; 24 import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep; 25 import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ZipVerifierStep; 26 import org.eclipse.equinox.p2.tests.TestActivator; 27 import org.junit.Test; 28 import org.osgi.framework.Bundle; 29 30 public class ZipVerifierProcessorTest { 31 32 @Test testGoodZip()33 public void testGoodZip() throws IOException { 34 // Setup the processor 35 ProcessingStep step = new ZipVerifierStep(); 36 ByteArrayOutputStream destination = new ByteArrayOutputStream(); 37 step.link(destination, new NullProgressMonitor()); 38 39 // drive the source data through the step 40 Bundle bundle = TestActivator.getContext().getBundle(); 41 InputStream inputStream = bundle.getEntry("testData/zipValidation/a.zip").openStream(); 42 FileUtils.copyStream(inputStream, true, step, true); 43 44 assertEquals(step.getStatus().getSeverity(), IStatus.OK); 45 } 46 47 @Test testBogusFile()48 public void testBogusFile() throws IOException { 49 // Setup the processor 50 ProcessingStep step = new ZipVerifierStep(); 51 ByteArrayOutputStream destination = new ByteArrayOutputStream(); 52 step.link(destination, new NullProgressMonitor()); 53 54 // drive the source data through the step 55 Bundle bundle = TestActivator.getContext().getBundle(); 56 InputStream inputStream = bundle.getEntry("testData/zipValidation/a.txt").openStream(); 57 FileUtils.copyStream(inputStream, true, step, true); 58 59 assertEquals(step.getStatus().getSeverity(), IStatus.ERROR); 60 } 61 62 @Test testBogusFile2()63 public void testBogusFile2() throws IOException { 64 // Setup the processor 65 ProcessingStep step = new ZipVerifierStep(); 66 ByteArrayOutputStream destination = new ByteArrayOutputStream(); 67 step.link(destination, new NullProgressMonitor()); 68 69 // drive the source data through the step 70 Bundle bundle = TestActivator.getContext().getBundle(); 71 InputStream inputStream = bundle.getEntry("testData/zipValidation/org.eclipse.mylyn.bugzilla.core_2.3.2.v20080402-2100.jar").openStream(); 72 FileUtils.copyStream(inputStream, true, step, true); 73 74 assertEquals(step.getStatus().getSeverity(), IStatus.ERROR); 75 } 76 77 @Test testBogusFile3()78 public void testBogusFile3() throws IOException { 79 // Setup the processor 80 ProcessingStep step = new ZipVerifierStep(); 81 ByteArrayOutputStream destination = new ByteArrayOutputStream(); 82 step.link(destination, new NullProgressMonitor()); 83 84 // drive the source data through the step 85 Bundle bundle = TestActivator.getContext().getBundle(); 86 InputStream inputStream = bundle.getEntry("testData/zipValidation/bogusa.zip").openStream(); 87 FileUtils.copyStream(inputStream, true, step, true); 88 89 assertEquals(step.getStatus().getSeverity(), IStatus.ERROR); 90 } 91 92 @Test testPackGZFile()93 public void testPackGZFile() throws IOException { 94 95 // Setup the processor 96 ProcessingStep step = new ZipVerifierStep(); 97 ByteArrayOutputStream destination = new ByteArrayOutputStream(); 98 step.link(destination, new NullProgressMonitor()); 99 100 // drive the source data through the step 101 Bundle bundle = TestActivator.getContext().getBundle(); 102 InputStream inputStream = bundle.getEntry("testData/zipValidation/org.eclipse.equinox.p2.updatechecker.source_1.0.0.v20080427-2136.jar.pack.gz").openStream(); 103 FileUtils.copyStream(inputStream, true, step, true); 104 105 assertEquals(step.getStatus().getSeverity(), IStatus.ERROR); 106 107 } 108 } 109