diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/LoginControllerTest.php | 10 | ||||
-rwxr-xr-x | tests/acceptance/run.sh | 59 | ||||
-rw-r--r-- | tests/bootstrap.php | 2 | ||||
-rw-r--r-- | tests/lib/Files/Config/UserMountCacheTest.php | 24 |
4 files changed, 64 insertions, 31 deletions
diff --git a/tests/Core/Controller/LoginControllerTest.php b/tests/Core/Controller/LoginControllerTest.php index c9ab8e7476d..ca32a04efe1 100644 --- a/tests/Core/Controller/LoginControllerTest.php +++ b/tests/Core/Controller/LoginControllerTest.php @@ -23,7 +23,6 @@ namespace Tests\Core\Controller; use OC\Authentication\TwoFactorAuth\Manager; use OC\Core\Controller\LoginController; -use OC\Security\Bruteforce\Throttler; use OC\User\Session; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; @@ -281,7 +280,7 @@ class LoginControllerTest extends TestCase { public function testLoginWithInvalidCredentials() { $user = 'MyUserName'; $password = 'secret'; - $loginPageUrl = 'some url'; + $loginPageUrl = '/login?redirect_url=/apps/files'; $this->request ->expects($this->once()) @@ -292,7 +291,10 @@ class LoginControllerTest extends TestCase { ->will($this->returnValue(false)); $this->urlGenerator->expects($this->once()) ->method('linkToRoute') - ->with('core.login.showLoginForm') + ->with('core.login.showLoginForm', [ + 'user' => 'MyUserName', + 'redirect_url' => '/apps/files', + ]) ->will($this->returnValue($loginPageUrl)); $this->userSession->expects($this->never()) @@ -304,7 +306,7 @@ class LoginControllerTest extends TestCase { $expected = new \OCP\AppFramework\Http\RedirectResponse($loginPageUrl); $expected->throttle(); - $this->assertEquals($expected, $this->loginController->tryLogin($user, $password, '')); + $this->assertEquals($expected, $this->loginController->tryLogin($user, $password, '/apps/files')); } public function testLoginWithValidCredentials() { diff --git a/tests/acceptance/run.sh b/tests/acceptance/run.sh index 3969782300d..42a718d46e2 100755 --- a/tests/acceptance/run.sh +++ b/tests/acceptance/run.sh @@ -48,31 +48,34 @@ # (probably you will not have containers nor images with those names, but just # in case). -# Switch between timeout on linux and gtimeout on macOS (same for mktemp and -# gmktemp) - -case "$OSTYPE" in - darwin*) - INSTALLED=$(which gtimeout) - if [ "$INSTALLED" == "" ]; then - echo "Please install coreutils (brew install coreutils)" - exit 1; - fi - - MKTEMP=gmktemp - TIMEOUT=gtimeout - DOCKEROPTION="-e no_proxy=localhost " - ;; - linux*) - MKTEMP=mktemp - TIMEOUT=timeout - DOCKEROPTION=" " - ;; - *) - echo "Operating system ($OSTYPE) not supported" - exit 1 - ;; -esac +# Sets the variables that abstract the differences in command names and options +# between operating systems. +# +# Switches between timeout on GNU/Linux and gtimeout on macOS (same for mktemp +# and gmktemp). +function setOperatingSystemAbstractionVariables() { + case "$OSTYPE" in + darwin*) + if [ "$(which gtimeout)" == "" ]; then + echo "Please install coreutils (brew install coreutils)" + exit 1 + fi + + MKTEMP=gmktemp + TIMEOUT=gtimeout + DOCKER_OPTIONS="-e no_proxy=localhost " + ;; + linux*) + MKTEMP=mktemp + TIMEOUT=timeout + DOCKER_OPTIONS=" " + ;; + *) + echo "Operating system ($OSTYPE) not supported" + exit 1 + ;; + esac +} # Launches the Selenium server in a Docker container. # @@ -105,12 +108,12 @@ function prepareSelenium() { SELENIUM_CONTAINER=selenium-nextcloud-local-test-acceptance echo "Starting Selenium server" - docker run --detach --name=$SELENIUM_CONTAINER --publish 4444:4444 --publish 5900:5900 $DOCKEROPTION selenium/standalone-firefox-debug:2.53.1-beryllium + docker run --detach --name=$SELENIUM_CONTAINER --publish 4444:4444 --publish 5900:5900 $DOCKER_OPTIONS selenium/standalone-firefox-debug:2.53.1-beryllium echo "Waiting for Selenium server to be ready" if ! $TIMEOUT 10s bash -c "while ! curl 127.0.0.1:4444 >/dev/null 2>&1; do sleep 1; done"; then echo "Could not start Selenium server; running" \ - "\"docker run --rm --publish 4444:4444 --publish 5900:5900 $DOCKEROPTION selenium/standalone-firefox-debug:2.53.1-beryllium\"" \ + "\"docker run --rm --publish 4444:4444 --publish 5900:5900 $DOCKER_OPTIONS selenium/standalone-firefox-debug:2.53.1-beryllium\"" \ "could give you a hint of the problem" exit 1 @@ -197,6 +200,8 @@ cd "$(dirname $0)" # If no parameter is provided to this script all the acceptance tests are run. SCENARIO_TO_RUN=$1 +setOperatingSystemAbstractionVariables + prepareSelenium prepareDocker diff --git a/tests/bootstrap.php b/tests/bootstrap.php index c58d9f58522..44c42d353e9 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -19,3 +19,5 @@ if (!class_exists('PHPUnit_Framework_TestCase')) { } OC_Hook::clear(); + +set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/share/php'); diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index 376f0a0276c..f38bd3fcdc3 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -47,6 +47,7 @@ class UserMountCacheTest extends TestCase { $userBackend = new Dummy(); $userBackend->createUser('u1', ''); $userBackend->createUser('u2', ''); + $userBackend->createUser('u3', ''); $this->userManager->registerBackend($userBackend); $this->cache = new \OC\Files\Config\UserMountCache($this->connection, $this->userManager, $this->createMock(Log::class)); } @@ -211,6 +212,7 @@ class UserMountCacheTest extends TestCase { public function testGetMountsForUser() { $user1 = $this->userManager->get('u1'); $user2 = $this->userManager->get('u2'); + $user3 = $this->userManager->get('u3'); list($storage1, $id1) = $this->getStorage(1); list($storage2, $id2) = $this->getStorage(2); @@ -219,9 +221,12 @@ class UserMountCacheTest extends TestCase { $this->cache->registerMounts($user1, [$mount1, $mount2]); $this->cache->registerMounts($user2, [$mount2]); + $this->cache->registerMounts($user3, [$mount2]); $this->clearCache(); + $user3->delete(); + $cachedMounts = $this->cache->getMountsForUser($user1); $this->assertCount(2, $cachedMounts); @@ -234,6 +239,9 @@ class UserMountCacheTest extends TestCase { $this->assertEquals($user1, $cachedMounts[1]->getUser()); $this->assertEquals($id2, $cachedMounts[1]->getRootId()); $this->assertEquals(2, $cachedMounts[1]->getStorageId()); + + $cachedMounts = $this->cache->getMountsForUser($user3); + $this->assertEmpty($cachedMounts); } public function testGetMountsByStorageId() { @@ -431,4 +439,20 @@ class UserMountCacheTest extends TestCase { $this->assertCount(0, $cachedMounts); } + + + public function testGetMountsForFileIdDeletedUser() { + $user1 = $this->userManager->get('u1'); + + list($storage1, $rootId) = $this->getStorage(2); + $rootId = $this->createCacheEntry('', 2); + $mount1 = new MountPoint($storage1, '/foo/'); + $this->cache->registerMounts($user1, [$mount1]); + + $user1->delete(); + $this->clearCache(); + + $cachedMounts = $this->cache->getMountsForFileId($rootId); + $this->assertEmpty($cachedMounts); + } } |