Fix tests

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2022-02-23 10:40:58 +01:00
parent cc6653e45c
commit d078d53683
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
10 changed files with 121 additions and 136 deletions

View File

@ -35,14 +35,14 @@ use OC\Files\Storage\Local;
use OC\Files\Storage\Temporary;
use OC\Files\Storage\Wrapper\PermissionsMask;
use OC\Files\View;
use OC\Security\SecureRandom;
use OCA\DAV\Connector\Sabre\File;
use OCP\Constants;
use OCP\Files\ForbiddenException;
use OCP\Files\Storage;
use OCP\IConfig;
use OCP\IRequestId;
use OCP\Lock\ILockingProvider;
use OCP\Security\ISecureRandom;
use PHPUnit\Framework\MockObject\MockObject;
use Test\HookHelper;
use Test\TestCase;
use Test\Traits\MountProviderTrait;
@ -64,11 +64,11 @@ class FileTest extends TestCase {
*/
private $user;
/** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
/** @var IConfig|MockObject */
protected $config;
/** @var ISecureRandom */
protected $secureRandom;
/** @var IRequestId|MockObject */
protected $requestId;
protected function setUp(): void {
parent::setUp();
@ -83,8 +83,8 @@ class FileTest extends TestCase {
$this->loginAsUser($this->user);
$this->config = $this->getMockBuilder('\OCP\IConfig')->getMock();
$this->secureRandom = new SecureRandom();
$this->config = $this->createMock(IConfig::class);
$this->requestId = $this->createMock(IRequestId::class);
}
protected function tearDown(): void {
@ -96,7 +96,7 @@ class FileTest extends TestCase {
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject|Storage
* @return MockObject|Storage
*/
private function getMockStorage() {
$storage = $this->getMockBuilder(Storage::class)
@ -184,7 +184,7 @@ class FileTest extends TestCase {
->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]])
->getMock();
\OC\Files\Filesystem::mount($storage, [], $this->user . '/');
/** @var View | \PHPUnit\Framework\MockObject\MockObject $view */
/** @var View | MockObject $view */
$view = $this->getMockBuilder(View::class)
->setMethods(['getRelativePath', 'resolvePath'])
->getMock();
@ -330,7 +330,7 @@ class FileTest extends TestCase {
null
);
/** @var \OCA\DAV\Connector\Sabre\File | \PHPUnit\Framework\MockObject\MockObject $file */
/** @var \OCA\DAV\Connector\Sabre\File | MockObject $file */
$file = $this->getMockBuilder(\OCA\DAV\Connector\Sabre\File::class)
->setConstructorArgs([$view, $info, null, $request])
->setMethods(['header'])
@ -416,7 +416,7 @@ class FileTest extends TestCase {
'server' => [
'HTTP_X_OC_MTIME' => $requestMtime,
]
], $this->secureRandom, $this->config, null);
], $this->requestId, $this->config, null);
$file = 'foo.txt';
if ($resultMtime === null) {
@ -439,7 +439,7 @@ class FileTest extends TestCase {
'server' => [
'HTTP_X_OC_MTIME' => $requestMtime,
]
], $this->secureRandom, $this->config, null);
], $this->requestId, $this->config, null);
$_SERVER['HTTP_OC_CHUNKED'] = true;
$file = 'foo.txt';

View File

