Skip to content

Commit

Permalink
Fixing unit tests ...
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Oct 27, 2017
1 parent 3b31cf2 commit f116830
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions apps/dav/tests/unit/Connector/Sabre/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@

namespace OCA\DAV\Tests\unit\Connector\Sabre;

use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\User\Session;
use OCA\DAV\Connector\Sabre\Auth;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUser;
Expand All @@ -43,29 +45,29 @@
* @group DB
*/
class AuthTest extends TestCase {
/** @var ISession */
/** @var ISession | \PHPUnit_Framework_MockObject_MockObject */
private $session;
/** @var \OCA\DAV\Connector\Sabre\Auth */
/** @var Auth */
private $auth;
/** @var Session */
/** @var Session | \PHPUnit_Framework_MockObject_MockObject */
private $userSession;
/** @var IRequest */
/** @var IRequest | \PHPUnit_Framework_MockObject_MockObject */
private $request;
/** @var Manager */
/** @var Manager | \PHPUnit_Framework_MockObject_MockObject */
private $twoFactorManager;

public function setUp() {
parent::setUp();
$this->session = $this->getMockBuilder('\OCP\ISession')
$this->session = $this->getMockBuilder(ISession::class)
->disableOriginalConstructor()->getMock();
$this->userSession = $this->getMockBuilder('\OC\User\Session')
$this->userSession = $this->getMockBuilder(Session::class)
->disableOriginalConstructor()->getMock();
$this->request = $this->getMockBuilder('\OCP\IRequest')
$this->request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()->getMock();
$this->twoFactorManager = $this->getMockBuilder('\OC\Authentication\TwoFactorAuth\Manager')
$this->twoFactorManager = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();
$this->auth = new \OCA\DAV\Connector\Sabre\Auth(
$this->auth = new Auth(
$this->session,
$this->userSession,
$this->request,
Expand Down Expand Up @@ -114,6 +116,10 @@ public function testValidateUserPassOfAlreadyDAVAuthenticatedUser() {
->expects($this->once())
->method('isLoggedIn')
->will($this->returnValue(true));
$this->userSession
->expects($this->once())
->method('verifyAuthHeaders')
->will($this->returnValue(true));
$this->userSession
->expects($this->exactly(2))
->method('getUser')
Expand Down Expand Up @@ -141,6 +147,10 @@ public function testValidateUserPassOfInvalidDAVAuthenticatedUser() {
->expects($this->once())
->method('isLoggedIn')
->will($this->returnValue(true));
$this->userSession
->expects($this->once())
->method('verifyAuthHeaders')
->will($this->returnValue(true));
$this->userSession
->expects($this->once())
->method('getUser')
Expand Down Expand Up @@ -168,6 +178,10 @@ public function testValidateUserPassOfInvalidDAVAuthenticatedUserWithValidPasswo
->expects($this->once())
->method('isLoggedIn')
->will($this->returnValue(true));
$this->userSession
->expects($this->once())
->method('verifyAuthHeaders')
->will($this->returnValue(true));
$this->userSession
->expects($this->exactly(3))
->method('getUser')
Expand Down Expand Up @@ -222,7 +236,7 @@ public function testValidateUserPassWithPasswordLoginForbidden() {
->expects($this->once())
->method('logClientIn')
->with('MyTestUser', 'MyTestPassword')
->will($this->throwException(new \OC\Authentication\Exceptions\PasswordLoginForbiddenException()));
->will($this->throwException(new PasswordLoginForbiddenException()));
$this->session
->expects($this->once())
->method('close');
Expand All @@ -231,9 +245,11 @@ public function testValidateUserPassWithPasswordLoginForbidden() {
}

public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForNonGet() {
/** @var RequestInterface | \PHPUnit_Framework_MockObject_MockObject $request */
$request = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var ResponseInterface | \PHPUnit_Framework_MockObject_MockObject $response */
$response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -274,9 +290,11 @@ public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForNonGet() {
}

public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenAndCorrectlyDavAuthenticated() {
/** @var RequestInterface | \PHPUnit_Framework_MockObject_MockObject $request */
$request = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var ResponseInterface | \PHPUnit_Framework_MockObject_MockObject $response */
$response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -324,9 +342,11 @@ public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenAndCorrectlyDavAu
* @expectedExceptionMessage 2FA challenge not passed.
*/
public function testAuthenticateAlreadyLoggedInWithoutTwoFactorChallengePassed() {
/** @var RequestInterface | \PHPUnit_Framework_MockObject_MockObject $request */
$request = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var ResponseInterface | \PHPUnit_Framework_MockObject_MockObject $response */
$response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -377,9 +397,11 @@ public function testAuthenticateAlreadyLoggedInWithoutTwoFactorChallengePassed()
* @expectedExceptionMessage CSRF check not passed.
*/
public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenAndIncorrectlyDavAuthenticated() {
/** @var RequestInterface | \PHPUnit_Framework_MockObject_MockObject $request */
$request = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var ResponseInterface | \PHPUnit_Framework_MockObject_MockObject $response */
$response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -423,9 +445,11 @@ public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenAndIncorrectlyDav
}

public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForNonGetAndDesktopClient() {
/** @var RequestInterface | \PHPUnit_Framework_MockObject_MockObject $request */
$request = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var ResponseInterface | \PHPUnit_Framework_MockObject_MockObject $response */
$response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -470,9 +494,11 @@ public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForNonGetAndDeskt
}

public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForGet() {
/** @var RequestInterface | \PHPUnit_Framework_MockObject_MockObject $request */
$request = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var ResponseInterface | \PHPUnit_Framework_MockObject_MockObject $response */
$response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -505,9 +531,11 @@ public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForGet() {
}

public function testAuthenticateAlreadyLoggedInWithCsrfTokenForGet() {
/** @var RequestInterface | \PHPUnit_Framework_MockObject_MockObject $request */
$request = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var ResponseInterface | \PHPUnit_Framework_MockObject_MockObject $response */
$response = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -558,11 +586,11 @@ public function testAuthenticateNoBasicAuthenticateHeadersProvided() {
* @expectedExceptionMessage Cannot authenticate over ajax calls
*/
public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjax() {
/** @var \Sabre\HTTP\RequestInterface $httpRequest */
/** @var RequestInterface | \PHPUnit_Framework_MockObject_MockObject $httpRequest */
$httpRequest = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var \Sabre\HTTP\ResponseInterface $httpResponse */
/** @var ResponseInterface $httpResponse */
$httpResponse = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand All @@ -579,11 +607,11 @@ public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjax() {
}

public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjaxButUserIsStillLoggedIn() {
/** @var \Sabre\HTTP\RequestInterface $httpRequest */
/** @var RequestInterface | \PHPUnit_Framework_MockObject_MockObject $httpRequest */
$httpRequest = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMock();
/** @var \Sabre\HTTP\ResponseInterface $httpResponse */
/** @var ResponseInterface $httpResponse */
$httpResponse = $this->getMockBuilder(ResponseInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down

0 comments on commit f116830

Please sign in to comment.