-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
SWC-6560: discussions e2e test
- Loading branch information
Showing
9 changed files
with
688 additions
and
46 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/ACCESS_TYPE.html | ||
*/ | ||
export enum ACCESS_TYPE { | ||
CREATE = 'CREATE', | ||
READ = 'READ', | ||
UPDATE = 'UPDATE', | ||
DELETE = 'DELETE', | ||
CHANGE_PERMISSIONS = 'CHANGE_PERMISSIONS', | ||
DOWNLOAD = 'DOWNLOAD', | ||
/** | ||
* @deprecated | ||
*/ | ||
UPLOAD = 'UPLOAD', | ||
PARTICIPATE = 'PARTICIPATE', | ||
SUBMIT = 'SUBMIT', | ||
READ_PRIVATE_SUBMISSION = 'READ_PRIVATE_SUBMISSION', | ||
UPDATE_SUBMISSION = 'UPDATE_SUBMISSION', | ||
DELETE_SUBMISSION = 'DELETE_SUBMISSION', | ||
TEAM_MEMBERSHIP_UPDATE = 'TEAM_MEMBERSHIP_UPDATE', | ||
SEND_MESSAGE = 'SEND_MESSAGE', | ||
CHANGE_SETTINGS = 'CHANGE_SETTINGS', | ||
MODERATE = 'MODERATE', | ||
/** Allows to review a group of submissions (e.g. on ARs) for a given object */ | ||
REVIEW_SUBMISSIONS = 'REVIEW_SUBMISSIONS', | ||
} | ||
|
||
export default ACCESS_TYPE |
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,55 @@ | ||
import { Page } from '@playwright/test' | ||
import ACCESS_TYPE from './ACCESS_TYPE' | ||
import { AccessControlList, ResourceAccess } from './types' | ||
import { waitForSrcEndpointConfig } from './utils' | ||
|
||
// https://rest-docs.synapse.org/rest/GET/entity/id/acl.html | ||
async function getEntityACL(page: Page, entityId: string, accessToken: string) { | ||
await waitForSrcEndpointConfig(page) | ||
const acl = await page.evaluate( | ||
async ({ entityId, accessToken }) => { | ||
// @ts-expect-error: Cannot find name 'SRC' | ||
return await SRC.SynapseClient.getEntityACL(entityId, accessToken) | ||
}, | ||
{ entityId, accessToken }, | ||
) | ||
return acl as AccessControlList | ||
} | ||
|
||
/** | ||
* Update an Entity's ACL | ||
* Note: The caller must be granted ACCESS_TYPE.CHANGE_PERMISSIONS on the Entity to call this method. | ||
* https://rest-docs.synapse.org/rest/PUT/entity/id/acl.html | ||
*/ | ||
async function updateEntityACL( | ||
page: Page, | ||
acl: AccessControlList, | ||
accessToken: string, | ||
) { | ||
await waitForSrcEndpointConfig(page) | ||
const updatedACL = await page.evaluate( | ||
async ({ acl, accessToken }) => { | ||
// @ts-expect-error: Cannot find name 'SRC' | ||
return await SRC.SynapseClient.updateEntityACL(acl, accessToken) | ||
}, | ||
{ acl, accessToken }, | ||
) | ||
return updatedACL as AccessControlList | ||
} | ||
|
||
// Note: The caller must be granted ACCESS_TYPE.CHANGE_PERMISSIONS on the Entity to call this method | ||
export async function addUserToEntityACL( | ||
page: Page, | ||
entityId: string, | ||
userId: number, | ||
accessToken: string, | ||
accessType: ACCESS_TYPE[] = [ACCESS_TYPE.DOWNLOAD, ACCESS_TYPE.READ], | ||
) { | ||
const acl = await getEntityACL(page, entityId, accessToken) | ||
const newAccess: ResourceAccess = { | ||
principalId: userId, | ||
accessType: accessType, | ||
} | ||
acl.resourceAccess.push(newAccess) | ||
return await updateEntityACL(page, acl, accessToken) | ||
} |
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,83 @@ | ||
import { Browser } from '@playwright/test' | ||
import { StorageStatePaths } from '../fixtures/authenticatedUserPages' | ||
import ACCESS_TYPE from './ACCESS_TYPE' | ||
import { addUserToEntityACL } from './acl' | ||
import { | ||
createProject, | ||
deleteFileHandleWithRetry, | ||
deleteProject, | ||
generateEntityName, | ||
} from './entities' | ||
import { | ||
getAccessTokenFromCookie, | ||
getAdminPAT, | ||
getUserIdFromLocalStorage, | ||
} from './testUser' | ||
import { Project } from './types' | ||
import { UserPrefix } from './userConfig' | ||
|
||
export const setupProject = async ( | ||
browser: Browser, | ||
projectCreator: UserPrefix, | ||
storageStatePaths: StorageStatePaths, | ||
) => { | ||
const context = await browser.newContext({ | ||
storageState: storageStatePaths[projectCreator], | ||
}) | ||
const page = await context.newPage() | ||
const accessToken = await getAccessTokenFromCookie(page) | ||
|
||
const projectName = generateEntityName('project') | ||
const projectId = await createProject(projectName, accessToken, page) | ||
await context.close() | ||
|
||
return { name: projectName, id: projectId } as Project | ||
} | ||
|
||
export const setupProjectWithPermissions = async ( | ||
browser: Browser, | ||
projectCreator: UserPrefix, | ||
projectAccessor: UserPrefix, | ||
storageStatePaths: StorageStatePaths, | ||
accessorPermissions: ACCESS_TYPE[] = [ACCESS_TYPE.DOWNLOAD, ACCESS_TYPE.READ], | ||
) => { | ||
const project = await setupProject(browser, projectCreator, storageStatePaths) | ||
|
||
const context = await browser.newContext({ | ||
storageState: storageStatePaths[projectAccessor], | ||
}) | ||
const page = await context.newPage() | ||
const userId = await getUserIdFromLocalStorage(page) | ||
await addUserToEntityACL( | ||
page, | ||
project.id, | ||
Number(userId), | ||
getAdminPAT(), | ||
accessorPermissions, | ||
) | ||
await context.close() | ||
|
||
return project | ||
} | ||
|
||
export const teardownProjectsAndFileHandles = async ( | ||
browser: Browser, | ||
projects: Project[], | ||
fileHandleIds: string[], | ||
) => { | ||
const context = await browser.newContext() | ||
const page = await context.newPage() | ||
const accessToken = getAdminPAT() | ||
|
||
// delete projects | ||
for (const project of projects) { | ||
await deleteProject(project.id, accessToken, page) | ||
} | ||
|
||
// delete fileHandles | ||
for (const fileHandleId of fileHandleIds) { | ||
await deleteFileHandleWithRetry(accessToken, fileHandleId, page) | ||
} | ||
|
||
await context.close() | ||
} |
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