Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore : Comprehensive e2e testing for public sharing #50260

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/files_sharing/src/components/SharingEntryLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
:disabled="pendingEnforcedExpirationDate || saving"
class="share-link-expiration-date-checkbox"
@change="onDefaultExpirationDateEnabledChange">
{{ config.enforcePasswordForPublicLink ? t('files_sharing', 'Enable link expiration (enforced)') : t('files_sharing', 'Enable link expiration') }}
{{ config.isDefaultExpireDateEnforced ? t('files_sharing', 'Enable link expiration (enforced)') : t('files_sharing', 'Enable link expiration') }}
</NcActionCheckbox>

<!-- expiration date -->
Expand Down
18 changes: 18 additions & 0 deletions cypress/e2e/files_sharing/ShareOptionsType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

export type ShareOptions = {
nfebe marked this conversation as resolved.
Show resolved Hide resolved
enforcePassword?: boolean
enforceExpirationDate?: boolean
alwaysAskForPassword?: boolean
defaultExpirationDateSet?: boolean
}

export const defaultShareOptions: ShareOptions = {
enforcePassword: false,
enforceExpirationDate: false,
alwaysAskForPassword: false,
defaultExpirationDateSet: false,
}
187 changes: 187 additions & 0 deletions cypress/e2e/files_sharing/public-share/required-before-create.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { ShareContext } from './setup-public-share.ts'
import type { ShareOptions } from '../ShareOptionsType.ts'
import { setupData, createShare } from './setup-public-share.ts'

