mirror of https://github.com/apache/archiva.git
ensure confirm directory overwrite works without DMI
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@1563553 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
32091286bb
commit
fed0b5a687
|
@ -45,6 +45,7 @@ public class RepositoryTest
|
|||
{
|
||||
goToRepositoriesPage();
|
||||
deleteManagedRepository( "managedrepo1", true, false );
|
||||
deleteManagedRepository( "managedrepo2", true, false );
|
||||
deleteManagedRepository( "managedrepoedit", true, false );
|
||||
deleteRemoteRepository( "remoterepo", false );
|
||||
}
|
||||
|
@ -52,8 +53,6 @@ public class RepositoryTest
|
|||
public void testAddManagedRepoValidValues()
|
||||
throws IOException
|
||||
{
|
||||
goToRepositoriesPage();
|
||||
getSelenium().open( "/archiva/admin/addRepository.action" );
|
||||
File dir = new File( getRepositoryDir() + "repository/" );
|
||||
if ( dir.exists() )
|
||||
{
|
||||
|
@ -67,10 +66,45 @@ public class RepositoryTest
|
|||
Assert.assertTrue( dir.exists() && dir.isDirectory() );
|
||||
}
|
||||
|
||||
public void testAddManagedRepoDirectoryExists()
|
||||
throws IOException
|
||||
{
|
||||
File dir = new File( getRepositoryDir() + "repository-exists/" );
|
||||
dir.mkdirs();
|
||||
Assert.assertTrue( dir.exists() && dir.isDirectory() );
|
||||
|
||||
addManagedRepository( "managedrepo2", "Managed Repository Sample 2", dir.getAbsolutePath(), "",
|
||||
"Maven 2.x Repository", "0 0 * * * ?", "", "" );
|
||||
assertTextPresent( "Managed Repository Sample 2" );
|
||||
|
||||
assertTextPresent( "WARNING: Repository location already exists." );
|
||||
|
||||
clickButtonWithValue( "Save" );
|
||||
|
||||
assertRepositoriesPage();
|
||||
assertTextPresent( "Managed Repository Sample 2" );
|
||||
}
|
||||
|
||||
public void testAddManagedRepoDirectoryExistsCancel()
|
||||
throws IOException
|
||||
{
|
||||
File dir = new File( getRepositoryDir() + "repository-exists/" );
|
||||
dir.mkdirs();
|
||||
Assert.assertTrue( dir.exists() && dir.isDirectory() );
|
||||
|
||||
addManagedRepository( "managedrepo3", "Managed Repository Sample 3", dir.getAbsolutePath(), "",
|
||||
"Maven 2.x Repository", "0 0 * * * ?", "", "" );
|
||||
assertTextPresent( "Managed Repository Sample 3" );
|
||||
assertTextPresent( "WARNING: Repository location already exists." );
|
||||
|
||||
clickButtonWithValue( "Cancel" );
|
||||
|
||||
assertRepositoriesPage();
|
||||
assertTextNotPresent( "Managed Repository Sample 3" );
|
||||
}
|
||||
|
||||
public void testAddManagedRepoInvalidValues()
|
||||
{
|
||||
goToRepositoriesPage();
|
||||
getSelenium().open( "/archiva/admin/addRepository.action" );
|
||||
addManagedRepository( "<> \\/~+[ ]'\"", "<>\\~+[]'\"" , "<> ~+[ ]'\"" , "<> ~+[ ]'\"", "Maven 2.x Repository", "", "-1", "101" );
|
||||
assertTextPresent( "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
|
||||
assertTextPresent( "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
|
||||
|
@ -119,8 +153,6 @@ public class RepositoryTest
|
|||
|
||||
public void testAddManagedRepoBlankValues()
|
||||
{
|
||||
goToRepositoriesPage();
|
||||
getSelenium().open( "/archiva/admin/addRepository.action" ); ;
|
||||
addManagedRepository( "", "" , "" , "", "Maven 2.x Repository", "", "", "" );
|
||||
assertTextPresent( "You must enter a repository identifier." );
|
||||
assertTextPresent( "You must enter a repository name." );
|
||||
|
@ -155,8 +187,6 @@ public class RepositoryTest
|
|||
public void testEditManagedRepo()
|
||||
throws IOException
|
||||
{
|
||||
goToRepositoriesPage();
|
||||
clickLinkWithText( "Add" );
|
||||
String directory = getRepositoryDir() + "local-repo/";
|
||||
File dir = new File( directory );
|
||||
if ( dir.exists() )
|
||||
|
@ -167,10 +197,69 @@ public class RepositoryTest
|
|||
"Maven 2.x Repository", "0 0 * * * ?", "", "" );
|
||||
|
||||
editManagedRepository( "repository.name" , "New Managed Repo Name" );
|
||||
assertRepositoriesPage();
|
||||
assertTextNotPresent( "Managed Repository for Editing" );
|
||||
assertTextPresent( "New Managed Repo Name" );
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testEditManagedRepo")
|
||||
public void testEditManagedRepoDirectoryChangedToNonExistant()
|
||||
throws IOException
|
||||
{
|
||||
goToRepositoriesPage();
|
||||
String directory = getRepositoryDir() + "new-repo-dir/";
|
||||
File dir = new File( directory );
|
||||
if ( dir.exists() )
|
||||
{
|
||||
FileUtils.deleteDirectory( dir );
|
||||
}
|
||||
|
||||
editManagedRepository( "repository.location", dir.getAbsolutePath() );
|
||||
assertRepositoriesPage();
|
||||
assertTextPresent( "new-repo-dir" );
|
||||
Assert.assertTrue( dir.exists() );
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testEditManagedRepo")
|
||||
public void testEditManagedRepoDirectoryChangedToExisting()
|
||||
throws IOException
|
||||
{
|
||||
goToRepositoriesPage();
|
||||
String directory = getRepositoryDir() + "new-repo-dir/";
|
||||
File dir = new File( directory );
|
||||
dir.mkdirs();
|
||||
Assert.assertTrue( dir.exists() && dir.isDirectory() );
|
||||
|
||||
editManagedRepository( "repository.location", dir.getAbsolutePath() );
|
||||
|
||||
assertTextPresent( "WARNING: Repository location already exists." );
|
||||
clickButtonWithValue( "Save" );
|
||||
|
||||
assertRepositoriesPage();
|
||||
assertTextPresent( "new-repo-dir" );
|
||||
Assert.assertTrue( dir.exists() );
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testEditManagedRepo")
|
||||
public void testEditManagedRepoDirectoryChangedToExistingCancel()
|
||||
throws IOException
|
||||
{
|
||||
goToRepositoriesPage();
|
||||
String directory = getRepositoryDir() + "existing-dir/";
|
||||
File dir = new File( directory );
|
||||
dir.mkdirs();
|
||||
Assert.assertTrue( dir.exists() && dir.isDirectory() );
|
||||
|
||||
editManagedRepository( "repository.location", dir.getAbsolutePath() );
|
||||
|
||||
assertTextPresent( "WARNING: Repository location already exists." );
|
||||
clickButtonWithValue( "Cancel" );
|
||||
|
||||
assertRepositoriesPage();
|
||||
assertTextNotPresent( "existing-dir" );
|
||||
Assert.assertTrue( dir.exists() );
|
||||
}
|
||||
|
||||
public void testEditManagedRepoInvalidValues()
|
||||
{
|
||||
editManagedRepository("<>\\~+[]'\"" , "<> ~+[ ]'\"" , "<> ~+[ ]'\"", "Maven 2.x Repository", "", "-1", "101");
|
||||
|
@ -221,8 +310,6 @@ public class RepositoryTest
|
|||
public void testDeleteManagedRepo()
|
||||
throws IOException
|
||||
{
|
||||
goToRepositoriesPage();
|
||||
clickLinkWithText( "Add" );
|
||||
File dir = new File( getRepositoryDir() + "managedrepodelete/" );
|
||||
if ( dir.exists() )
|
||||
{
|
||||
|
@ -243,8 +330,6 @@ public class RepositoryTest
|
|||
public void testDeleteManagedRepoWithContents()
|
||||
throws IOException
|
||||
{
|
||||
goToRepositoriesPage();
|
||||
clickLinkWithText( "Add" );
|
||||
File dir = new File( getRepositoryDir() + "managedrepodeletecontents/" );
|
||||
if ( dir.exists() )
|
||||
{
|
||||
|
|
|
@ -135,8 +135,6 @@ public class XSSSecurityTest
|
|||
|
||||
public void testAddManagedRepositoryImmunityToInputFieldCrossSiteScripting()
|
||||
{
|
||||
goToRepositoriesPage();
|
||||
getSelenium().open( "/archiva/admin/addRepository.action" );
|
||||
addManagedRepository( "test\"><script>alert('xss')</script>", "test\"><script>alert('xss')</script>" , "test\"><script>alert('xss')</script>" , "test\"><script>alert('xss')</script>", "Maven 2.x Repository", "", "-1", "101" );
|
||||
// xss inputs are blocked by validation.
|
||||
assertTextPresent( "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
|
||||
|
|
|
@ -586,8 +586,10 @@ public abstract class AbstractArchivaTest
|
|||
public void addManagedRepository( String identifier, String name, String directory, String indexDirectory,
|
||||
String type, String cron, String daysOlder, String retentionCount )
|
||||
{
|
||||
//goToRepositoriesPage();
|
||||
//clickLinkWithText( "Add" );
|
||||
if (!getSelenium().getLocation().contains( "/archiva/admin/addRepository.action" )) {
|
||||
getSelenium().open( "/archiva/admin/addRepository.action" );
|
||||
}
|
||||
|
||||
setFieldValue( "repository.id", identifier );
|
||||
setFieldValue( "repository.name", name );
|
||||
setFieldValue( "repository.location", directory );
|
||||
|
|
|
@ -49,6 +49,8 @@ public class AddManagedRepositoryAction
|
|||
|
||||
private boolean confirm;
|
||||
|
||||
private boolean cancel;
|
||||
|
||||
public void prepare()
|
||||
{
|
||||
this.repository = new ManagedRepositoryConfiguration();
|
||||
|
@ -68,6 +70,11 @@ public class AddManagedRepositoryAction
|
|||
|
||||
public String commit()
|
||||
{
|
||||
if ( cancel )
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
if ( !confirm )
|
||||
{
|
||||
File location = new File( repository.getLocation() );
|
||||
|
@ -181,4 +188,9 @@ public class AddManagedRepositoryAction
|
|||
{
|
||||
this.confirm = StringUtils.isNotEmpty( confirm );
|
||||
}
|
||||
|
||||
public void setCancel( String cancel )
|
||||
{
|
||||
this.cancel = StringUtils.isNotEmpty( cancel );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,10 @@ public class EditManagedRepositoryAction
|
|||
*/
|
||||
private ArchivaDAO archivaDAO;
|
||||
|
||||
private boolean confirm;
|
||||
|
||||
private boolean cancel;
|
||||
|
||||
public void prepare()
|
||||
{
|
||||
if ( StringUtils.isNotBlank( repoid ) )
|
||||
|
@ -86,14 +90,19 @@ public class EditManagedRepositoryAction
|
|||
return INPUT;
|
||||
}
|
||||
|
||||
public String confirmUpdate()
|
||||
{
|
||||
// location was changed
|
||||
return save( true );
|
||||
}
|
||||
|
||||
public String commit()
|
||||
{
|
||||
if ( cancel )
|
||||
{
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
if ( confirm )
|
||||
{
|
||||
// location was changed
|
||||
return save( true );
|
||||
}
|
||||
|
||||
ManagedRepositoryConfiguration existingConfig =
|
||||
archivaConfiguration.getConfiguration().findManagedRepositoryById( repository.getId() );
|
||||
|
||||
|
@ -239,6 +248,16 @@ public class EditManagedRepositoryAction
|
|||
return "editRepository_commit";
|
||||
}
|
||||
|
||||
public void setConfirm( String confirm )
|
||||
{
|
||||
this.confirm = StringUtils.isNotEmpty( confirm );
|
||||
}
|
||||
|
||||
public void setCancel( String cancel )
|
||||
{
|
||||
this.cancel = StringUtils.isNotEmpty( cancel );
|
||||
}
|
||||
|
||||
// for testing
|
||||
|
||||
public void setArchivaDAO( ArchivaDAO archivaDao )
|
||||
|
|
|
@ -125,16 +125,8 @@
|
|||
<s:hidden name="repository.scanned" value="%{#attr.repository.scanned}"/>
|
||||
<s:hidden name="repository.deleteReleasedSnapshots" value="%{#attr.repository.deleteReleasedSnapshots}"/>
|
||||
|
||||
<c:choose>
|
||||
<c:when test="${action == 'addRepository_commit'}">
|
||||
<s:submit value="Save" name="confirm" />
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<s:submit value="Save" method="confirmUpdate"/>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
|
||||
<s:submit value="Cancel" method="execute"/>
|
||||
<s:submit value="Save" name="confirm" />
|
||||
<s:submit value="Cancel" name="cancel" />
|
||||
</div>
|
||||
</s:form>
|
||||
|
||||
|
|
Loading…
Reference in New Issue