Browse Source

[MRM-747] Archiva should prevent re-deployment of released or non-snapshot versioned artifacts

o block re-deployment of released artifacts to repository of configured using web upload form
o added unit test


git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@883057 13f79535-47bb-0310-9956-ffa450edef68
tags/archiva-1.3
Maria Odea B. Ching 14 years ago
parent
commit
27cb4991b1

+ 11
- 2
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java View File

@@ -351,8 +351,17 @@ public class UploadAction
try
{
copyFile( artifactFile, targetPath, filename, fixChecksums );
queueRepositoryTask( repository.getId(), repository.toFile( artifactReference ) );
File targetFile = new File( targetPath, filename );
if( targetFile.exists() && !VersionUtil.isSnapshot( version ) && repoConfig.isBlockRedeployments() )
{
addActionError( "Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed." );
return ERROR;
}
else
{
copyFile( artifactFile, targetPath, filename, fixChecksums );
queueRepositoryTask( repository.getId(), repository.toFile( artifactReference ) );
}
}
catch ( IOException ie )
{

+ 82
- 5
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/UploadActionTest.java View File

@@ -97,6 +97,7 @@ public class UploadActionTest
repoConfig.setLayout( "default" );
repoConfig.setLocation( testRepo.getPath() );
repoConfig.setName( REPOSITORY_ID );
repoConfig.setBlockRedeployments( true );
config.addManagedRepository( repoConfig );
RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
@@ -336,7 +337,7 @@ public class UploadActionTest

public void testArtifactUploadFailedRepositoryNotFound()
throws Exception
{
{
setUploadParameters( "1.0", null,
new File( getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
@@ -405,9 +406,9 @@ public class UploadActionTest
true );

ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( REPOSITORY_ID );
repoConfig.setBlockRedeployments( false );
content.setRepository( repoConfig );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
@@ -451,5 +452,81 @@ public class UploadActionTest
assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );

verifyChecksums( repoLocation );
}
}
public void testUploadArtifactAlreadyExistingRedeploymentsBlocked()
throws Exception
{
setUploadParameters( "1.0", null,
new File( getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
true );

ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );

archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content, 2 );

archivaConfigControl.replay();
repoFactoryControl.replay();

String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
setUploadParameters( "1.0", null,
new File( getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
true );
returnString = uploadAction.doUpload();
assertEquals( Action.ERROR, returnString );

archivaConfigControl.verify();
repoFactoryControl.verify();

String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );

verifyChecksums( repoLocation );
}
public void testUploadArtifactAlreadyExistingRedeploymentsAllowed()
throws Exception
{
setUploadParameters( "1.0", null,
new File( getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
true );
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( REPOSITORY_ID );
repoConfig.setBlockRedeployments( false );
content.setRepository( repoConfig );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content, 2 );
archivaConfigControl.replay();
repoFactoryControl.replay();
String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
setUploadParameters( "1.0", null,
new File( getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
true );
returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
archivaConfigControl.verify();
repoFactoryControl.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
verifyChecksums( repoLocation );
}
}

Loading…
Cancel
Save