describe('files_sharing: Before create checks', () => {

let shareContext: ShareContext

before(() => {
// Setup data for the shared folder once before all tests
cy.createRandomUser().then((randomUser) => {
shareContext = {
user: randomUser,
}
})
})

afterEach(() => {
cy.runOccCommand('config:app:delete core shareapi_enable_link_password_by_default')
cy.runOccCommand('config:app:delete core shareapi_enforce_links_password')
cy.runOccCommand('config:app:delete core shareapi_default_expire_date')
cy.runOccCommand('config:app:delete core shareapi_enforce_expire_date')
cy.runOccCommand('config:app:delete core shareapi_expire_after_n_days')
})

const applyShareOptions = (options: ShareOptions): void => {
cy.runOccCommand(`config:app:set --value ${options.alwaysAskForPassword ? 'yes' : 'no'} core shareapi_enable_link_password_by_default`)
cy.runOccCommand(`config:app:set --value ${options.enforcePassword ? 'yes' : 'no'} core shareapi_enforce_links_password`)
cy.runOccCommand(`config:app:set --value ${options.enforceExpirationDate ? 'yes' : 'no'} core shareapi_enforce_expire_date`)
cy.runOccCommand(`config:app:set --value ${options.defaultExpirationDateSet ? 'yes' : 'no'} core shareapi_default_expire_date`)
if (options.defaultExpirationDateSet) {
cy.runOccCommand('config:app:set --value 2 core shareapi_expire_after_n_days')
}
}

it('Checks if user can create share when both password and expiration date are enforced', () => {
const shareOptions : ShareOptions = {
alwaysAskForPassword: true,
enforcePassword: true,
enforceExpirationDate: true,
defaultExpirationDateSet: true,
}
applyShareOptions(shareOptions)
const shareName = 'passwordAndExpireEnforced'
setupData(shareContext, shareName)
createShare(shareContext, shareName, shareOptions).then((shareUrl) => {
shareContext.url = shareUrl
cy.log(`Created share with URL: ${shareUrl}`)
})
})

it('Checks if user can create share when password is enforced and expiration date has a default set', () => {
const shareOptions : ShareOptions = {
alwaysAskForPassword: true,
enforcePassword: true,
defaultExpirationDateSet: true,
}
applyShareOptions(shareOptions)
const shareName = 'passwordEnforcedDefaultExpire'
setupData(shareContext, shareName)
createShare(shareContext, shareName).then((shareUrl) => {
shareContext.url = shareUrl
cy.log(`Created share with URL: ${shareUrl}`)
})
})

it('Checks if user can create share when password is optionally requested and expiration date is enforced', () => {
const shareOptions : ShareOptions = {
alwaysAskForPassword: true,
enforceExpirationDate: true,
}
applyShareOptions(shareOptions)
const shareName = 'defaultPasswordExpireEnforced'
setupData(shareContext, shareName)
createShare(shareContext, shareName, shareOptions).then((shareUrl) => {
shareContext.url = shareUrl
cy.log(`Created share with URL: ${shareUrl}`)
})
})

it('Checks if user can create share when password is optionally requested and expiration date have defaults set', () => {
const shareOptions : ShareOptions = {
alwaysAskForPassword: true,
defaultExpirationDateSet: true,
}
applyShareOptions(shareOptions)
const shareName = 'defaultPasswordAndExpire'
setupData(shareContext, shareName)
createShare(shareContext, shareName).then((shareUrl) => {
shareContext.url = shareUrl
cy.log(`Created share with URL: ${shareUrl}`)
})
})

it('Checks if user can create share with password enforced and expiration date set but not enforced', () => {
const shareOptions : ShareOptions = {
alwaysAskForPassword: true,
enforcePassword: true,
defaultExpirationDateSet: true,
enforceExpirationDate: false,
}
applyShareOptions(shareOptions)
const shareName = 'passwordEnforcedExpireSetNotEnforced'
setupData(shareContext, shareName)
createShare(shareContext, shareName, shareOptions).then((shareUrl) => {
shareContext.url = shareUrl
cy.log(`Created share with URL: ${shareUrl}`)
})
})

it('Checks if user can create share with both password and expiration date not enforced, but defaults set', () => {
const shareOptions : ShareOptions = {
enforcePassword: false,
enforceExpirationDate: false,
defaultExpirationDateSet: true,
alwaysAskForPassword: true,
}
const shareName = 'defaultPasswordExpireNotEnforced'
setupData(shareContext, shareName)
createShare(shareContext, shareName, shareOptions).then((shareUrl) => {
shareContext.url = shareUrl
cy.log(`Created share with URL: ${shareUrl}`)
})
})

it('Checks if user can create share with password not enforced but expiration date enforced', () => {
const shareOptions : ShareOptions = {
alwaysAskForPassword: true,
enforcePassword: false,
defaultExpirationDateSet: true,
enforceExpirationDate: true,
}
applyShareOptions(shareOptions)
const shareName = 'noPasswordExpireEnforced'
setupData(shareContext, shareName)
createShare(shareContext, shareName, shareOptions).then((shareUrl) => {
shareContext.url = shareUrl
cy.log(`Created share with URL: ${shareUrl}`)
})
})

it('Checks if user can create share with password not enforced and expiration date has a default set', () => {
const shareOptions : ShareOptions = {
enforcePassword: false,
defaultExpirationDateSet: true,
}
applyShareOptions(shareOptions)
const shareName = 'defaultExpireNoPasswordEnforced'
setupData(shareContext, shareName)
createShare(shareContext, shareName, shareOptions).then((shareUrl) => {
shareContext.url = shareUrl
cy.log(`Created share with URL: ${shareUrl}`)
})
})

it('Checks if user can create share with expiration date set and password not enforced', () => {
const shareOptions : ShareOptions = {
alwaysAskForPassword: true,
enforcePassword: false,
defaultExpirationDateSet: true,
}
applyShareOptions(shareOptions)

const shareName = 'noPasswordExpireDefault'
setupData(shareContext, shareName)
createShare(shareContext, shareName, shareOptions).then((shareUrl) => {
shareContext.url = shareUrl
cy.log(`Created share with URL: ${shareUrl}`)
})
})

it('Checks if user can create share with password not enforced, expiration date not enforced, and no defaults set', () => {
applyShareOptions()
const shareName = 'noPasswordNoExpireNoDefaults'
setupData(shareContext, shareName)
createShare(shareContext, shareName, null).then((shareUrl) => {
shareContext.url = shareUrl
cy.log(`Created share with URL: ${shareUrl}`)
})
})

})
Loading
Loading