private IURLGenerator $urlGenerator;
private Defaults $defaults;
private Throttler $throttler;
- private Chain $loginChain;
private IInitialStateService $initialStateService;
private WebAuthnManager $webAuthnManager;
private IManager $manager;
IURLGenerator $urlGenerator,
Defaults $defaults,
Throttler $throttler,
- Chain $loginChain,
IInitialStateService $initialStateService,
WebAuthnManager $webAuthnManager,
IManager $manager,
$this->urlGenerator = $urlGenerator;
$this->defaults = $defaults;
$this->throttler = $throttler;
- $this->loginChain = $loginChain;
$this->initialStateService = $initialStateService;
$this->webAuthnManager = $webAuthnManager;
$this->manager = $manager;
* @NoCSRFRequired
* @BruteForceProtection(action=login)
*
- * @param string $user
- * @param string $password
- * @param string $redirect_url
- * @param string $timezone
- * @param string $timezone_offset
- *
* @return RedirectResponse
*/
- public function tryLogin(string $user,
+ public function tryLogin(Chain $loginChain,
+ string $user,
string $password,
string $redirect_url = null,
string $timezone = '',
$timezone,
$timezone_offset
);
- $result = $this->loginChain->process($data);
+ $result = $loginChain->process($data);
if (!$result->isSuccess()) {
return $this->createLoginFailedResponse(
$data->getUsername(),
use OCP\Diagnostics\IEventLogger;
use OCP\IConfig;
use OCP\IRequest;
+use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
/**
/** @var IEventLogger */
private $eventLogger;
+ private ContainerInterface $appContainer;
+
/**
* @param Http $protocol the http protocol with contains all status headers
* @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which
IConfig $config,
ConnectionAdapter $connection,
LoggerInterface $logger,
- IEventLogger $eventLogger) {
+ IEventLogger $eventLogger,
+ ContainerInterface $appContainer) {
$this->protocol = $protocol;
$this->middlewareDispatcher = $middlewareDispatcher;
$this->reflector = $reflector;
$this->connection = $connection;
$this->logger = $logger;
$this->eventLogger = $eventLogger;
+ $this->appContainer = $appContainer;
}
$value = false;
} elseif ($value !== null && \in_array($type, $types, true)) {
settype($value, $type);
+ } elseif ($value === null && $type !== null && $this->appContainer->has($type)) {
+ $value = $this->appContainer->get($type);
}
$arguments[] = $value;
/** @var Throttler|MockObject */
private $throttler;
- /** @var LoginChain|MockObject */
- private $chain;
-
/** @var IInitialStateService|MockObject */
private $initialStateService;
$this->twoFactorManager = $this->createMock(Manager::class);
$this->defaults = $this->createMock(Defaults::class);
$this->throttler = $this->createMock(Throttler::class);
- $this->chain = $this->createMock(LoginChain::class);
$this->initialStateService = $this->createMock(IInitialStateService::class);
$this->webAuthnManager = $this->createMock(\OC\Authentication\WebAuthn\Manager::class);
$this->notificationManager = $this->createMock(IManager::class);
$this->urlGenerator,
$this->defaults,
$this->throttler,
- $this->chain,
$this->initialStateService,
$this->webAuthnManager,
$this->notificationManager,
$this->assertEquals($expectedResponse, $this->loginController->showLoginForm('0', ''));
}
- public function testLoginWithInvalidCredentials() {
+ public function testLoginWithInvalidCredentials(): void {
$user = 'MyUserName';
$password = 'secret';
$loginPageUrl = '/login?redirect_url=/apps/files';
-
+ $loginChain = $this->createMock(LoginChain::class);
$this->request
->expects($this->once())
->method('passesCSRFCheck')
'/apps/files'
);
$loginResult = LoginResult::failure($loginData, LoginController::LOGIN_MSG_INVALIDPASSWORD);
- $this->chain->expects($this->once())
+ $loginChain->expects($this->once())
->method('process')
->with($this->equalTo($loginData))
->willReturn($loginResult);
$expected = new RedirectResponse($loginPageUrl);
$expected->throttle(['user' => 'MyUserName']);
- $response = $this->loginController->tryLogin($user, $password, '/apps/files');
+ $response = $this->loginController->tryLogin($loginChain, $user, $password, '/apps/files');
$this->assertEquals($expected, $response);
}
public function testLoginWithValidCredentials() {
$user = 'MyUserName';
$password = 'secret';
-
+ $loginChain = $this->createMock(LoginChain::class);
$this->request
->expects($this->once())
->method('passesCSRFCheck')
$password
);
$loginResult = LoginResult::success($loginData);
- $this->chain->expects($this->once())
+ $loginChain->expects($this->once())
->method('process')
->with($this->equalTo($loginData))
->willReturn($loginResult);
->willReturn('/default/foo');
$expected = new RedirectResponse('/default/foo');
- $this->assertEquals($expected, $this->loginController->tryLogin($user, $password));
+ $this->assertEquals($expected, $this->loginController->tryLogin($loginChain, $user, $password));
}
public function testLoginWithoutPassedCsrfCheckAndNotLoggedIn(): void {
->willReturn('jane');
$password = 'secret';
$originalUrl = 'another%20url';
-
+ $loginChain = $this->createMock(LoginChain::class);
$this->request
->expects($this->once())
->method('passesCSRFCheck')
$this->userSession->expects($this->never())
->method('createRememberMeToken');
- $response = $this->loginController->tryLogin('Jane', $password, $originalUrl);
+ $response = $this->loginController->tryLogin($loginChain, 'Jane', $password, $originalUrl);
$expected = new RedirectResponse('');
$expected->throttle(['user' => 'Jane']);
$password = 'secret';
$originalUrl = 'another url';
$redirectUrl = 'http://localhost/another url';
-
+ $loginChain = $this->createMock(LoginChain::class);
$this->request
->expects($this->once())
->method('passesCSRFCheck')
->with('remember_login_cookie_lifetime')
->willReturn(1234);
- $response = $this->loginController->tryLogin('Jane', $password, $originalUrl);
+ $response = $this->loginController->tryLogin($loginChain, 'Jane', $password, $originalUrl);
$expected = new RedirectResponse($redirectUrl);
$this->assertEquals($expected, $response);
$user = 'MyUserName';
$password = 'secret';
$redirectUrl = 'https://next.cloud/apps/mail';
-
+ $loginChain = $this->createMock(LoginChain::class);
$this->request
->expects($this->once())
->method('passesCSRFCheck')
'/apps/mail'
);
$loginResult = LoginResult::success($loginData);
- $this->chain->expects($this->once())
+ $loginChain->expects($this->once())
->method('process')
->with($this->equalTo($loginData))
->willReturn($loginResult);
->willReturn($redirectUrl);
$expected = new RedirectResponse($redirectUrl);
- $response = $this->loginController->tryLogin($user, $password, '/apps/mail');
+ $response = $this->loginController->tryLogin($loginChain, $user, $password, '/apps/mail');
$this->assertEquals($expected, $response);
}
public function testToNotLeakLoginName() {
+ $loginChain = $this->createMock(LoginChain::class);
$this->request
->expects($this->once())
->method('passesCSRFCheck')
'/apps/files'
);
$loginResult = LoginResult::failure($loginData, LoginController::LOGIN_MSG_INVALIDPASSWORD);
- $this->chain->expects($this->once())
+ $loginChain->expects($this->once())
->method('process')
->with($this->equalTo($loginData))
->willReturnCallback(function (LoginData $data) use ($loginResult) {
$expected->throttle(['user' => 'john']);
$response = $this->loginController->tryLogin(
+ $loginChain,
'john@doe.com',
'just wrong',
'/apps/files'
use OCP\IConfig;
use OCP\IRequest;
use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use OCP\IRequestId;
private $config;
/** @var LoggerInterface|MockObject */
private $logger;
- /**
- * @var IEventLogger|MockObject
- */
+ /** @var IEventLogger|MockObject */
private $eventLogger;
+ /** @var ContainerInterface|MockObject */
+ private $container;
protected function setUp(): void {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->eventLogger = $this->createMock(IEventLogger::class);
+ $this->container = $this->createMock(ContainerInterface::class);
$app = $this->getMockBuilder(
'OC\AppFramework\DependencyInjection\DIContainer')
->disableOriginalConstructor()
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container,
);
$this->response = $this->createMock(Response::class);
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);
$this->config,
\OC::$server->getDatabaseConnection(),
$this->logger,
- $this->eventLogger
+ $this->eventLogger,
+ $this->container
);
$controller = new TestController('app', $this->request);