View Javadoc
1   package org.apache.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.it.util.ResourceExtractor;
23  
24  import java.io.File;
25  
26  public class MavenITmng7128BlockExternalHttpReactorTest
27          extends AbstractMavenIntegrationTestCase
28  {
29      private static final String PROJECT_PATH = "/mng-7128-block-external-http-reactor";
30  
31      public MavenITmng7128BlockExternalHttpReactorTest()
32      {
33          super( "[3.8.1,)" );
34      }
35  
36      /**
37       * This test verifies that defining a repository in pom.xml that uses HTTP is blocked.
38       *
39       * @throws Exception in case of failure
40       */
41      public void testBlockedHttpRepositoryInPom() throws Exception
42      {
43          final File projectDir = ResourceExtractor.simpleExtractResources( getClass(), PROJECT_PATH );
44          final Verifier verifier = newVerifier( projectDir.getAbsolutePath() );
45          verifier.addCliOption( "-s settings.xml" ); // ITs override global settings that provide blocked mirror: need to define the mirror in dedicated settings
46  
47          try
48          {
49              verifier.executeGoal( "compiler:compile" );
50              fail( "HTTP repository defined in pom.xml should have failed the build but did not." );
51          }
52          catch ( VerificationException ve )
53          {
54              // Inspect the reason why the build broke.
55              verifier.verifyTextInLog( "[ERROR] Failed to execute goal on project http-repository-in-pom: "
56                  + "Could not resolve dependencies for project org.apache.maven.its.mng7128:http-repository-in-pom:jar:1.0: "
57                  + "Failed to collect dependencies at junit:junit:jar:1.3: "
58                  + "Failed to read artifact descriptor for junit:junit:jar:1.3: "
59                  + "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
60                  + "Blocked mirror for repositories: [insecure-http-repo (http://repo.maven.apache.org/, default, releases+snapshots)]" );
61          }
62      }
63  }