@ -31,16 +31,17 @@ use OC\Core\Controller\TwoFactorChallengeController;
use OC\Core\Middleware\TwoFactorMiddleware;
use OC\User\Session;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\Authentication\TwoFactorAuth\ALoginSetupController;
use OCP\Authentication\TwoFactorAuth\IProvider;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IRequestId;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Security\ISecureRandom;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
@ -88,7 +89,7 @@ class TwoFactorMiddlewareTest extends TestCase {
'REQUEST_URI' => 'test/url'
]
],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
@ -139,9 +140,9 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->middleware->beforeController($this->controller, 'index');
}
public function testBeforeControllerTwoFactorAuthRequired() {
$this->expectException(\OC\Authentication\Exceptions\TwoFactorAuthRequiredException::class);
$this->expectException(TwoFactorAuthRequiredException::class);
$user = $this->createMock(IUser::class);
@ -163,9 +164,9 @@ class TwoFactorMiddlewareTest extends TestCase {
$this->middleware->beforeController($this->controller, 'index');
}
public function testBeforeControllerUserAlreadyLoggedIn() {
$this->expectException(\OC\Authentication\Exceptions\UserAlreadyLoggedInException::class);
$this->expectException(UserAlreadyLoggedInException::class);
$user = $this->createMock(IUser::class);
@ -187,32 +188,32 @@ class TwoFactorMiddlewareTest extends TestCase {
->with($user)
->willReturn(false);
$twoFactorChallengeController = $this->getMockBuilder('\OC\Core\Controller\TwoFactorChallengeController')
$twoFactorChallengeController = $this->getMockBuilder(TwoFactorChallengeController::class)
->disableOriginalConstructor()
->getMock();
$this->middleware->beforeController($twoFactorChallengeController, 'index');
}
public function testAfterExceptionTwoFactorAuthRequired() {
$ex = new \OC\Authentication\Exceptions\TwoFactorAuthRequiredException();
$ex = new TwoFactorAuthRequiredException();
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('core.TwoFactorChallenge.selectChallenge')
->willReturn('test/url');
$expected = new \OCP\AppFramework\Http\RedirectResponse('test/url');
$expected = new RedirectResponse('test/url');
$this->assertEquals($expected, $this->middleware->afterException($this->controller, 'index', $ex));
}
public function testAfterException() {
$ex = new \OC\Authentication\Exceptions\UserAlreadyLoggedInException();
$ex = new UserAlreadyLoggedInException();
$this->urlGenerator->expects($this->once())
->method('linkToRoute')
->with('files.view.index')
->willReturn('redirect/url');
$expected = new \OCP\AppFramework\Http\RedirectResponse('redirect/url');
$expected = new RedirectResponse('redirect/url');
$this->assertEquals($expected, $this->middleware->afterException($this->controller, 'index', $ex));
}

View File

@ -26,6 +26,7 @@ namespace Test\AppFramework\Controller;
use OC\AppFramework\Http\Request;
use OCP\AppFramework\ApiController;
use OCP\IConfig;
use OCP\IRequestId;
class ChildApiController extends ApiController {
};
@ -38,12 +39,8 @@ class ApiControllerTest extends \Test\TestCase {
public function testCors() {
$request = new Request(
['server' => ['HTTP_ORIGIN' => 'test']],
$this->getMockBuilder('\OCP\Security\ISecureRandom')
->disableOriginalConstructor()
->getMock(),
$this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock()
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->controller = new ChildApiController('app', $request, 'verbs',
'headers', 100);

View File

@ -29,6 +29,8 @@ use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IRequestId;
use OC\AppFramework\DependencyInjection\DIContainer;
class ChildController extends Controller {
public function __construct($appName, $request) {
@ -75,15 +77,11 @@ class ControllerTest extends \Test\TestCase {
'session' => ['sezession' => 'kein'],
'method' => 'hi',
],
$this->getMockBuilder('\OCP\Security\ISecureRandom')
->disableOriginalConstructor()
->getMock(),
$this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock()
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->app = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer')
$this->app = $this->getMockBuilder(DIContainer::class)
->setMethods(['getAppName'])
->setConstructorArgs(['test'])
->getMock();

View File

@ -28,7 +28,7 @@ use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
use OCP\AppFramework\OCSController;
use OCP\IConfig;
use OCP\Security\ISecureRandom;
use OCP\IRequestId;
class ChildOCSController extends OCSController {
}
@ -42,12 +42,8 @@ class OCSControllerTest extends \Test\TestCase {
'HTTP_ORIGIN' => 'test',
],
],
$this->getMockBuilder(ISecureRandom::class)
->disableOriginalConstructor()
->getMock(),
$this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock()
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$controller = new ChildOCSController('app', $request, 'verbs',
'headers', 100);
@ -67,12 +63,8 @@ class OCSControllerTest extends \Test\TestCase {
public function testXML() {
$controller = new ChildOCSController('app', new Request(
[],
$this->getMockBuilder(ISecureRandom::class)
->disableOriginalConstructor()
->getMock(),
$this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock()
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
));
$controller->setOCSVersion(1);
@ -100,12 +92,8 @@ class OCSControllerTest extends \Test\TestCase {
public function testJSON() {
$controller = new ChildOCSController('app', new Request(
[],
$this->getMockBuilder(ISecureRandom::class)
->disableOriginalConstructor()
->getMock(),
$this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock()
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
));
$controller->setOCSVersion(1);
$expected = '{"ocs":{"meta":{"status":"ok","statuscode":100,"message":"OK",' .
@ -121,12 +109,8 @@ class OCSControllerTest extends \Test\TestCase {
public function testXMLV2() {
$controller = new ChildOCSController('app', new Request(
[],
$this->getMockBuilder(ISecureRandom::class)
->disableOriginalConstructor()
->getMock(),
$this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock()
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
));
$controller->setOCSVersion(2);
@ -152,12 +136,8 @@ class OCSControllerTest extends \Test\TestCase {
public function testJSONV2() {
$controller = new ChildOCSController('app', new Request(
[],
$this->getMockBuilder(ISecureRandom::class)
->disableOriginalConstructor()
->getMock(),
$this->getMockBuilder(IConfig::class)
->disableOriginalConstructor()
->getMock()
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
));
$controller->setOCSVersion(2);
$expected = '{"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK"},"data":{"test":"hi"}}}';

View File

@ -28,6 +28,7 @@ use OC\AppFramework\Middleware\MiddlewareDispatcher;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\IConfig;
use OCP\IRequestId;
// needed to test ordering
class TestMiddleware extends Middleware {
@ -129,8 +130,8 @@ class MiddlewareDispatcherTest extends \Test\TestCase {
->setConstructorArgs(['app',
new Request(
['method' => 'GET'],
$this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
$this->getMockBuilder(IConfig::class)->getMock()
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
)
])->getMock();
}
@ -272,7 +273,7 @@ class MiddlewareDispatcherTest extends \Test\TestCase {
public function testExceptionShouldRunAfterExceptionOfOnlyPreviouslyExecutedMiddlewares() {
$m1 = $this->getMiddleware();
$m2 = $this->getMiddleware(true);
$m3 = $this->getMockBuilder('\OCP\AppFramework\Middleware')->getMock();
$m3 = $this->createMock(Middleware::class);
$m3->expects($this->never())
->method('afterException');
$m3->expects($this->never())

View File

@ -24,9 +24,12 @@
namespace Test\AppFramework\Middleware;
use OC\AppFramework\Http\Request;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Middleware;
use OCP\IConfig;
use OCP\IRequestId;
use OC\AppFramework\DependencyInjection\DIContainer;
class ChildMiddleware extends Middleware {
};
@ -49,22 +52,22 @@ class MiddlewareTest extends \Test\TestCase {
$this->middleware = new ChildMiddleware();
$this->api = $this->getMockBuilder('OC\AppFramework\DependencyInjection\DIContainer')
$this->api = $this->getMockBuilder(DIContainer::class)
->disableOriginalConstructor()
->getMock();
$this->controller = $this->getMockBuilder('OCP\AppFramework\Controller')
$this->controller = $this->getMockBuilder(Controller::class)
->setMethods([])
->setConstructorArgs([
$this->api,
new Request(
[],
$this->getMockBuilder('\OCP\Security\ISecureRandom')->getMock(),
$this->getMockBuilder(IConfig::class)->getMock()
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
)
])->getMock();
$this->exception = new \Exception();
$this->response = $this->getMockBuilder('OCP\AppFramework\Http\Response')->getMock();
$this->response = $this->getMockBuilder(Response::class)->getMock();
}

View File

@ -21,7 +21,7 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\Security\ISecureRandom;
use OCP\IRequestId;
class CORSMiddlewareTest extends \Test\TestCase {
@ -52,7 +52,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
'HTTP_ORIGIN' => 'test'
]
],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->reflector->reflect($this, __FUNCTION__);
@ -71,7 +71,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
'HTTP_ORIGIN' => 'test'
]
],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler);
@ -88,7 +88,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
public function testNoOriginHeaderNoCORSHEADER() {
$request = new Request(
[],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->reflector->reflect($this, __FUNCTION__);
@ -112,7 +112,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
'HTTP_ORIGIN' => 'test'
]
],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->reflector->reflect($this, __FUNCTION__);
@ -130,7 +130,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
public function testNoCORSShouldAllowCookieAuth() {
$request = new Request(
[],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->reflector->reflect($this, __FUNCTION__);
@ -155,7 +155,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->session->expects($this->once())
@ -181,7 +181,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->session->expects($this->once())
@ -207,7 +207,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->session->expects($this->once())
@ -228,7 +228,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler);
@ -244,7 +244,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler);
@ -264,7 +264,7 @@ class CORSMiddlewareTest extends \Test\TestCase {
'PHP_AUTH_USER' => 'user',
'PHP_AUTH_PW' => 'pass'
]],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$middleware = new CORSMiddleware($request, $this->reflector, $this->session, $this->throttler);

View File

@ -42,9 +42,9 @@ use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IRequestId;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
class SecurityMiddlewareTest extends \Test\TestCase {
@ -500,7 +500,7 @@ class SecurityMiddlewareTest extends \Test\TestCase {
'REQUEST_URI' => 'nextcloud/index.php/apps/specialapp'
]
],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->middleware = $this->getMiddleware(false, false, false);
@ -534,7 +534,7 @@ class SecurityMiddlewareTest extends \Test\TestCase {
'REQUEST_URI' => 'nextcloud/index.php/apps/specialapp',
],
],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
@ -580,7 +580,7 @@ class SecurityMiddlewareTest extends \Test\TestCase {
'REQUEST_URI' => 'nextcloud/index.php/apps/specialapp'
]
],
$this->createMock(ISecureRandom::class),
$this->createMock(IRequestId::class),
$this->createMock(IConfig::class)
);
$this->middleware = $this->getMiddleware(false, false, false);

View File

@ -9,10 +9,13 @@
namespace Test\User;
use OC\AppFramework\Http\Request;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
use OC\Security\Bruteforce\Throttler;
use OC\Session\Memory;
use OC\User\LoginException;
use OC\User\Manager;
use OC\User\Session;
use OC\User\User;
@ -23,6 +26,7 @@ use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IRequestId;
use OCP\ISession;
use OCP\IUser;
use OCP\Lockdown\ILockdownManager;
@ -30,6 +34,7 @@ use OCP\Security\ISecureRandom;
use OCP\User\Events\PostLoginEvent;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use OC\Security\CSRF\CsrfTokenManager;
/**
* @group DB
@ -136,7 +141,7 @@ class SessionTest extends \Test\TestCase {
->method('getUID')
->willReturn('foo');
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession->setUser($user);
}
@ -147,7 +152,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('bar')
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
->will($this->throwException(new InvalidTokenException()));
$session->expects($this->exactly(2))
->method('set')
->with($this->callback(function ($key) {
@ -217,7 +222,7 @@ class SessionTest extends \Test\TestCase {
public function testLoginValidPasswordDisabled() {
$this->expectException(\OC\User\LoginException::class);
$this->expectException(LoginException::class);
$session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$session->expects($this->never())
@ -227,9 +232,9 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('bar')
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
->will($this->throwException(new InvalidTokenException()));
$managerMethods = get_class_methods(\OC\User\Manager::class);
$managerMethods = get_class_methods(Manager::class);
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
@ -257,13 +262,13 @@ class SessionTest extends \Test\TestCase {
$this->dispatcher->expects($this->never())
->method('dispatch');
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession->login('foo', 'bar');
}
public function testLoginInvalidPassword() {
$session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$managerMethods = get_class_methods(\OC\User\Manager::class);
$managerMethods = get_class_methods(Manager::class);
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
@ -276,7 +281,7 @@ class SessionTest extends \Test\TestCase {
])
->getMock();
$backend = $this->createMock(\Test\Util\User\Dummy::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$user = $this->createMock(IUser::class);
@ -287,7 +292,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('bar')
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
->will($this->throwException(new InvalidTokenException()));
$user->expects($this->never())
->method('isEnabled');
@ -308,7 +313,7 @@ class SessionTest extends \Test\TestCase {
public function testLoginNonExisting() {
$session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$manager = $this->createMock(Manager::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$session->expects($this->never())
->method('set');
@ -317,7 +322,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('bar')
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
->will($this->throwException(new InvalidTokenException()));
$manager->expects($this->once())
->method('checkPasswordNoLogging')
@ -328,13 +333,13 @@ class SessionTest extends \Test\TestCase {
}
public function testLogClientInNoTokenPasswordWith2fa() {
$this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class);
$this->expectException(PasswordLoginForbiddenException::class);
$manager = $this->createMock(Manager::class);
$session = $this->createMock(ISession::class);
$request = $this->createMock(IRequest::class);
/** @var \OC\User\Session $userSession */
/** @var Session $userSession */
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods(['login', 'supportsCookies', 'createSessionToken', 'getUser'])
@ -343,7 +348,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('doe')
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
->will($this->throwException(new InvalidTokenException()));
$this->config->expects($this->once())
->method('getSystemValue')
->with('token_auth_enforced', false)
@ -379,7 +384,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('doe')
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
->will($this->throwException(new InvalidTokenException()));
$this->config->expects($this->once())
->method('getSystemValue')
->with('token_auth_enforced', false)
@ -396,7 +401,7 @@ class SessionTest extends \Test\TestCase {
$session = $this->createMock(ISession::class);
$request = $this->createMock(IRequest::class);
/** @var \OC\User\Session $userSession */
/** @var Session $userSession */
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods(['isTokenPassword', 'login', 'supportsCookies', 'createSessionToken', 'getUser'])
@ -432,13 +437,13 @@ class SessionTest extends \Test\TestCase {
public function testLogClientInNoTokenPasswordNo2fa() {
$this->expectException(\OC\Authentication\Exceptions\PasswordLoginForbiddenException::class);
$this->expectException(PasswordLoginForbiddenException::class);
$manager = $this->createMock(Manager::class);
$session = $this->createMock(ISession::class);
$request = $this->createMock(IRequest::class);
/** @var \OC\User\Session $userSession */
/** @var Session $userSession */
$userSession = $this->getMockBuilder(Session::class)
->setConstructorArgs([$manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher])
->setMethods(['login', 'isTwoFactorEnforced'])
@ -447,7 +452,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with('doe')
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
->will($this->throwException(new InvalidTokenException()));
$this->config->expects($this->once())
->method('getSystemValue')
->with('token_auth_enforced', false)
@ -477,7 +482,7 @@ class SessionTest extends \Test\TestCase {
public function testRememberLoginValidToken() {
$session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$managerMethods = get_class_methods(\OC\User\Manager::class);
$managerMethods = get_class_methods(Manager::class);
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
@ -567,7 +572,7 @@ class SessionTest extends \Test\TestCase {
public function testRememberLoginInvalidSessionToken() {
$session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$managerMethods = get_class_methods(\OC\User\Manager::class);
$managerMethods = get_class_methods(Manager::class);
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
@ -612,7 +617,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('renewSessionToken')
->with($oldSessionId, $sessionId)
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
->will($this->throwException(new InvalidTokenException()));
$user->expects($this->never())
->method('getUID')
@ -632,7 +637,7 @@ class SessionTest extends \Test\TestCase {
public function testRememberLoginInvalidToken() {
$session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$managerMethods = get_class_methods(\OC\User\Manager::class);
$managerMethods = get_class_methods(Manager::class);
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
@ -685,7 +690,7 @@ class SessionTest extends \Test\TestCase {
public function testRememberLoginInvalidUser() {
$session = $this->getMockBuilder(Memory::class)->setConstructorArgs([''])->getMock();
$managerMethods = get_class_methods(\OC\User\Manager::class);
$managerMethods = get_class_methods(Manager::class);
//keep following methods intact in order to ensure hooks are working
$mockedManagerMethods = array_diff($managerMethods, ['__construct', 'emit', 'listen']);
$manager = $this->getMockBuilder(Manager::class)
@ -735,7 +740,7 @@ class SessionTest extends \Test\TestCase {
'bar' => new User('bar', null, $this->createMock(EventDispatcherInterface::class))
];
$manager = $this->getMockBuilder('\OC\User\Manager')
$manager = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();
@ -768,18 +773,18 @@ class SessionTest extends \Test\TestCase {
$manager = $this->createMock(Manager::class);
$session = $this->createMock(ISession::class);
$user = $this->createMock(IUser::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$random = $this->createMock(ISecureRandom::class);
$requestId = $this->createMock(IRequestId::class);
$config = $this->createMock(IConfig::class);
$csrf = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenManager')
$csrf = $this->getMockBuilder(CsrfTokenManager::class)
->disableOriginalConstructor()
->getMock();
$request = new \OC\AppFramework\Http\Request([
$request = new Request([
'server' => [
'HTTP_USER_AGENT' => 'Firefox',
]
], $random, $config, $csrf);
], $requestId, $config, $csrf);
$uid = 'user123';
$loginName = 'User123';
@ -796,7 +801,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with($password)
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
->will($this->throwException(new InvalidTokenException()));
$this->tokenProvider->expects($this->once())
->method('generateToken')
@ -809,18 +814,18 @@ class SessionTest extends \Test\TestCase {
$manager = $this->createMock(Manager::class);
$session = $this->createMock(ISession::class);
$user = $this->createMock(IUser::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$random = $this->createMock(ISecureRandom::class);
$requestId = $this->createMock(IRequestId::class);
$config = $this->createMock(IConfig::class);
$csrf = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenManager')
$csrf = $this->getMockBuilder(CsrfTokenManager::class)
->disableOriginalConstructor()
->getMock();
$request = new \OC\AppFramework\Http\Request([
$request = new Request([
'server' => [
'HTTP_USER_AGENT' => 'Firefox',
]
], $random, $config, $csrf);
], $requestId, $config, $csrf);
$uid = 'user123';
$loginName = 'User123';
@ -837,7 +842,7 @@ class SessionTest extends \Test\TestCase {
$this->tokenProvider->expects($this->once())
->method('getToken')
->with($password)
->will($this->throwException(new \OC\Authentication\Exceptions\InvalidTokenException()));
->will($this->throwException(new InvalidTokenException()));
$this->tokenProvider->expects($this->once())
->method('generateToken')
@ -847,24 +852,24 @@ class SessionTest extends \Test\TestCase {
}
public function testCreateSessionTokenWithTokenPassword() {
$manager = $this->getMockBuilder('\OC\User\Manager')
$manager = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();
$session = $this->createMock(ISession::class);
$token = $this->createMock(IToken::class);
$user = $this->createMock(IUser::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$random = $this->createMock(ISecureRandom::class);
$requestId = $this->createMock(IRequestId::class);
$config = $this->createMock(IConfig::class);
$csrf = $this->getMockBuilder('\OC\Security\CSRF\CsrfTokenManager')
$csrf = $this->getMockBuilder(CsrfTokenManager::class)
->disableOriginalConstructor()
->getMock();
$request = new \OC\AppFramework\Http\Request([
$request = new Request([
'server' => [
'HTTP_USER_AGENT' => 'Firefox',
]
], $random, $config, $csrf);
], $requestId, $config, $csrf);
$uid = 'user123';
$loginName = 'User123';
@ -896,11 +901,11 @@ class SessionTest extends \Test\TestCase {
}
public function testCreateSessionTokenWithNonExistentUser() {
$manager = $this->getMockBuilder('\OC\User\Manager')
$manager = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();
$session = $this->createMock(ISession::class);
$userSession = new \OC\User\Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$userSession = new Session($manager, $session, $this->timeFactory, $this->tokenProvider, $this->config, $this->random, $this->lockdownManager, $this->logger, $this->dispatcher);
$request = $this->createMock(IRequest::class);
$uid = 'user123';