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

Resharing in e2e test #7378

Merged
merged 1 commit into from
Aug 4, 2022
Merged
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
54 changes: 54 additions & 0 deletions tests/e2e/cucumber/features/integrations/reshare.ocis.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Feature: reshare

Background:
Given "Admin" disables share auto accepting

Scenario: re-sharing
Given "Admin" creates following users
ScharfViktor marked this conversation as resolved.
Show resolved Hide resolved
| id |
| Alice |
| Brian |
| Carol |
And "Admin" creates following group
ScharfViktor marked this conversation as resolved.
Show resolved Hide resolved
| id |
| sales |
| finance |
And "Admin" adds user to the group
| user | group |
| Carol | sales |

And "Alice" logs in
And "Alice" opens the "files" app
And "Alice" navigates to the personal space page
And "Alice" creates the following resources
| resource | type |
| folder_to_shared | folder |
When "Alice" shares the following resource using the sidebar panel
| resource | user | role |
| folder_to_shared | Brian | editor |
And "Alice" logs out

And "Brian" logs in
And "Brian" opens the "files" app
And "Brian" navigates to the shared with me page
And "Brian" accepts the following share
| name |
| folder_to_shared |
And "Brian" reshares the following resource
| resource | user | role |
| folder_to_shared | Carol | viewer |
And "Brian" logs out

And "Carol" logs in
And "Carol" opens the "files" app
And "Carol" navigates to the shared with me page
And "Carol" accepts the following share
| name |
| folder_to_shared |
And "Carol" reshares the following resource
| resource | user | role |
| folder_to_shared | Alice | viewer |
Comment on lines +48 to +50
Copy link
Contributor

@SwikritiT SwikritiT Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know it was possible to reshare the resource to the person to whom the resource belongs with a different roles. Is this expected?

I tried to play around with the UI

  1. Alice accepts the share request
  2. Alice as the owner of the resource creates a sub folder inside folder_to_shared like test
  3. The sub-folder is displayed in shared with me inside folder_to_shared
  4. If Alice goes inside folder_to_shared->tests from shared with me (this folder is shared with role viewer), she can create resources inside it but not directly inside folder_to_shared

Probably not related to this PR. Seems like a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't try to check this case. It's too complicated. It doesn't seem realistic.
I checked only that user can re-share re-shared resource. I did not create the 4th user

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll create a separate issue for this case

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue created here owncloud/ocis#4336

And "Carol" logs out
SwikritiT marked this conversation as resolved.
Show resolved Hide resolved



35 changes: 35 additions & 0 deletions tests/e2e/cucumber/steps/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,38 @@ Given(
})
}
)

Given(
'{string} creates following group(s)',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
const admin = this.usersEnvironment.getUser({ key: stepUser })

for (const info of stepTable.hashes()) {
const group = this.usersEnvironment.getGroup({ key: info.id })
if (config.ocis) {
await api.graph.deleteGroup({ group, admin })
await api.graph.createGroup({ group, admin })
} else {
await api.user.deleteGroup({ group, admin })
await api.user.createGroup({ group, admin })
}
}
}
)

Given(
'{string} adds user(s) to the group(s)',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
const admin = this.usersEnvironment.getUser({ key: stepUser })

for (const info of stepTable.hashes()) {
const group = this.usersEnvironment.getGroup({ key: info.group })
const user = this.usersEnvironment.getUser({ key: info.user })
if (config.ocis) {
await api.graph.addUserToGroup({ user, group, admin })
} else {
await api.user.addUserToGroup({ user, group, admin })
}
}
}
)
28 changes: 28 additions & 0 deletions tests/e2e/cucumber/steps/app-files/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ When(
}
)

When(
/^"([^"]*)" reshares the following (resource|resources)$/,
async function (this: World, stepUser: string, _: string, stepTable: DataTable) {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const shareObject = new objects.applicationFiles.Share({ page })
const shareInfo = stepTable.hashes().reduce((acc, stepRow) => {
const { user, resource, role } = stepRow

if (!acc[resource]) {
acc[resource] = { users: [], role: '' }
}

acc[resource].users.push(this.usersEnvironment.getUser({ key: user }))
acc[resource].role = role

return acc
}, {})

for (const folder of Object.keys(shareInfo)) {
await shareObject.createReshare({
folder,
users: shareInfo[folder].users,
role: shareInfo[folder].role
})
}
}
)

