Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dokuwiki
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
BRIC
dokuwiki
Commits
020ea9e1
Commit
020ea9e1
authored
11 years ago
by
Christopher Smith
Browse files
Options
Downloads
Patches
Plain Diff
unit tests for self deleting of user accounts
parent
2a7abf2d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
_test/tests/inc/auth_deleteprofile.test.php
+179
-0
179 additions, 0 deletions
_test/tests/inc/auth_deleteprofile.test.php
inc/confutils.php
+1
-1
1 addition, 1 deletion
inc/confutils.php
with
180 additions
and
1 deletion
_test/tests/inc/auth_deleteprofile.test.php
0 → 100644
+
179
−
0
View file @
020ea9e1
<?php
class
Mock_Auth_Plugin
extends
DokuWiki_Auth_Plugin
{
public
$loggedOff
=
false
;
public
function
__construct
(
$canDeleteUser
=
true
)
{
$this
->
cando
[
'delUser'
]
=
$canDeleteUser
;
}
public
function
checkPass
(
$user
,
$pass
)
{
return
$pass
==
'password'
;
}
public
function
deleteUsers
(
$users
)
{
return
in_array
(
$_SERVER
[
'REMOTE_USER'
],
$users
);
}
public
function
logoff
()
{
$this
->
loggedOff
=
true
;
}
}
class
auth_deleteprofile_test
extends
DokuWikiTest
{
/*
* Tests:
*
* 1. It works and the user is logged off
* 2. Password matches when config requires it
* 3,4. Auth plugin can prevent & wiki config can prevent
* 5. Any of invalid security token, missing/not set 'delete' flag, missing/unchecked 'confirm_delete'
*
*/
function
test_success
()
{
global
$ACT
,
$INPUT
,
$conf
,
$auth
;
$ACT
=
'profile_delete'
;
$conf
[
'profileconfirm'
]
=
false
;
$_SERVER
[
'REMOTE_USER'
]
=
'testuser'
;
$input
=
array
(
'do'
=>
$ACT
,
'sectok'
=>
getSecurityToken
(),
'delete'
=>
'1'
,
'confirm_delete'
=>
'1'
,
);
$_POST
=
$input
;
$_REQUEST
=
$input
;
$INPUT
=
new
Input
();
$auth
=
new
Mock_Auth_Plugin
();
$this
->
assertTrue
(
auth_deleteprofile
());
$this
->
assertTrue
(
$auth
->
loggedOff
);
}
function
test_confirmation_required
()
{
global
$ACT
,
$INPUT
,
$conf
,
$auth
;
$ACT
=
'profile_delete'
;
$conf
[
'profileconfirm'
]
=
true
;
$_SERVER
[
'REMOTE_USER'
]
=
'testuser'
;
$input
=
array
(
'do'
=>
$ACT
,
'sectok'
=>
getSecurityToken
(),
'delete'
=>
'1'
,
'confirm_delete'
=>
'1'
,
'oldpass'
=>
'wrong'
,
);
$_POST
=
$input
;
$_REQUEST
=
$input
;
$INPUT
=
new
Input
();
$auth
=
new
Mock_Auth_Plugin
();
// password check required - it fails, so don't delete profile
$this
->
assertFalse
(
auth_deleteprofile
());
// now it passes, we're good to go
$INPUT
->
set
(
'oldpass'
,
'password'
);
$INPUT
->
post
->
set
(
'oldpass'
,
'password'
);
$this
->
assertTrue
(
auth_deleteprofile
());
}
function
test_authconfig_prevents
()
{
global
$ACT
,
$INPUT
,
$conf
,
$auth
;
$ACT
=
'profile_delete'
;
$conf
[
'profileconfirm'
]
=
false
;
$_SERVER
[
'REMOTE_USER'
]
=
'testuser'
;
$input
=
array
(
'do'
=>
$ACT
,
'sectok'
=>
getSecurityToken
(),
'delete'
=>
'1'
,
'confirm_delete'
=>
'1'
,
);
$_POST
=
$input
;
$_REQUEST
=
$input
;
$INPUT
=
new
Input
();
$auth
=
new
Mock_Auth_Plugin
(
false
);
$conf
[
'disableactions'
]
=
''
;
$this
->
assertFalse
(
auth_deleteprofile
());
}
function
test_wikiconfig_prevents
()
{
global
$ACT
,
$INPUT
,
$conf
,
$auth
;
$ACT
=
'profile_delete'
;
$conf
[
'profileconfirm'
]
=
false
;
$_SERVER
[
'REMOTE_USER'
]
=
'testuser'
;
$input
=
array
(
'do'
=>
$ACT
,
'sectok'
=>
getSecurityToken
(),
'delete'
=>
'1'
,
'confirm_delete'
=>
'1'
,
);
$_POST
=
$input
;
$_REQUEST
=
$input
;
$INPUT
=
new
Input
();
$auth
=
new
Mock_Auth_Plugin
();
$conf
[
'disableactions'
]
=
'profile_delete'
;
$this
->
assertFalse
(
actionOK
(
'profile_delete'
));
$this
->
assertTrue
(
$auth
->
canDo
(
'delUser'
));
$this
->
assertFalse
(
auth_deleteprofile
());
}
function
test_basic_parameters
()
{
global
$ACT
,
$INPUT
,
$conf
,
$auth
;
$ACT
=
'profile_delete'
;
$conf
[
'profileconfirm'
]
=
true
;
$_SERVER
[
'REMOTE_USER'
]
=
'testuser'
;
$input
=
array
(
'do'
=>
$ACT
,
'sectok'
=>
getSecurityToken
(),
'delete'
=>
'1'
,
'confirm_delete'
=>
'1'
,
'oldpass'
=>
'password'
,
);
$_POST
=
$input
;
$_REQUEST
=
$input
;
$input_foundation
=
new
Input
();
$auth
=
new
Mock_Auth_Plugin
();
$INPUT
=
clone
$input_foundation
;
$INPUT
->
remove
(
'delete'
);
$this
->
assertFalse
(
auth_deleteprofile
());
$INPUT
=
clone
$input_foundation
;
$INPUT
->
set
(
'sectok'
,
'wrong'
);
$this
->
assertFalse
(
auth_deleteprofile
());
$INPUT
=
clone
$input_foundation
;
$INPUT
->
remove
(
'confirm_delete'
);
$this
->
assertFalse
(
auth_deleteprofile
());
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
inc/confutils.php
+
1
−
1
View file @
020ea9e1
...
...
@@ -241,7 +241,7 @@ function getConfigFiles($type) {
*/
function
actionOK
(
$action
){
static
$disabled
=
null
;
if
(
is_null
(
$disabled
)){
if
(
is_null
(
$disabled
)
||
defined
(
'SIMPLE_TEST'
)
){
global
$conf
;
/** @var auth_basic $auth */
global
$auth
;
...
...
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