mirror of https://github.com/apache/archiva.git
[MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
Fixed parsing of filenames to look for "." or "-" after the version to help determine if this artifact has a classifier or just a double-extension. Added unit tests to repository.content.* classes for double extension. Added unit test to RepositoryServlet for GET of artifact with double extension. git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@588732 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a7bf8292c3
commit
76aabf37a0
|
@ -67,7 +67,7 @@ public class ArtifactExtensionMapping
|
|||
}
|
||||
|
||||
// Return type
|
||||
return type;
|
||||
return type.replace( '-', '.' );
|
||||
}
|
||||
|
||||
public static String guessTypeFromFilename( File file )
|
||||
|
|
|
@ -143,10 +143,25 @@ public class DefaultPathParser
|
|||
}
|
||||
|
||||
// Do we have a classifier?
|
||||
artifact.setClassifier( parser.remaining() );
|
||||
switch(parser.seperator())
|
||||
{
|
||||
case '-':
|
||||
// Definately a classifier.
|
||||
artifact.setClassifier( parser.remaining() );
|
||||
|
||||
// Set the type.
|
||||
artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
|
||||
// Set the type.
|
||||
artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
|
||||
break;
|
||||
case '.':
|
||||
// We have an dual extension possibility.
|
||||
String extension = parser.remaining() + '.' + parser.getExtension();
|
||||
artifact.setType( extension.replace( '.', '-' ) );
|
||||
break;
|
||||
case 0:
|
||||
// End of the filename, only a simple extension left. - Set the type.
|
||||
artifact.setType( ArtifactExtensionMapping.guessTypeFromFilename( filename ) );
|
||||
break;
|
||||
}
|
||||
|
||||
// Special case for maven plugins
|
||||
if ( StringUtils.equals( "jar", artifact.getType() ) &&
|
||||
|
|
|
@ -114,6 +114,28 @@ public class FilenameParser
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current seperator character.
|
||||
*
|
||||
* @return the seperator character (either '.' or '-'), or 0 if no seperator character available.
|
||||
*/
|
||||
protected char seperator()
|
||||
{
|
||||
// Past the end of the string?
|
||||
if ( offset >= name.length() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Before the start of the string?
|
||||
if ( offset <= 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return name.charAt( offset - 1 );
|
||||
}
|
||||
|
||||
protected String getName()
|
||||
{
|
||||
return name;
|
||||
|
@ -207,4 +229,6 @@ public class FilenameParser
|
|||
|
||||
return ver.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -51,6 +51,22 @@ public class DefaultPathParserTest
|
|||
"wrong artifact id" );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
|
||||
*/
|
||||
public void testGoodButDualExtensions()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "org.project";
|
||||
String artifactId = "example-presentation";
|
||||
String version = "3.2";
|
||||
String classifier = null;
|
||||
String type = "xml-zip";
|
||||
String path = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, classifier, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-432] Oddball version spec.
|
||||
* Example of an oddball / unusual version spec.
|
||||
|
|
|
@ -97,11 +97,26 @@ public class FilenameParserTest
|
|||
|
||||
assertEquals( "ganymede-ssh2", parser.expect( "ganymede-ssh2" ) );
|
||||
assertEquals( "build250", parser.expect( "build250" ) );
|
||||
assertEquals( '-', parser.seperator() );
|
||||
assertEquals( "sources", parser.remaining() );
|
||||
|
||||
assertNull( parser.expect( "jar" ) );
|
||||
}
|
||||
|
||||
public void testExpectWithRemainingDualExtensions()
|
||||
{
|
||||
FilenameParser parser = new FilenameParser( "example-presentation-3.2.xml.zip" );
|
||||
|
||||
assertEquals( "example-presentation-3.2.xml", parser.getName() );
|
||||
assertEquals( "zip", parser.getExtension() );
|
||||
|
||||
assertEquals( "example-presentation", parser.expect( "example-presentation" ) );
|
||||
assertEquals( "3.2", parser.expect( "3.2" ) );
|
||||
assertEquals( '.', parser.seperator() );
|
||||
assertEquals( "xml", parser.remaining() );
|
||||
|
||||
}
|
||||
|
||||
public void testNextNonVersion()
|
||||
{
|
||||
FilenameParser parser = new FilenameParser( "maven-test-plugin-1.8.3.jar" );
|
||||
|
|
|
@ -59,6 +59,21 @@ public class LegacyPathParserTest
|
|||
assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
|
||||
*/
|
||||
public void testGoodButDualExtensions()
|
||||
throws LayoutException
|
||||
{
|
||||
String groupId = "org.project";
|
||||
String artifactId = "example-presentation";
|
||||
String version = "3.2.xml";
|
||||
String type = "distribution-zip";
|
||||
String path = "org.project/zips/example-presentation-3.2.xml.zip";
|
||||
|
||||
assertLayout( path, groupId, artifactId, version, type );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-432] Oddball version spec.
|
||||
* Example of an oddball / unusual version spec.
|
||||
|
|
|
@ -295,6 +295,33 @@ public class RepositoryRequestTest
|
|||
return createManagedRepositoryContent( "test-internal", "Internal Test Repo", repoRoot, layout );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
|
||||
*/
|
||||
public void testToNativePathArtifactDefaultToDefaultDualExtension()
|
||||
throws Exception
|
||||
{
|
||||
ManagedRepositoryContent repository = createManagedRepo( "default" );
|
||||
|
||||
// Test (artifact) default to default - dual extension
|
||||
assertEquals( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repoRequest
|
||||
.toNativePath( "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip", repository ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
|
||||
*/
|
||||
public void testToNativePathArtifactLegacyToDefaultDualExtension()
|
||||
throws Exception
|
||||
{
|
||||
ManagedRepositoryContent repository = createManagedRepo( "default" );
|
||||
|
||||
// Test (artifact) legacy to default - dual extension
|
||||
// NOTE: The detection of a dual extension is flawed.
|
||||
assertEquals( "org/project/example-presentation/3.2.xml/example-presentation-3.2.xml.zip", repoRequest
|
||||
.toNativePath( "org.project/zips/example-presentation-3.2.xml.zip", repository ) );
|
||||
}
|
||||
|
||||
public void testToNativePathMetadataDefaultToDefault()
|
||||
throws Exception
|
||||
{
|
||||
|
|
|
@ -217,4 +217,25 @@ public class RepositoryServletNoProxyTest
|
|||
|
||||
assertEquals( "Expected file contents", expectedArtifactContents, response.getText() );
|
||||
}
|
||||
|
||||
/**
|
||||
* [MRM-481] Artifact requests with a .xml.zip extension fail with a 404 Error
|
||||
*/
|
||||
public void testGetNoProxyDualExtensionDefaultLayout()
|
||||
throws Exception
|
||||
{
|
||||
String expectedContents = "the-contents-of-the-dual-extension";
|
||||
String dualExtensionPath = "org/project/example-presentation/3.2/example-presentation-3.2.xml.zip";
|
||||
|
||||
File checksumFile = new File( repoRootInternal, dualExtensionPath );
|
||||
checksumFile.getParentFile().mkdirs();
|
||||
|
||||
FileUtils.writeStringToFile( checksumFile, expectedContents, null );
|
||||
|
||||
WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + dualExtensionPath );
|
||||
WebResponse response = sc.getResponse( request );
|
||||
assertResponseOK( response );
|
||||
|
||||
assertEquals( "Expected file contents", expectedContents, response.getText() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue