Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
0bddaa23
Unverified
Commit
0bddaa23
authored
8 years ago
by
Vincent Petry
Committed by
Roeland Jago Douma
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Added more tests for sharing's MountProvider
parent
67fa6bf9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/files_sharing/tests/MountProviderTest.php
+158
-0
158 additions, 0 deletions
apps/files_sharing/tests/MountProviderTest.php
with
158 additions
and
0 deletions
apps/files_sharing/tests/MountProviderTest.php
+
158
−
0
View file @
0bddaa23
...
@@ -88,6 +88,11 @@ class MountProviderTest extends \Test\TestCase {
...
@@ -88,6 +88,11 @@ class MountProviderTest extends \Test\TestCase {
return
$share
;
return
$share
;
}
}
/**
* Tests excluding shares from the current view. This includes:
* - shares that were opted out of (permissions === 0)
* - shares with a group in which the owner is already in
*/
public
function
testExcludeShares
()
{
public
function
testExcludeShares
()
{
$rootFolder
=
$this
->
getMock
(
'\OCP\Files\IRootFolder'
);
$rootFolder
=
$this
->
getMock
(
'\OCP\Files\IRootFolder'
);
$userManager
=
$this
->
getMock
(
'\OCP\IUserManager'
);
$userManager
=
$this
->
getMock
(
'\OCP\IUserManager'
);
...
@@ -133,5 +138,158 @@ class MountProviderTest extends \Test\TestCase {
...
@@ -133,5 +138,158 @@ class MountProviderTest extends \Test\TestCase {
$this
->
assertEquals
(
'/share4'
,
$mountedShare2
->
getTarget
());
$this
->
assertEquals
(
'/share4'
,
$mountedShare2
->
getTarget
());
$this
->
assertEquals
(
31
,
$mountedShare2
->
getPermissions
());
$this
->
assertEquals
(
31
,
$mountedShare2
->
getPermissions
());
}
}
public
function
mergeSharesDataProvider
()
{
// note: the user in the specs here is the shareOwner not recipient
// the recipient is always "user1"
return
[
// #0: share as outsider with "group1" and "user1" with same permissions
[
[
[
1
,
100
,
'user2'
,
'/share2'
,
31
],
],
[
[
2
,
100
,
'user2'
,
'/share2'
,
31
],
],
[
// combined, user share has higher priority
[
'1'
,
100
,
'user2'
,
'/share2'
,
31
],
],
],
// #1: share as outsider with "group1" and "user1" with different permissions
[
[
[
1
,
100
,
'user2'
,
'/share'
,
31
],
],
[
[
2
,
100
,
'user2'
,
'/share'
,
15
],
],
[
// use highest permissions
[
'1'
,
100
,
'user2'
,
'/share'
,
31
],
],
],
// #2: share as outsider with "group1" and "group2" with same permissions
[
[
],
[
[
1
,
100
,
'user2'
,
'/share'
,
31
],
[
2
,
100
,
'user2'
,
'/share'
,
31
],
],
[
// combined, first group share has higher priority
[
'1'
,
100
,
'user2'
,
'/share'
,
31
],
],
],
// #3: share as outsider with "group1" and "group2" with different permissions
[
[
],
[
[
1
,
100
,
'user2'
,
'/share'
,
31
],
[
2
,
100
,
'user2'
,
'/share'
,
15
],
],
[
// use higher permissions
[
'1'
,
100
,
'user2'
,
'/share'
,
31
],
],
],
// #4: share as insider with "group1"
[
[
],
[
[
1
,
100
,
'user1'
,
'/share'
,
31
],
],
[
// no received share since "user1" is the sharer/owner
],
],
// #5: share as insider with "group1" and "group2" with different permissions
[
[
],
[
[
1
,
100
,
'user1'
,
'/share'
,
31
],
[
2
,
100
,
'user1'
,
'/share'
,
15
],
],
[
// no received share since "user1" is the sharer/owner
],
],
// #6: share as outside with "group1", recipient opted out
[
[
],
[
[
1
,
100
,
'user2'
,
'/share'
,
0
],
],
[
// no received share since "user1" opted out
],
],
];
}
/**
* Tests merging shares.
*
* Happens when sharing the same entry to a user through multiple ways,
* like several groups and also direct shares at the same time.
*
* @dataProvider mergeSharesDataProvider
*
* @param array $userShares array of user share specs
* @param array $groupShares array of group share specs
* @param array $expectedShares array of expected supershare specs
*/
public
function
testMergeShares
(
$userShares
,
$groupShares
,
$expectedShares
)
{
$rootFolder
=
$this
->
getMock
(
'\OCP\Files\IRootFolder'
);
$userManager
=
$this
->
getMock
(
'\OCP\IUserManager'
);
$userShares
=
array_map
(
function
(
$shareSpec
)
{
return
$this
->
makeMockShare
(
$shareSpec
[
0
],
$shareSpec
[
1
],
$shareSpec
[
2
],
$shareSpec
[
3
],
$shareSpec
[
4
]);
},
$userShares
);
$groupShares
=
array_map
(
function
(
$shareSpec
)
{
return
$this
->
makeMockShare
(
$shareSpec
[
0
],
$shareSpec
[
1
],
$shareSpec
[
2
],
$shareSpec
[
3
],
$shareSpec
[
4
]);
},
$groupShares
);
$this
->
user
->
expects
(
$this
->
any
())
->
method
(
'getUID'
)
->
will
(
$this
->
returnValue
(
'user1'
));
$this
->
shareManager
->
expects
(
$this
->
at
(
0
))
->
method
(
'getSharedWith'
)
->
with
(
'user1'
,
\OCP\Share
::
SHARE_TYPE_USER
)
->
will
(
$this
->
returnValue
(
$userShares
));
$this
->
shareManager
->
expects
(
$this
->
at
(
1
))
->
method
(
'getSharedWith'
)
->
with
(
'user1'
,
\OCP\Share
::
SHARE_TYPE_GROUP
,
null
,
-
1
)
->
will
(
$this
->
returnValue
(
$groupShares
));
$this
->
shareManager
->
expects
(
$this
->
any
())
->
method
(
'newShare'
)
->
will
(
$this
->
returnCallback
(
function
()
use
(
$rootFolder
,
$userManager
)
{
return
new
\OC\Share20\Share
(
$rootFolder
,
$userManager
);
}));
$mounts
=
$this
->
provider
->
getMountsForUser
(
$this
->
user
,
$this
->
loader
);
$this
->
assertCount
(
count
(
$expectedShares
),
$mounts
);
foreach
(
$mounts
as
$index
=>
$mount
)
{
$expectedShare
=
$expectedShares
[
$index
];
$this
->
assertInstanceOf
(
'OCA\Files_Sharing\SharedMount'
,
$mount
);
// supershare
$share
=
$mount
->
getShare
();
$this
->
assertEquals
(
$expectedShare
[
0
],
$share
->
getId
());
$this
->
assertEquals
(
$expectedShare
[
1
],
$share
->
getNodeId
());
$this
->
assertEquals
(
$expectedShare
[
2
],
$share
->
getShareOwner
());
$this
->
assertEquals
(
$expectedShare
[
3
],
$share
->
getTarget
());
$this
->
assertEquals
(
$expectedShare
[
4
],
$share
->
getPermissions
());
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment