Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
6585eaa5
Commit
6585eaa5
authored
10 years ago
by
Vincent Petry
Browse files
Options
Downloads
Patches
Plain Diff
Added failing unit tests for mount config hooks
parent
0610937a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/files_external/lib/config.php
+8
-8
8 additions, 8 deletions
apps/files_external/lib/config.php
apps/files_external/tests/mountconfig.php
+134
-0
134 additions, 0 deletions
apps/files_external/tests/mountconfig.php
lib/private/files/filesystem.php
+5
-0
5 additions, 0 deletions
lib/private/files/filesystem.php
with
147 additions
and
8 deletions
apps/files_external/lib/config.php
+
8
−
8
View file @
6585eaa5
...
...
@@ -518,11 +518,11 @@ class OC_Mount_Config {
if
(
$result
&&
$isNew
)
{
\OC_Hook
::
emit
(
\OC\Files\Filesystem
::
CLASSNAME
,
'add_mount_poi
nt
'
,
\OC\Files\Filesystem
::
signal_create_mou
nt
,
array
(
'
path
'
=>
$mountPoint
,
'
type
'
=>
$mountType
,
'applicable'
=>
$applicable
\OC\Files\Filesystem
::
signal_param_
path
=>
$mountPoint
,
\OC\Files\Filesystem
::
signal_param_mount_
type
=>
$mountType
,
\OC\Files\Filesystem
::
signal_param_users
=>
$applicable
,
)
);
}
...
...
@@ -561,11 +561,11 @@ class OC_Mount_Config {
self
::
writeData
(
$isPersonal
?
OCP\User
::
getUser
()
:
NULL
,
$mountPoints
);
\OC_Hook
::
emit
(
\OC\Files\Filesystem
::
CLASSNAME
,
'remove_mount_point'
,
\OC\Files\Filesystem
::
signal_delete_mount
,
array
(
'
path
'
=>
$mountPoint
,
'
type
'
=>
$mountType
,
'applicable'
=>
$applicable
\OC\Files\Filesystem
::
signal_param_
path
=>
$mountPoint
,
\OC\Files\Filesystem
::
signal_param_mount_
type
=>
$mountType
,
\OC\Files\Filesystem
::
signal_param_users
=>
$applicable
,
)
);
return
true
;
...
...
This diff is collapsed.
Click to expand it.
apps/files_external/tests/mountconfig.php
+
134
−
0
View file @
6585eaa5
...
...
@@ -26,6 +26,42 @@ class Test_Mount_Config_Dummy_Storage {
}
}
class
Test_Mount_Config_Hook_Test
{
static
$signal
;
static
$params
;
public
static
function
setUpHooks
()
{
self
::
clear
();
\OCP\Util
::
connectHook
(
\OC\Files\Filesystem
::
CLASSNAME
,
\OC\Files\Filesystem
::
signal_create_mount
,
'\Test_Mount_Config_Hook_Test'
,
'createHookCallback'
);
\OCP\Util
::
connectHook
(
\OC\Files\Filesystem
::
CLASSNAME
,
\OC\Files\Filesystem
::
signal_delete_mount
,
'\Test_Mount_Config_Hook_Test'
,
'deleteHookCallback'
);
}
public
static
function
clear
()
{
self
::
$signal
=
null
;
self
::
$params
=
null
;
}
public
static
function
createHookCallback
(
$params
)
{
self
::
$signal
=
\OC\Files\Filesystem
::
signal_create_mount
;
self
::
$params
=
$params
;
}
public
static
function
deleteHookCallback
(
$params
)
{
self
::
$signal
=
\OC\Files\Filesystem
::
signal_create_mount
;
self
::
$params
=
$params
;
}
public
static
function
getLastCall
()
{
return
array
(
self
::
$signal
,
self
::
$params
);
}
}
/**
* Class Test_Mount_Config
*/
...
...
@@ -77,9 +113,11 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase {
);
OC_Mount_Config
::
$skipTest
=
true
;
Test_Mount_Config_Hook_Test
::
setupHooks
();
}
public
function
tearDown
()
{
Test_Mount_Config_Hook_Test
::
clear
();
OC_Mount_Config
::
$skipTest
=
false
;
\OC_User
::
deleteUser
(
self
::
TEST_USER2
);
...
...
@@ -337,6 +375,102 @@ class Test_Mount_Config extends \PHPUnit_Framework_TestCase {
$this
->
assertEquals
(
array_keys
(
$options
),
array_keys
(
$savedOptions
));
}
public
function
testHooks
()
{
$mountPoint
=
'/test'
;
$mountType
=
'user'
;
$applicable
=
'all'
;
$isPersonal
=
false
;
$mountConfig
=
array
(
'host'
=>
'smbhost'
,
'user'
=>
'smbuser'
,
'password'
=>
'smbpassword'
,
'share'
=>
'smbshare'
,
'root'
=>
'smbroot'
);
// write config
$this
->
assertTrue
(
OC_Mount_Config
::
addMountPoint
(
$mountPoint
,
'\OC\Files\Storage\SMB'
,
$mountConfig
,
$mountType
,
$applicable
,
$isPersonal
)
);
list
(
$hookName
,
$params
)
=
Test_Mount_Config_Hook_Test
::
getLastCall
();
$this
->
assertEquals
(
\OC\Files\Filesystem
::
signal_create_mount
,
$hookName
);
$this
->
assertEquals
(
$mountPoint
,
$params
[
\OC\Files\Filesystem
::
signal_param_path
]
);
$this
->
assertEquals
(
$mountType
,
$params
[
\OC\Files\Filesystem
::
signal_param_mount_type
]
);
$this
->
assertEquals
(
$applicable
,
$params
[
\OC\Files\Filesystem
::
signal_param_mount_users
]
);
Test_Mount_Config_Hook_Test
::
clear
();
// edit
$mountConfig
[
'host'
]
=
'anothersmbhost'
;
$this
->
assertTrue
(
OC_Mount_Config
::
addMountPoint
(
$mountPoint
,
'\OC\Files\Storage\SMB'
,
$mountConfig
,
$mountType
,
$applicable
,
$isPersonal
)
);
// hook must not be called on edit
list
(
$hookName
,
$params
)
=
Test_Mount_Config_Hook_Test
::
getLastCall
();
$this
->
assertEquals
(
null
,
$hookName
);
Test_Mount_Config_Hook_Test
::
clear
();
$this
->
assertTrue
(
OC_Mount_Config
::
removeMountPoint
(
'/ext'
,
$mountType
,
$applicable
,
$isPersonal
)
);
list
(
$hookName
,
$params
)
=
Test_Mount_Config_Hook_Test
::
getLastCall
();
$this
->
assertEquals
(
\OC\Files\Filesystem
::
signal_delete_mount
,
$hookName
);
$this
->
assertEquals
(
$mountPoint
,
$params
[
\OC\Files\Filesystem
::
signal_param_path
]
);
$this
->
assertEquals
(
$mountType
,
$params
[
\OC\Files\Filesystem
::
signal_param_mount_type
]
);
$this
->
assertEquals
(
$applicable
,
$params
[
\OC\Files\Filesystem
::
signal_param_mount_users
]
);
}
/**
* Test password obfuscation
*/
...
...
This diff is collapsed.
Click to expand it.
lib/private/files/filesystem.php
+
5
−
0
View file @
6585eaa5
...
...
@@ -158,6 +158,11 @@ class Filesystem {
*/
const
signal_param_run
=
'run'
;
const
signal_create_mount
=
'create_mount'
;
const
signal_delete_mount
=
'delete_mount'
;
const
signal_param_mount_type
=
'mounttype'
;
const
signal_param_users
=
'users'
;
/**
* @var \OC\Files\Storage\Loader $loader
*/
...
...
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