15685: Adds validations to file names to avoid '.' and '..'
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 12 Nov 2020 19:14:07 +0000 (16:14 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 12 Nov 2020 19:14:07 +0000 (16:14 -0300)
Although the backend already does validations, this will provide a better UX
because of the immediate feedback and better error message.

Also, adjusted tests.

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

cypress/integration/collection-panel.spec.js
src/validators/valid-name.tsx

index c20c8ca87e767bfe11fc61311904867eee66f046..63a25a25a92d190669374aaf44aa1985f3c00e1b 100644 (file)
@@ -142,7 +142,8 @@ describe('Collection panel tests', function() {
                 ['bar', '&'],
                 ['&', 'foo'],
                 ['foo', '&amp;'],
-                ['&amp;', 'I ❤️ ⛵️']
+                ['&amp;', 'I ❤️ ⛵️'],
+                ['I ❤️ ⛵️', '...']
             ];
             nameTransitions.forEach(([from, to]) => {
                 cy.get('[data-cy=collection-files-panel]')
@@ -220,27 +221,9 @@ describe('Collection panel tests', function() {
         .as('testCollection').then(function() {
             cy.loginAs(activeUser);
             cy.visit(`/collections/${this.testCollection.uuid}`);
-            const illegalNamesFromBackend = ['.', '..'];
-            illegalNamesFromBackend.forEach((name) => {
-                cy.get('[data-cy=collection-files-panel]')
-                    .contains('bar').rightclick();
-                cy.get('[data-cy=context-menu]')
-                    .contains('Rename')
-                    .click();
-                cy.get('[data-cy=form-dialog]')
-                    .should('contain', 'Rename')
-                    .within(() => {
-                        cy.get('input').type(`{selectall}{backspace}${name}`);
-                    });
-                cy.get('[data-cy=form-submit-btn]').click();
-                cy.get('[data-cy=form-dialog]')
-                    .should('contain', 'Rename')
-                    .within(() => {
-                        cy.contains('Could not rename');
-                    });
-                cy.get('[data-cy=form-cancel-btn]').click();
-            });
             const illegalNamesFromUI = [
+                ['.', "Name cannot be '.' or '..'"],
+                ['..', "Name cannot be '.' or '..'"],
                 ['', 'This field is required'],
                 [' ', 'Leading/trailing whitespaces not allowed'],
                 [' foo', 'Leading/trailing whitespaces not allowed'],
@@ -258,7 +241,6 @@ describe('Collection panel tests', function() {
                     .within(() => {
                         cy.get('input').type(`{selectall}{backspace}${name}`);
                     });
-                cy.get('[data-cy=form-cancel-btn]').focus();
                 cy.get('[data-cy=form-dialog]')
                     .should('contain', 'Rename')
                     .within(() => {
index c3650542714b371348112e6bdc9f15b56eb4b15f..89bb3f96888203691029b322e486cd98b3e0df3f 100644 (file)
@@ -31,7 +31,7 @@ export const validFileName = (value: string) => {
 export const validFilePath = (filePath: string) => {
     const errors = filePath.split('/').map(pathPart => {
         if (pathPart === "") { return "Empty dir name not allowed"; }
-        return validFileName(pathPart);
+        return validNameAllowSlash(pathPart) || validFileName(pathPart);
     });
     return errors.filter(e => e !== undefined)[0];
 };
\ No newline at end of file