From c723f814afe9d4ffde7bf4d7045c948c90816664 Mon Sep 17 00:00:00 2001 From: Kiran Parajuli Date: Wed, 11 Mar 2020 14:36:23 +0545 Subject: [PATCH] Added acceptance tests for enforced expiration on collaborator shares --- .../shareWithGroups.feature | 49 +++++++++- .../shareWithUsers.feature | 96 ++++++++++++++++++- .../FilesPageElement/expirationDatePicker.js | 34 ++++--- .../FilesPageElement/publicLinksDialog.js | 13 ++- .../FilesPageElement/sharingDialog.js | 91 ++++++++++++------ .../stepDefinitions/publicLinkContext.js | 10 +- .../stepDefinitions/sharingContext.js | 42 +++++++- 7 files changed, 276 insertions(+), 59 deletions(-) diff --git a/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature b/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature index 91f32fa1139..90ab43e6a01 100644 --- a/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature +++ b/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature @@ -358,7 +358,7 @@ Feature: Sharing files and folders with internal groups And user "user3" has logged in using the webUI When the user edits the collaborator expiry date of "grp1" of file "lorem.txt" to "+7" days using the webUI Then user "user1" should have received a share with target "lorem (2).txt" and expiration date in 7 days - Then user "user2" should have received a share with target "lorem (2).txt" and expiration date in 7 days + And user "user2" should have received a share with target "lorem (2).txt" and expiration date in 7 days And user "user3" should have a share with these details: | field | value | | path | /lorem.txt | @@ -367,3 +367,50 @@ Feature: Sharing files and folders with internal groups | share_with | grp1 | | expiration | +7 | + Scenario: share a resource with another internal group with default expiration date + Given the setting "shareapi_default_expire_date_group_share" of app "core" has been set to "yes" + And the setting "shareapi_expire_after_n_days_group_share" of app "core" has been set to "42" + And user "user3" has logged in using the webUI + When the user shares folder "lorem.txt" with group "grp1" as "Viewer" using the webUI + Then user "user3" should have a share with these details: + | field | value | + | path | /lorem.txt | + | share_type | group | + | uid_owner | user3 | + | share_with | grp1 | + | expiration | +42 | + And user "user1" should have received a share with target "lorem (2).txt" and expiration date in 42 days + And user "user2" should have received a share with target "lorem (2).txt" and expiration date in 42 days + + Scenario Outline: share a resource with another internal group with expiration date beyond maximum enforced expiration date + Given the setting "shareapi_default_expire_date_group_share" of app "core" has been set to "yes" + And the setting "shareapi_enforce_expire_date_group_share" of app "core" has been set to "yes" + And the setting "shareapi_expire_after_n_days_group_share" of app "core" has been set to "5" + And user "user3" has logged in using the webUI + When the user tries to share resource "" with group "grp1" which expires in "+6" days using the webUI + Then the expiration date shown on the webUI should be "+5" days + And user "user1" should not have created any shares + Examples: + | shared-resource | + | lorem.txt | + | simple-folder | + + Scenario Outline: share a resource with another internal group with expiration date within maximum enforced expiration date + Given the setting "shareapi_default_expire_date_group_share" of app "core" has been set to "yes" + And the setting "shareapi_enforce_expire_date_group_share" of app "core" has been set to "yes" + And the setting "shareapi_expire_after_n_days_group_share" of app "core" has been set to "5" + And user "user3" has created a new share with following settings + | path | | + | shareTypeString | group | + | shareWith | grp1 | + | expireDate | +4 | + And user "user3" has logged in using the webUI + When the user tries to edit the collaborator expiry date of "grp1" of resource "" to "+7" days using the webUI + Then the expiration date shown on the webUI should be "+4" days + And it should not be possible to save the pending share on the webUI + And user "user1" should have received a share with target "" and expiration date in 4 days + And user "user2" should have received a share with target "" and expiration date in 4 days + Examples: + | shared-resource | target-resource | + | lorem.txt | lorem (2).txt | + | simple-folder | simple-folder (2) | diff --git a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature index 71a0fe548fd..d1866411ab6 100644 --- a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature +++ b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature @@ -593,7 +593,7 @@ Feature: Sharing files and folders with internal users Scenario: share a file with another internal user which should expire after 2 days Given user "user1" has logged in using the webUI - When the user shares file "testimage.jpg" with user "User Two" which expires after 2 days using the webUI + When the user shares file "testimage.jpg" with user "User Two" which expires in "+2" days using the webUI Then user "user2" should have received a share with target "testimage (2).jpg" and expiration date in 2 days Scenario: share a file with another internal user with default expiration date @@ -618,3 +618,97 @@ Feature: Sharing files and folders with internal users | uid_owner | user1 | | share_with | user2 | | expiration | +7 | + + Scenario: share a resource with another internal user with expiration date within enforced maximum expiration date + Given the setting "shareapi_default_expire_date_user_share" of app "core" has been set to "yes" + And the setting "shareapi_enforce_expire_date_user_share" of app "core" has been set to "yes" + And the setting "shareapi_expire_after_n_days_user_share" of app "core" has been set to "5" + And user "user1" has logged in using the webUI + When the user shares file "lorem.txt" with user "User Two" which expires in "+4" days using the webUI + Then user "user1" should have a share with these details: + | field | value | + | path | /lorem.txt | + | share_type | user | + | uid_owner | user1 | + | share_with | user2 | + | expiration | +4 | + + Scenario Outline: share a resource with another internal user with expiration date beyond enforced maximum expiration date + Given the setting "shareapi_default_expire_date_user_share" of app "core" has been set to "yes" + And the setting "shareapi_enforce_expire_date_user_share" of app "core" has been set to "yes" + And the setting "shareapi_expire_after_n_days_user_share" of app "core" has been set to "5" + And user "user1" has logged in using the webUI + When the user tries to share resource "" with user "User Two" which expires in "+6" days using the webUI + Then the expiration date shown on the webUI should be "+5" days + And user "user1" should not have created any shares + Examples: + | shared-resource | + | lorem.txt | + | simple-folder | + + Scenario Outline: edit a share with another internal user changing expiration date within enforced maximum expiration date + Given the setting "shareapi_default_expire_date_user_share" of app "core" has been set to "yes" + And the setting "shareapi_enforce_expire_date_user_share" of app "core" has been set to "yes" + And the setting "shareapi_expire_after_n_days_user_share" of app "core" has been set to "5" + And user "user1" has created a new share with following settings + | path | | + | shareWith | user2 | + | expireDate | +4 | + And user "user1" has logged in using the webUI + When the user tries to edit the collaborator expiry date of "User Two" of resource "" to "+7" days using the webUI + Then the expiration date shown on the webUI should be "+4" days + And it should not be possible to save the pending share on the webUI + Examples: + | shared-resource | + | lorem.txt | + | simple-folder | + + @issue-3174 + Scenario Outline: enforced expiry date for group affect user shares + Given the setting "shareapi_default_expire_date_user_share" of app "core" has been set to "yes" + And the setting "shareapi_default_expire_date_group_share" of app "core" has been set to "yes" + And the setting "shareapi_enforce_expire_date_user_share" of app "core" has been set to "yes" + And the setting "shareapi_enforce_expire_date_group_share" of app "core" has been set to "yes" + And the setting "shareapi_expire_after_n_days_user_share" of app "core" has been set to "10" + And the setting "shareapi_expire_after_n_days_group_share" of app "core" has been set to "5" + And user "user1" has logged in using the webUI + When the user tries to share resource "" with user "User Two" which expires in "+6" days using the webUI + Then the expiration date shown on the webUI should be "+5" days +# Then the expiration date shown on the webUI should be "+6" days +# Then user "user1" should have a share with these details: +# | field | value | +# | path | | +# | share_type | user | +# | uid_owner | user1 | +# | share_with | user2 | +# | expiration | +6 | + Examples: + | shared-resource | + | lorem.txt | + | simple-folder | + + @issue-3174 + Scenario Outline: enforced expiry date for users affect group sharess + Given group "grp1" has been created + And user "user2" has been added to group "grp1" + And the setting "shareapi_default_expire_date_user_share" of app "core" has been set to "yes" + And the setting "shareapi_default_expire_date_group_share" of app "core" has been set to "yes" + And the setting "shareapi_enforce_expire_date_user_share" of app "core" has been set to "yes" + And the setting "shareapi_enforce_expire_date_group_share" of app "core" has been set to "yes" + And the setting "shareapi_expire_after_n_days_user_share" of app "core" has been set to "5" + And the setting "shareapi_expire_after_n_days_group_share" of app "core" has been set to "10" + And user "user1" has logged in using the webUI + When the user tries to share resource "" with group "grp1" which expires in "+6" days using the webUI + Then the expiration date shown on the webUI should be "+5" days +# Then the expiration date shown on the webUI should be "+6" days +# Then user "user1" should have a share with these details: +# | field | value | +# | path | | +# | share_type | group | +# | uid_owner | user1 | +# | share_with | grp1 | +# | expiration | +6 | + Examples: + | shared-resource | + | lorem.txt | + | simple-folder | diff --git a/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js b/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js index 2962405564a..31843d9f2c2 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js +++ b/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js @@ -1,5 +1,4 @@ const util = require('util') -const sharingHelper = require('../../helpers/sharingHelper') module.exports = { commands: { @@ -105,11 +104,8 @@ module.exports = { const monthSelector = this.setExpiryDateMonthSelectorXpath( pastDate.toLocaleString('en-GB', { month: 'long' }) ) - const daySelector = this.setExpiryDateDaySelectorXpath(pastDate.getDay()) + const daySelector = this.setExpiryDateDaySelectorXpath(pastDate.getDate()) await this - .initAjaxCounters() - .waitForElementVisible('@linkExpirationDateField') - .click('@linkExpirationDateField') .waitForElementVisible('@dateTimePopupYear') .waitForAnimationToFinish() .waitForElementEnabled( @@ -150,25 +146,32 @@ module.exports = { * sets expiration date on collaborators/public-link shares * * @param {string} value - provided date in format YYYY-MM-DD, or empty string to unset date - * @returns {Promise} + * @param {string} shareType link|collaborator + * @returns {Promise} returns true if succeeds to set provided expiration date */ - setExpirationDate: async function (value) { + setExpirationDate: async function (value, shareType = 'collaborator') { if (value === '') { return this.click('@publicLinkDeleteExpirationDateButton') } - value = sharingHelper.calculateDate(value) const dateToSet = new Date(Date.parse(value)) + if (shareType === 'collaborator') { + const disabled = await this.isExpiryDateDisabled(dateToSet) + if (disabled) { + console.log('WARNING: Cannot change expiration date to disabled value!') + await this + .waitForElementVisible('@dateTimeCancelButton') + .click('@dateTimeCancelButton') + return false + } + } const year = dateToSet.getFullYear() const month = dateToSet.toLocaleString('en-GB', { month: 'long' }) const day = dateToSet.getDate() await this - .initAjaxCounters() - .waitForElementVisible('@linkExpirationDateField') - .click('@linkExpirationDateField') - return this .setExpiryDateYear(year) .setExpiryDateMonth(month) .setExpiryDateDay(day) + return true } }, elements: { @@ -191,12 +194,13 @@ module.exports = { selector: '//div[@class="vdatetime-popup__actions"]/div[.="Ok"]', locateStrategy: 'xpath' }, + dateTimeCancelButton: { + selector: '//div[@class="vdatetime-popup__actions"]/div[.="Cancel"]', + locateStrategy: 'xpath' + }, dateTimePopupDate: { selector: '.vdatetime-popup__date' }, - linkExpirationDateField: { - selector: '.vdatetime-input' - }, publicLinkDeleteExpirationDateButton: { selector: '#oc-files-file-link-expire-date-delete' } diff --git a/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js b/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js index 4e403122fbd..b6b83f5da76 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js +++ b/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js @@ -1,5 +1,6 @@ const util = require('util') const _ = require('lodash') +const sharingHelper = require('../../helpers/sharingHelper') module.exports = { commands: { @@ -79,10 +80,12 @@ module.exports = { } else if (key === 'password') { return this.setPublicLinkPassword(value) } else if (key === 'expireDate') { + value = sharingHelper.calculateDate(value) return this.api.page .FilesPageElement - .expirationDatePicker() - .setExpirationDate(value) + .sharingDialog() + .openExpirationDatePicker() + .setExpirationDate(value, 'link') } return this }, @@ -97,10 +100,10 @@ module.exports = { * @param {string} editData.expireDate - Expire date for a public link share * @returns {exports} */ - editPublicLink: function (linkName, editData) { - this.clickLinkEditBtn(linkName) + editPublicLink: async function (linkName, editData) { + await this.clickLinkEditBtn(linkName) for (const [key, value] of Object.entries(editData)) { - this.setPublicLinkForm(key, value) + await this.setPublicLinkForm(key, value) } return this }, diff --git a/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js b/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js index 21b52e9f313..10c8d3ea492 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js +++ b/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js @@ -1,6 +1,6 @@ const util = require('util') const _ = require('lodash') -const { COLLABORATOR_PERMISSION_ARRAY } = require('../../helpers/sharingHelper') +const { COLLABORATOR_PERMISSION_ARRAY, calculateDate } = require('../../helpers/sharingHelper') const { client } = require('nightwatch-api') const collaboratorDialog = client.page.FilesPageElement.SharingDialog.collaboratorsDialog() const SHARE_TYPE_STRING = { @@ -79,8 +79,9 @@ module.exports = { /** * - * @param {string} sharee + * @param {string} receiver * @param {boolean} [shareWithGroup=false] + * @param {boolean} remoteShare */ selectCollaboratorForShare: async function (receiver, shareWithGroup = false, remoteShare = false) { let sharee = receiver @@ -127,33 +128,16 @@ module.exports = { return this }, - /** - * @param {int} days - */ - selectExpirationDaysOnPendingShare: async function (days) { - const currentDate = new Date() - const currentDay = currentDate.getDate() - const currentMonth = currentDate.getMonth() - const expirationDate = new Date(currentDate.setDate(currentDay + days)) - const dateSelector = util.format(this.elements.collaboratorExpirationDateModalDay.selector, expirationDate.getDate()) - - if (expirationDate.getMonth() !== currentMonth) { - await this.click('@collaboratorExpirationDateModalNextMonthButton') - } - - await this.click('@collaboratorExpirationDateInput') - await this.useXpath().click(dateSelector) - await this.click('@collaboratorExpirationDateModalConfirmButton') - - return this - }, - /** * * @param {string} sharee * @param {boolean} shareWithGroup * @param {string} role * @param {string} permissions + * @param {boolean} remote + * @param {string} days + * + * @return void */ shareWithUserOrGroup: async function (sharee, shareWithGroup = false, role, permissions, remote = false, days) { await collaboratorDialog.clickCreateShare() @@ -165,7 +149,14 @@ module.exports = { } if (days) { - await this.selectExpirationDaysOnPendingShare(days) + const dateToSet = calculateDate(days) + const isExpiryDateChanged = await this + .openExpirationDatePicker() + .setExpirationDate(dateToSet) + if (!isExpiryDateChanged) { + console.log('WARNING: Cannot create share with disabled expiration date!') + return + } } return this.confirmShare() @@ -494,11 +485,52 @@ module.exports = { */ changeCollaboratorExpiryDate: async function (collaborator, days) { await collaboratorDialog.clickEditShare(collaborator) - await this.api.page - .FilesPageElement - .expirationDatePicker() - .setExpirationDate(days) + const dateToSet = calculateDate(days) + const isExpiryDateChanged = await this + .openExpirationDatePicker() + .setExpirationDate(dateToSet) + if (!isExpiryDateChanged) { + console.log('WARNING: Cannot create share with disabled expiration date!') + return + } return this.saveChanges() + }, + /** + * opens expiration date field on the webUI + * @return {*} + */ + openExpirationDatePicker: function () { + this + .initAjaxCounters() + .waitForElementVisible('@expirationDateField') + .click('@expirationDateField') + return client.page.FilesPageElement.expirationDatePicker() + }, + /** + * extracts set value in expiration date field + * @return {Promise<*>} + */ + getExpirationDateFromInputField: async function () { + let expirationDate + await this + .waitForElementVisible('@expirationDateField') + .getValue('@expirationDateField', (result) => { + expirationDate = result.value + }) + return expirationDate + }, + /** + * gets disabled status of save share button + * @return {Promise<*>} + */ + getDisabledAttributeOfSaveShareButton: async function () { + let disabled + await this + .waitForElementVisible('@saveShareButton') + .getAttribute('@saveShareButton', 'disabled', (result) => { + disabled = result.value + }) + return disabled } }, elements: { @@ -612,6 +644,9 @@ module.exports = { collaboratorsListItemName: { selector: '//span[contains(@class, "files-collaborators-collaborator-name") and text()="%s"]', locateStrategy: 'xpath' + }, + expirationDateField: { + selector: '.vdatetime-input' } } } diff --git a/tests/acceptance/stepDefinitions/publicLinkContext.js b/tests/acceptance/stepDefinitions/publicLinkContext.js index ba88d7aa4cd..1eb1492d1ca 100644 --- a/tests/acceptance/stepDefinitions/publicLinkContext.js +++ b/tests/acceptance/stepDefinitions/publicLinkContext.js @@ -128,15 +128,17 @@ When('the user edits the public link named {string} of file/folder/resource {str When('the user tries to edit expiration of the public link named {string} of file {string} to past date {string}', async function (linkName, resource, pastDate) { - await client.page.FilesPageElement + const api = client.page.FilesPageElement + await api .appSideBar() .closeSidebar(100) .openPublicLinkDialog(resource) - await client.page.FilesPageElement.publicLinksDialog().clickLinkEditBtn(linkName) + await api.publicLinksDialog().clickLinkEditBtn(linkName) const value = sharingHelper.calculateDate(pastDate) const dateToSet = new Date(Date.parse(value)) - const isDisabled = await client.page.FilesPageElement - .expirationDatePicker() + const isDisabled = await api + .sharingDialog() + .openExpirationDatePicker() .isExpiryDateDisabled(dateToSet) return assert.ok( isDisabled, diff --git a/tests/acceptance/stepDefinitions/sharingContext.js b/tests/acceptance/stepDefinitions/sharingContext.js index 5c516ff9f9b..c09b665538d 100644 --- a/tests/acceptance/stepDefinitions/sharingContext.js +++ b/tests/acceptance/stepDefinitions/sharingContext.js @@ -325,9 +325,10 @@ const assertUsersGroupsWithPatternInAutocompleteListExcluding = async function ( * * @param {string} resource * @param {string} sharee - * @param {int} days + * @param {string} days * @param {boolean} shareWithGroup * @param {boolean} remote + * @param {boolean} expectToSucceed */ const userSharesFileOrFolderWithUserOrGroupWithExpirationDate = async function ({ resource, sharee, days, shareWithGroup = false, remote = false @@ -777,7 +778,7 @@ When( } ) -When('the user edits the collaborator expiry date of {string} of file/folder/resource {string} to {string} days/day using the webUI', +When('the user (tries to )edit/edits the collaborator expiry date of {string} of file/folder/resource {string} to {string} days/day using the webUI', async function (collaborator, resource, days) { const api = client.page.FilesPageElement await api @@ -994,9 +995,15 @@ Then('the following resources should have the following collaborators', async fu } }) -When('the user shares file/folder/resource {string} with user {string} which expires after {int} day/days using the webUI', function (resource, sharee, days) { - return userSharesFileOrFolderWithUserOrGroupWithExpirationDate({ resource, sharee, days }) -}) +When('the user (tries to )share/shares file/folder/resource {string} with user {string} which expires in {string} day/days using the webUI', + function (resource, sharee, days) { + return userSharesFileOrFolderWithUserOrGroupWithExpirationDate({ resource, sharee, days }) + }) + +When('the user (tries to )share/shares file/folder/resource {string} with group {string} which expires in {string} day/days using the webUI', + function (resource, sharee, days) { + return userSharesFileOrFolderWithUserOrGroupWithExpirationDate({ resource, sharee, days, shareWithGroup: true }) + }) When('the user shares file/folder/resource {string} with user {string} using the webUI', function (resource, user) { return userSharesFileOrFolderWithUser(resource, user, 'Viewer') @@ -1009,3 +1016,28 @@ Then('the fields of the {string} collaborator for file/folder/resource {string} Then('user {string} should have received a share with target {string} and expiration date in {int} day/days', function (user, target, days) { return checkReceivedSharesExpirationDate(user, target, days) }) + +Then('the expiration date shown on the webUI should be {string} days', + async function (expectedDays) { + let expectedDate = sharingHelper.calculateDate(expectedDays) + expectedDate = new Date((Date.parse(expectedDate))) + const expectedDateString = expectedDate.toLocaleString('en-GB', { month: 'short' }) + ' ' + + (expectedDate.getDate()).toString() + ', ' + expectedDate.getFullYear() + const dateStringFromInputField = await client.page.FilesPageElement + .sharingDialog() + .getExpirationDateFromInputField() + assert.strictEqual( + expectedDateString, + dateStringFromInputField, + `Expected: Expiration date field with ${expectedDateString}, but found ${dateStringFromInputField}` + ) + }) + +Then('it should not be possible to save the pending share on the webUI', async function () { + const state = await client.page.FilesPageElement.sharingDialog().getDisabledAttributeOfSaveShareButton() + assert.strictEqual( + 'true', + state, + 'Expected: save share button to be disabled but got enabled' + ) +})