You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2021/03/27 02:18:25 UTC

[maven-integration-testing] branch master updated: [MNG-7128] test blocked HTTP repository in pom.xml

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git


The following commit(s) were added to refs/heads/master by this push:
     new 39b9af7  [MNG-7128] test blocked HTTP repository in pom.xml
39b9af7 is described below

commit 39b9af737bd2b4227866f9cb9ddd12bbb2c11508
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sat Mar 27 03:18:05 2021 +0100

    [MNG-7128] test blocked HTTP repository in pom.xml
---
 .../org/apache/maven/it/IntegrationTestSuite.java  |  1 +
 ...MavenITmng7128BlockExternalHttpReactorTest.java | 62 ++++++++++++++++++++++
 .../mng-7128-block-external-http-reactor/pom.xml   | 44 +++++++++++++++
 .../settings.xml                                   | 34 ++++++++++++
 4 files changed, 141 insertions(+)

diff --git a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
index d9be087..812541b 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
@@ -106,6 +106,7 @@ public class IntegrationTestSuite
         // Tests that don't run stable and need to be fixed
         // -------------------------------------------------------------------------------------------------------------
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
+        suite.addTestSuite( MavenITmng7128BlockExternalHttpReactorTest.class );
         suite.addTestSuite( MavenITmng6511OptionalProjectSelectionTest.class );
         suite.addTestSuite( MavenITmng7110ExtensionClassloader.class );
         suite.addTestSuite( MavenITmng7051OptionalProfileActivationTest.class );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7128BlockExternalHttpReactorTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7128BlockExternalHttpReactorTest.java
new file mode 100644
index 0000000..7a38117
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng7128BlockExternalHttpReactorTest.java
@@ -0,0 +1,62 @@
+package org.apache.maven.it;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.it.util.ResourceExtractor;
+
+import java.io.File;
+import java.io.IOException;
+
+public class MavenITmng7128BlockExternalHttpReactorTest
+        extends AbstractMavenIntegrationTestCase
+{
+    private static final String PROJECT_PATH = "/mng-7128-block-external-http-reactor";
+
+    public MavenITmng7128BlockExternalHttpReactorTest()
+    {
+        super( "[3.8.1,)" );
+    }
+
+    /**
+     * This test verifies that defining a repository in pom.xml that uses HTTP is blocked.
+     */
+    public void testBlockedHttpRepositoryInPom() throws IOException, VerificationException
+    {
+        final File projectDir = ResourceExtractor.simpleExtractResources( getClass(), PROJECT_PATH );
+        final Verifier verifier = newVerifier( projectDir.getAbsolutePath() );
+        verifier.addCliOption( "-s settings.xml" ); // ITs override global settings that provide blocked mirror: need to define the mirror in dedicated settings
+
+        try
+        {
+            verifier.executeGoal( "compiler:compile" );
+            fail( "HTTP repository defined in pom.xml should have failed the build but did not." );
+        }
+        catch ( VerificationException ve )
+        {
+            // Inspect the reason why the build broke.
+            verifier.verifyTextInLog( "[ERROR] Failed to execute goal on project http-repository-in-pom: "
+                + "Could not resolve dependencies for project org.apache.maven.its.mng7128:http-repository-in-pom:jar:1.0: "
+                + "Failed to collect dependencies at junit:junit:jar:1.3: "
+                + "Failed to read artifact descriptor for junit:junit:jar:1.3: "
+                + "Could not transfer artifact junit:junit:pom:1.3 from/to maven-default-http-blocker (http://0.0.0.0/): " // mirror introduced in MNG-7118
+                + "Blocked mirror for repositories: [insecure-http-repo (http://repo.maven.apache.org/, default, releases+snapshots)]" );
+        }
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-7128-block-external-http-reactor/pom.xml b/core-it-suite/src/test/resources/mng-7128-block-external-http-reactor/pom.xml
new file mode 100644
index 0000000..dc3cbd3
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7128-block-external-http-reactor/pom.xml
@@ -0,0 +1,44 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng7128</groupId>
+  <artifactId>http-repository-in-pom</artifactId>
+  <version>1.0</version>
+
+  <name>Maven Integration Test :: MNG-7128</name>
+  <description>
+    Define a HTTP repository in this reactor pom.xml: check that it is blocked.
+  </description>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>1.3</version><!-- version intentionally not available in central to trigger download from defined repository -->
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.8.1</version>
+        <configuration>
+          <source>8</source>
+          <target>8</target>
+          <encoding>UTF-8</encoding>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <repositories>
+    <repository>
+      <id>insecure-http-repo</id>
+      <name>HTTP repository: should be blocked</name>
+      <url>http://repo.maven.apache.org/</url><!-- intentionally insecure HTTP -->
+    </repository>
+  </repositories>
+</project>
+
diff --git a/core-it-suite/src/test/resources/mng-7128-block-external-http-reactor/settings.xml b/core-it-suite/src/test/resources/mng-7128-block-external-http-reactor/settings.xml
new file mode 100644
index 0000000..8212563
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-7128-block-external-http-reactor/settings.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
+  <mirrors>
+    <mirror><!-- copied from Maven default settings.xml -->
+      <id>maven-default-http-blocker</id>
+      <mirrorOf>external:http:*</mirrorOf>
+      <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
+      <url>http://0.0.0.0/</url>
+      <blocked>true</blocked>
+    </mirror>
+  </mirrors>
+</settings>