aboutsummaryrefslogtreecommitdiffstats
path: root/tests/settings
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@owncloud.com>2016-05-18 18:25:05 +0200
committerChristoph Wurst <christoph@owncloud.com>2016-05-23 09:11:12 +0200
commit6495534bcdbbda8aa2748cc9f5d94dcb2bc7a04a (patch)
treeb000c3f7bc3b5dc2cc96b80b7f9ece2c51e9ba01 /tests/settings
parent12431aa3997154aaea4eec11c2dd65f9e5dbe179 (diff)
downloadnextcloud-server-6495534bcdbbda8aa2748cc9f5d94dcb2bc7a04a.tar.gz
nextcloud-server-6495534bcdbbda8aa2748cc9f5d94dcb2bc7a04a.zip
add button to add new device tokens
Diffstat (limited to 'tests/settings')
-rw-r--r--tests/settings/controller/AuthSettingsControllerTest.php77
1 files changed, 76 insertions, 1 deletions
diff --git a/tests/settings/controller/AuthSettingsControllerTest.php b/tests/settings/controller/AuthSettingsControllerTest.php
index d236f9f5ebc..3b46a2caa2b 100644
--- a/tests/settings/controller/AuthSettingsControllerTest.php
+++ b/tests/settings/controller/AuthSettingsControllerTest.php
@@ -22,7 +22,12 @@
namespace Test\Settings\Controller;
+use OC\AppFramework\Http;
+use OC\Authentication\Exceptions\InvalidTokenException;
+use OC\Authentication\Token\IToken;
use OC\Settings\Controller\AuthSettingsController;
+use OCP\AppFramework\Http\JSONResponse;
+use OCP\Session\Exceptions\SessionNotAvailableException;
use Test\TestCase;
class AuthSettingsControllerTest extends TestCase {
@@ -32,6 +37,8 @@ class AuthSettingsControllerTest extends TestCase {
private $request;
private $tokenProvider;
private $userManager;
+ private $session;
+ private $secureRandom;
private $uid;
protected function setUp() {
@@ -40,10 +47,12 @@ class AuthSettingsControllerTest extends TestCase {
$this->request = $this->getMock('\OCP\IRequest');
$this->tokenProvider = $this->getMock('\OC\Authentication\Token\IProvider');
$this->userManager = $this->getMock('\OCP\IUserManager');
+ $this->session = $this->getMock('\OCP\ISession');
+ $this->secureRandom = $this->getMock('\OCP\Security\ISecureRandom');
$this->uid = 'jane';
$this->user = $this->getMock('\OCP\IUser');
- $this->controller = new AuthSettingsController('core', $this->request, $this->tokenProvider, $this->userManager, $this->uid);
+ $this->controller = new AuthSettingsController('core', $this->request, $this->tokenProvider, $this->userManager, $this->session, $this->secureRandom, $this->uid);
}
public function testIndex() {
@@ -63,4 +72,70 @@ class AuthSettingsControllerTest extends TestCase {
$this->assertEquals($result, $this->controller->index());
}
+ public function testCreate() {
+ $name = 'Nexus 4';
+ $sessionToken = $this->getMock('\OC\Authentication\Token\IToken');
+ $deviceToken = $this->getMock('\OC\Authentication\Token\IToken');
+ $password = '123456';
+
+ $this->session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('sessionid'));
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('sessionid')
+ ->will($this->returnValue($sessionToken));
+ $this->tokenProvider->expects($this->once())
+ ->method('getPassword')
+ ->with($sessionToken, 'sessionid')
+ ->will($this->returnValue($password));
+
+ $this->secureRandom->expects($this->exactly(4))
+ ->method('generate')
+ ->with(5, implode('', range('A', 'Z')))
+ ->will($this->returnValue('XXXXX'));
+ $newToken = 'XXXXX-XXXXX-XXXXX-XXXXX';
+
+ $this->tokenProvider->expects($this->once())
+ ->method('generateToken')
+ ->with($newToken, $this->uid, $password, $name, IToken::PERMANENT_TOKEN)
+ ->will($this->returnValue($deviceToken));
+
+ $expected = [
+ 'token' => $newToken,
+ 'deviceToken' => $deviceToken,
+ ];
+ $this->assertEquals($expected, $this->controller->create($name));
+ }
+
+ public function testCreateSessionNotAvailable() {
+ $name = 'personal phone';
+
+ $this->session->expects($this->once())
+ ->method('getId')
+ ->will($this->throwException(new SessionNotAvailableException()));
+
+ $expected = new JSONResponse();
+ $expected->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
+
+ $this->assertEquals($expected, $this->controller->create($name));
+ }
+
+ public function testCreateInvalidToken() {
+ $name = 'Company IPhone';
+
+ $this->session->expects($this->once())
+ ->method('getId')
+ ->will($this->returnValue('sessionid'));
+ $this->tokenProvider->expects($this->once())
+ ->method('getToken')
+ ->with('sessionid')
+ ->will($this->throwException(new InvalidTokenException()));
+
+ $expected = new JSONResponse();
+ $expected->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
+
+ $this->assertEquals($expected, $this->controller->create($name));
+ }
+
}