When(
'{string} accepts the following share(s)',
async function (this: World, stepUser: string, stepTable: DataTable) {
Expand Down
9 changes: 8 additions & 1 deletion tests/e2e/support/api/graph/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
export { me, createUser, deleteUser } from './user'
export {
me,
createUser,
deleteUser,
createGroup,
deleteGroup,
addUserToGroup
} from './userManagement'
42 changes: 0 additions & 42 deletions tests/e2e/support/api/graph/user.ts

This file was deleted.

131 changes: 131 additions & 0 deletions tests/e2e/support/api/graph/userManagement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { checkResponseStatus, request } from '../http'
import { Group, Me, User } from '../../types'
import join from 'join-path'
import { config } from '../../../config'

export const me = async ({ user }: { user: User }): Promise<Me> => {
const response = await request({
method: 'GET',
path: join('graph', 'v1.0', 'me'),
user
})

return await response.json()
}

export const createUser = async ({ user, admin }: { user: User; admin: User }): Promise<User> => {
const body = JSON.stringify({
displayName: user.displayName,
mail: user.email,
onPremisesSamAccountName: user.id,
passwordProfile: { password: user.password }
})

const response = await request({
method: 'POST',
path: join('graph', 'v1.0', 'users'),
body,
user: admin
})

checkResponseStatus(response, 'Failed while creating user')
return user
}

export const deleteUser = async ({ user, admin }: { user: User; admin: User }): Promise<User> => {
await request({
method: 'DELETE',
path: join('graph', 'v1.0', 'users', user.id),
user: admin
})

return user
}

const getUserId = async ({ user, admin }: { user: User; admin: User }): Promise<string> => {
let userId = ''
const response = await request({
method: 'GET',
path: join('graph', 'v1.0', 'users', user.id),
user: admin
})
if (response.ok) {
userId = (await response.json()).id
}
return userId
}

export const createGroup = async ({
group,
admin
}: {
group: Group
admin: User
}): Promise<Group> => {
const body = JSON.stringify({
displayName: group.displayName
})

const response = await request({
method: 'POST',
path: join('graph', 'v1.0', 'groups'),
body,
user: admin
})

checkResponseStatus(response, 'Failed while creating group')
return group
}

const getGroupId = async ({ group, admin }: { group: Group; admin: User }): Promise<string> => {
let groupId = ''
const response = await request({
method: 'GET',
path: join('graph', 'v1.0', 'groups', group.displayName),
user: admin
})
if (response.ok) {
groupId = (await response.json()).id
}
return groupId
}

export const deleteGroup = async ({
group,
admin
}: {
group: Group
admin: User
}): Promise<Group> => {
const groupId = await getGroupId({ group, admin })
await request({
method: 'DELETE',
path: join('graph', 'v1.0', 'groups', groupId),
user: admin
})
return group
}

export const addUserToGroup = async ({
user,
group,
admin
}: {
user: User
group: Group
admin: User
}): Promise<void> => {
const groupId = await getGroupId({ group, admin })
const userId = await getUserId({ user, admin })
const body = JSON.stringify({
'@odata.id': join(config.backendUrl, 'graph', 'v1.0', 'users', userId)
})

const response = await request({
method: 'POST',
path: join('graph', 'v1.0', 'groups', groupId, 'members', '$ref'),
body: body,
user: admin
})
checkResponseStatus(response, 'Failed while adding an user to the group')
}
2 changes: 1 addition & 1 deletion tests/e2e/support/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * as http from './http'
export * as user from './user'
export * as user from './userManagement'
export * as config from './config'
export * as settings from './settings'
export * as graph from './graph'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { checkResponseStatus, checkOCJsonStatus, request } from './http'
import { User } from '../types'
import { Group, User } from '../types'
import { URLSearchParams } from 'url'
import join from 'join-path'

Expand Down Expand Up @@ -68,3 +68,59 @@ export const getUser = async ({ user }: { user: User }): Promise<User> => {

return user
}

export const createGroup = async ({
group,
admin
}: {
group: Group
admin: User
}): Promise<Group> => {
const body = new URLSearchParams()
body.append('groupid', group.id)
const response = await request({
method: 'POST',
path: join('ocs', 'v2.php', 'cloud', 'groups'),
body: body,
user: admin
})
checkResponseStatus(response, 'Failed while creating group')
return group
}

export const deleteGroup = async ({
group,
admin
}: {
group: Group
admin: User
}): Promise<Group> => {
await request({
method: 'DELETE',
path: join('ocs', 'v2.php', 'cloud', 'groups', encodeURIComponent(group.id)),
user: admin
})

return group
}

export const addUserToGroup = async ({
user,
group,
admin
}: {
user: User
group: Group
admin: User
}): Promise<Group> => {
const body = new URLSearchParams()
body.append('groupid', group.id)
const response = await request({
method: 'POST',
path: join('ocs', 'v2.php', 'cloud', 'users', user.id, 'groups'),
body: body,
user: admin
})
checkResponseStatus(response, 'Failed while adding an user to the group')
return group
}
2 changes: 1 addition & 1 deletion tests/e2e/support/environment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export { ActorsEnvironment } from './actor'
export { FilesEnvironment } from './file'
export { LinksEnvironment } from './link'
export { SpacesEnvironment } from './space'
export { UsersEnvironment } from './user'
export { UsersEnvironment } from './userManagement'
Loading