]> source.dussan.org Git - archiva.git/commitdiff
ensure confirm directory overwrite works without DMI
authorBrett Porter <brett@apache.org>
Sun, 2 Feb 2014 02:39:24 +0000 (02:39 +0000)
committerBrett Porter <brett@apache.org>
Sun, 2 Feb 2014 02:39:24 +0000 (02:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-1.3.x@1563553 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RepositoryTest.java
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/XSSSecurityTest.java
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/confirmAddRepository.jsp

index a7842c73f9dd024c8f44055493b4b84e9a66f810..bc2819f6b783a194cf547b07754d19ce34fc18dd 100644 (file)
@@ -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() )
         {
index 2e57090c97d5019ea336402a898dc6657db71fe3..52d1c3bc1e9f581c5a1005d2edbd23c8be91cb8c 100644 (file)
@@ -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(-)." );
index af956ae5ded4c8d30e3898d59cc47ab3fe99b5f5..a39b54bc774fa8116f7a8dd58555c9b946c2b2b3 100644 (file)
@@ -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 );
index 2fbb5ff7bb85b7f931abf36e0f5c3958dd0fc1e3..a0568107d4a87e81bdaa20127e6e8a41501ce5c2 100644 (file)
@@ -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 );
+    }
 }
index 030cd1d398da2e59eb0a83c8bc07aa2f55091906..a52b0e8570ef2fb149de001e63ee4677fd3d16ae 100644 (file)
@@ -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 )
index 8b374409caead2034a05efe358437ad67429aa9c..a54f9b4d74552861229831dbddba62e214b4c034 100644 (file)
       <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>