forked from owncloud/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request owncloud#6461 from owncloud/unauthorizedUserOpenPu…
…blicLink [tests-only] Add e2e test for unauthorized user opening public link
- Loading branch information
Showing
7 changed files
with
179 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint-disable */ | ||
export * as sidebar from './sidebar' | ||
export * from './misc' | ||
export * from './publicLink' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { DataTable } from '@cucumber/cucumber' | ||
import { PublicLinkPage } from '../../page/publicLinkPage' | ||
import { filesCta } from '../../cta' | ||
|
||
export const checkResourcesExistence = async ({ | ||
actionType, | ||
stepTable, | ||
pageType = 'public' | ||
}: { | ||
actionType: string | ||
stepTable: DataTable | ||
pageType?: string | ||
}): Promise<void> => { | ||
const publicLinkPage = new PublicLinkPage() | ||
actionType = actionType.trim() | ||
|
||
const files = stepTable.raw().map((f) => f[0]) | ||
for (const file of files) { | ||
const resourceExist = await publicLinkPage.resourceExists({ | ||
pageType, | ||
name: file | ||
}) | ||
filesCta.resourceExistenceErrorMessage(actionType, resourceExist, file) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { errors, Page } from 'playwright' | ||
import util from 'util' | ||
import { state } from '../../cucumber/environment/shared' | ||
import { PublicLink } from './files/publicLink' | ||
|
||
export class PublicLinkPage { | ||
private static page: Page | ||
private readonly passwordInput: string | ||
private readonly passwordSubmitButton: string | ||
private readonly fileUploadInput: string | ||
private publicResourceSelector: string | ||
private uploadedResourceSelector: string | ||
|
||
constructor() { | ||
this.passwordInput = 'input[type="password"]' | ||
this.passwordSubmitButton = | ||
'//*[@id="password-submit"]|//*[@id="oc-textinput-3"]/ancestor::div[contains(@class, "oc-mb-s")]/following-sibling::button' | ||
this.publicResourceSelector = `[data-test-resource-name="%s"]` | ||
this.uploadedResourceSelector = `//tbody/tr/td[contains(@class, "oc-pl-rm") and contains(text(), "%s")]` | ||
this.fileUploadInput = '//input[@id="file_upload_start" or @class="dz-hidden-input"]' | ||
} | ||
|
||
public static async setup(): Promise<PublicLinkPage> { | ||
PublicLinkPage.page = await state.browser | ||
.newContext({ ignoreHTTPSErrors: true }) | ||
.then((context) => context.newPage()) | ||
return new PublicLinkPage() | ||
} | ||
|
||
async navigateToPublicLink(): Promise<void> { | ||
await PublicLinkPage.page.goto(PublicLink.getLastCreatedPublicLink()) | ||
} | ||
|
||
async authenticatePassword(password: string): Promise<void> { | ||
await PublicLinkPage.page.locator(this.passwordInput).fill(password) | ||
await PublicLinkPage.page.locator(this.passwordSubmitButton).click() | ||
} | ||
|
||
async resourceExists({ pageType, name, timeout = 500 }): Promise<boolean> { | ||
let exist = true | ||
let resourceSelector | ||
if (pageType === 'upload') { | ||
resourceSelector = this.uploadedResourceSelector | ||
} else { | ||
resourceSelector = this.publicResourceSelector | ||
} | ||
|
||
await PublicLinkPage.page | ||
.waitForSelector(util.format(resourceSelector, name), { timeout }) | ||
.catch((e) => { | ||
if (!(e instanceof errors.TimeoutError)) { | ||
throw e | ||
} | ||
|
||
exist = false | ||
}) | ||
|
||
return exist | ||
} | ||
|
||
async uploadFiles(filePath: string): Promise<void> { | ||
await PublicLinkPage.page.locator(this.fileUploadInput).setInputFiles(filePath) | ||
} | ||
|
||
async reload(): Promise<void> { | ||
await PublicLinkPage.page.reload() | ||
} | ||
} |