1 package org.apache.maven.it;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.it.util.ResourceExtractor;
23 import org.eclipse.jetty.security.ConstraintMapping;
24 import org.eclipse.jetty.security.ConstraintSecurityHandler;
25 import org.eclipse.jetty.security.HashLoginService;
26 import org.eclipse.jetty.server.NetworkConnector;
27 import org.eclipse.jetty.server.Server;
28 import org.eclipse.jetty.server.handler.DefaultHandler;
29 import org.eclipse.jetty.server.handler.HandlerList;
30 import org.eclipse.jetty.server.handler.ResourceHandler;
31 import org.eclipse.jetty.servlet.ServletContextHandler;
32 import org.eclipse.jetty.util.security.Constraint;
33 import org.eclipse.jetty.util.security.Password;
34
35 import java.io.File;
36 import java.util.Properties;
37
38 import static org.eclipse.jetty.servlet.ServletContextHandler.SECURITY;
39 import static org.eclipse.jetty.servlet.ServletContextHandler.SESSIONS;
40 import static org.eclipse.jetty.util.security.Constraint.__BASIC_AUTH;
41
42
43
44
45
46
47 public class MavenITmng4489MirroringOfExtensionRepoTest
48 extends AbstractMavenIntegrationTestCase
49 {
50
51 public MavenITmng4489MirroringOfExtensionRepoTest()
52 {
53 super( "[2.0.3,3.0-alpha-1),[3.0-alpha-6,)" );
54 }
55
56
57
58
59
60
61
62 public void testit()
63 throws Exception
64 {
65 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4489" );
66
67 Constraint constraint = new Constraint();
68 constraint.setName( Constraint.__BASIC_AUTH );
69 constraint.setRoles( new String[] { "user" } );
70 constraint.setAuthenticate( true );
71
72 ConstraintMapping constraintMapping = new ConstraintMapping();
73 constraintMapping.setConstraint( constraint );
74 constraintMapping.setPathSpec( "/*" );
75
76 HashLoginService userRealm = new HashLoginService( "TestRealm" );
77 userRealm.putUser( "testuser", new Password( "testtest" ), new String[] { "user" } );
78
79 Server server = new Server( 0 );
80 ServletContextHandler ctx = new ServletContextHandler( server, "/", SESSIONS | SECURITY );
81 ConstraintSecurityHandler securityHandler = (ConstraintSecurityHandler) ctx.getSecurityHandler();
82 securityHandler.setLoginService( userRealm );
83 securityHandler.setAuthMethod( __BASIC_AUTH );
84 securityHandler.setConstraintMappings( new ConstraintMapping[] { constraintMapping } );
85
86 ResourceHandler repoHandler = new ResourceHandler();
87 repoHandler.setResourceBase( testDir.getAbsolutePath() );
88
89 HandlerList handlerList = new HandlerList();
90 handlerList.addHandler( securityHandler );
91 handlerList.addHandler( repoHandler );
92 handlerList.addHandler( new DefaultHandler() );
93
94 server.setHandler( handlerList );
95
96 try
97 {
98 server.start();
99 if ( server.isFailed() )
100 {
101 fail( "Couldn't bind the server socket to a free port!" );
102 }
103 int port = ( (NetworkConnector) server.getConnectors()[0] ).getLocalPort();
104 System.out.println( "Bound server socket to the port " + port );
105 Verifier verifier = newVerifier( testDir.getAbsolutePath() );
106 verifier.setAutoclean( false );
107 verifier.deleteDirectory( "target" );
108 verifier.deleteArtifacts( "org.apache.maven.its.mng4489" );
109 Properties filterProps = verifier.newDefaultFilterProperties();
110 filterProps.setProperty( "@port@", Integer.toString( port ) );
111 verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", filterProps );
112 verifier.addCliOption( "-s" );
113 verifier.addCliOption( "settings.xml" );
114 verifier.executeGoal( "validate" );
115 verifier.verifyErrorFreeLog();
116 verifier.resetStreams();
117
118 verifier.assertArtifactPresent( "org.apache.maven.its.mng4489", "ext-dep", "0.1", "jar" );
119 verifier.assertArtifactPresent( "org.apache.maven.its.mng4489", "ext-dep", "0.1", "pom" );
120 }
121 finally
122 {
123 server.stop();
124 server.join();
125 }
126 }
127 }