Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>tags/v14.0.0beta1
@@ -31,14 +31,12 @@ use OCP\AppFramework\Db\Entity; | |||
* @method void setUid(string $uid); | |||
* @method void setLoginName(string $loginname) | |||
* @method void setPassword(string $password) | |||
* @method string getName() | |||
* @method void setName(string $name) | |||
* @method void setToken(string $token) | |||
* @method string getToken() | |||
* @method void setType(int $type) | |||
* @method int getType() | |||
* @method void setRemember(int $remember) | |||
* @method int getRemember() | |||
* @method void setLastActivity(int $lastactivity) | |||
* @method int getLastActivity() | |||
*/ | |||
@@ -107,9 +105,9 @@ class DefaultToken extends Entity implements IToken { | |||
/** | |||
* Get the (encrypted) login password | |||
* | |||
* @return string | |||
* @return string|null | |||
*/ | |||
public function getPassword(): string { | |||
public function getPassword() { | |||
return parent::getPassword(); | |||
} | |||
@@ -136,14 +134,18 @@ class DefaultToken extends Entity implements IToken { | |||
* Get the timestamp of the last password check | |||
* | |||
* @param int $time | |||
* @return int | |||
*/ | |||
public function setLastCheck(int $time): int { | |||
return parent::setLastCheck($time); | |||
public function setLastCheck(int $time) { | |||
parent::setLastCheck($time); | |||
} | |||
public function getScope(): string { | |||
return parent::getScope(); | |||
$scope = parent::getScope(); | |||
if ($scope === null) { | |||
return ''; | |||
} | |||
return $scope; | |||
} | |||
public function getScopeAsArray(): array { | |||
@@ -156,7 +158,17 @@ class DefaultToken extends Entity implements IToken { | |||
return $scope; | |||
} | |||
public function setScope(array $scope) { | |||
parent::setScope(json_encode($scope)); | |||
public function setScope(array $scope = null) { | |||
if ($scope !== null) { | |||
parent::setScope(json_encode($scope)); | |||
} | |||
} | |||
public function getName(): string { | |||
return parent::getName(); | |||
} | |||
public function getRemember(): int { | |||
return parent::getRemember(); | |||
} | |||
} |
@@ -174,11 +174,11 @@ class DefaultTokenProvider implements IProvider { | |||
/** | |||
* Get a token by token id | |||
* | |||
* @param string $tokenId | |||
* @param int $tokenId | |||
* @throws InvalidTokenException | |||
* @return IToken | |||
*/ | |||
public function getTokenById(string $tokenId): IToken { | |||
public function getTokenById(int $tokenId): IToken { | |||
try { | |||
return $this->mapper->getTokenById($tokenId); | |||
} catch (DoesNotExistException $ex) { |
@@ -65,11 +65,11 @@ interface IProvider { | |||
/** | |||
* Get a token by token id | |||
* | |||
* @param string $tokenId | |||
* @param int $tokenId | |||
* @throws InvalidTokenException | |||
* @return IToken | |||
*/ | |||
public function getTokenById(string $tokenId): IToken; | |||
public function getTokenById(int $tokenId): IToken; | |||
/** | |||
* Duplicate an existing session token |
@@ -57,9 +57,9 @@ interface IToken extends JsonSerializable { | |||
/** | |||
* Get the (encrypted) login password | |||
* | |||
* @return string | |||
* @return string|null | |||
*/ | |||
public function getPassword(): string; | |||
public function getPassword(); | |||
/** | |||
* Get the timestamp of the last password check | |||
@@ -94,7 +94,7 @@ interface IToken extends JsonSerializable { | |||
* | |||
* @param array $scope | |||
*/ | |||
public function setScope(array $scope); | |||
public function setScope(array $scope = null); | |||
public function getName(): string; | |||
@@ -24,10 +24,10 @@ namespace Test\Authentication\Token; | |||
use OC\Authentication\Exceptions\InvalidTokenException; | |||
use OC\Authentication\Token\DefaultToken; | |||
use OC\Authentication\Token\DefaultTokenMapper; | |||
use OC\Authentication\Token\DefaultTokenProvider; | |||
use OC\Authentication\Token\IToken; | |||
use OCP\AppFramework\Db\DoesNotExistException; | |||
use OCP\AppFramework\Db\Mapper; | |||
use OCP\AppFramework\Utility\ITimeFactory; | |||
use OCP\IConfig; | |||
use OCP\ILogger; | |||
@@ -39,7 +39,7 @@ class DefaultTokenProviderTest extends TestCase { | |||
/** @var DefaultTokenProvider|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $tokenProvider; | |||
/** @var Mapper|\PHPUnit_Framework_MockObject_MockObject */ | |||
/** @var DefaultTokenMapper|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $mapper; | |||
/** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */ | |||
private $crypto; | |||
@@ -55,9 +55,7 @@ class DefaultTokenProviderTest extends TestCase { | |||
protected function setUp() { | |||
parent::setUp(); | |||
$this->mapper = $this->getMockBuilder('\OC\Authentication\Token\DefaultTokenMapper') | |||
->disableOriginalConstructor() | |||
->getMock(); | |||
$this->mapper = $this->createMock(DefaultTokenMapper::class); | |||
$this->crypto = $this->createMock(ICrypto::class); | |||
$this->config = $this->createMock(IConfig::class); | |||
$this->logger = $this->createMock(ILogger::class); |
@@ -33,14 +33,6 @@ class DefaultTokenTest extends TestCase { | |||
$this->assertEquals($scope, $token->getScopeAsArray()); | |||
} | |||
public function testSetScopeAsString() { | |||
$scope = ['filesystem' => false]; | |||
$token = new DefaultToken(); | |||
$token->setScope(json_encode($scope)); | |||
$this->assertEquals(json_encode($scope), $token->getScope()); | |||
$this->assertEquals($scope, $token->getScopeAsArray()); | |||
} | |||
public function testDefaultScope() { | |||
$scope = ['filesystem' => true]; | |||
$token = new DefaultToken(); |