Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
843fdb65
Commit
843fdb65
authored
Mar 18, 2017
by
Ujjwal Bhardwaj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update test cases for PR 27346
parent
8880ea3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
8 deletions
+77
-8
settings/Controller/UsersController.php
settings/Controller/UsersController.php
+1
-1
tests/Settings/Controller/UsersControllerTest.php
tests/Settings/Controller/UsersControllerTest.php
+76
-7
No files found.
settings/Controller/UsersController.php
View file @
843fdb65
...
...
@@ -809,7 +809,7 @@ class UsersController extends Controller {
try
{
$this
->
checkEmailChangeToken
(
$token
,
$userId
);
}
catch
(
\
Exception
$e
)
{
$this
->
log
->
error
(
"Cannot change email because, "
.
$e
->
getMessage
(),
[
'app'
=>
'settings'
]);
$this
->
log
->
error
(
$e
->
getMessage
(),
[
'app'
=>
'settings'
]);
return
new
RedirectResponse
(
$this
->
urlGenerator
->
linkToRoute
(
'settings.SettingsPage.getPersonal'
,
[
'changestatus'
=>
'error'
]));
}
...
...
tests/Settings/Controller/UsersControllerTest.php
View file @
843fdb65
...
...
@@ -13,6 +13,7 @@ namespace Tests\Settings\Controller;
use
\
OC\Settings\Application
;
use
OCP\AppFramework\Http
;
use
OCP\AppFramework\Http\DataResponse
;
use
OCP\AppFramework\Http\RedirectResponse
;
/**
* @group DB
...
...
@@ -1793,6 +1794,15 @@ class UsersControllerTest extends \Test\TestCase {
->
willReturn
(
true
);
}
$this
->
container
[
'Config'
]
->
expects
(
$this
->
any
())
->
method
(
'getUserValue'
)
->
with
(
'foo'
,
'owncloud'
,
'changeMail'
)
->
will
(
$this
->
returnValue
(
'12000:AVerySecretToken'
));
$this
->
container
[
'TimeFactory'
]
->
expects
(
$this
->
any
())
->
method
(
'getTime'
)
->
willReturnOnConsecutiveCalls
(
12301
,
12348
);
$this
->
container
[
'UserManager'
]
->
expects
(
$this
->
atLeastOnce
())
->
method
(
'get'
)
...
...
@@ -1803,14 +1813,10 @@ class UsersControllerTest extends \Test\TestCase {
->
method
(
'generate'
)
->
with
(
'21'
)
->
will
(
$this
->
returnValue
(
'ThisIsMaybeANotSoSecretToken!'
));
$this
->
container
[
'TimeFactory'
]
->
expects
(
$this
->
any
())
->
method
(
'getTime'
)
->
will
(
$this
->
returnValue
(
12348
));
$this
->
container
[
'Config'
]
->
expects
(
$this
->
any
())
->
method
(
'setUserValue'
)
->
with
(
'foo'
,
'owncloud'
,
'change
m
ail'
,
'12348:ThisIsMaybeANotSoSecretToken!'
);
->
with
(
'foo'
,
'owncloud'
,
'change
M
ail'
,
'12348:ThisIsMaybeANotSoSecretToken!'
);
$this
->
container
[
'URLGenerator'
]
->
expects
(
$this
->
any
())
->
method
(
'linkToRouteAbsolute'
)
...
...
@@ -1825,11 +1831,11 @@ class UsersControllerTest extends \Test\TestCase {
$message
->
expects
(
$this
->
any
())
->
method
(
'setSubject'
)
->
with
(
'
password reset
'
);
->
with
(
'
email address confirm
'
);
$message
->
expects
(
$this
->
any
())
->
method
(
'setPlainBody'
)
->
with
(
'Use the following link to
reset your password
: https://ownCloud.com/index.php/mailaddress/'
);
->
with
(
'Use the following link to
confirm your changes to the email address
: https://ownCloud.com/index.php/mailaddress/'
);
$message
->
expects
(
$this
->
any
())
->
method
(
'setFrom'
)
...
...
@@ -2085,4 +2091,67 @@ class UsersControllerTest extends \Test\TestCase {
$response
=
$this
->
container
[
'UsersController'
]
->
setDisplayName
(
$user
->
getUID
(),
'newDisplayName'
);
$this
->
assertEquals
(
$expectedResponse
,
$response
);
}
public
function
testDifferentLoggedUserAndRequestUser
()
{
$token
=
'AVerySecretToken'
;
$userId
=
'ExistingUser'
;
$mailAddress
=
'sample@email.com'
;
$userObject
=
$this
->
getMockBuilder
(
'OCP\IUser'
)
->
disableOriginalConstructor
()
->
getMock
();
$diffUserObject
=
$this
->
getMockBuilder
(
'OCP\IUser'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
container
[
'UserManager'
]
->
expects
(
$this
->
once
())
->
method
(
'get'
)
->
with
(
$userId
)
->
will
(
$this
->
returnValue
(
$userObject
));
$this
->
container
[
'UserSession'
]
->
expects
(
$this
->
once
())
->
method
(
'getUser'
)
->
will
(
$this
->
returnValue
(
$diffUserObject
));
$this
->
container
[
'Logger'
]
->
expects
(
$this
->
once
())
->
method
(
'error'
)
->
with
(
'The logged in user is different than expected.'
);
$expectedResponse
=
new
RedirectResponse
(
$this
->
container
[
'URLGenerator'
]
->
linkToRoute
(
'settings.SettingsPage.getPersonal'
,
[
'changestatus'
=>
'error'
])
);
$response
=
$this
->
container
[
'UsersController'
]
->
changeMail
(
$token
,
$userId
,
$mailAddress
);
$this
->
assertEquals
(
$expectedResponse
,
$response
);
}
public
function
testInvalidEmailChangeToken
()
{
$token
=
'AVerySecretToken'
;
$userId
=
'ExistingUser'
;
$mailAddress
=
'sample@email.com'
;
$userObject
=
$this
->
getMockBuilder
(
'OCP\IUser'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
container
[
'UserManager'
]
->
expects
(
$this
->
atLeastOnce
())
->
method
(
'get'
)
->
with
(
$userId
)
->
will
(
$this
->
returnValue
(
$userObject
));
$this
->
container
[
'UserSession'
]
->
expects
(
$this
->
once
())
->
method
(
'getUser'
)
->
will
(
$this
->
returnValue
(
$userObject
));
$this
->
container
[
'Logger'
]
->
expects
(
$this
->
once
())
->
method
(
'error'
)
->
with
(
'Couldn\'t change the email address because the token is invalid'
);
$expectedResponse
=
new
RedirectResponse
(
$this
->
container
[
'URLGenerator'
]
->
linkToRoute
(
'settings.SettingsPage.getPersonal'
,
[
'changestatus'
=>
'error'
])
);
$response
=
$this
->
container
[
'UsersController'
]
->
changeMail
(
$token
,
$userId
,
$mailAddress
);
$this
->
assertEquals
(
$expectedResponse
,
$response
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment