summaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-03-08 11:27:52 +0100
committerGitHub <noreply@github.com>2018-03-08 11:27:52 +0100
commita2db959f5c43ac6aa50b30c65ef73150c9b720b6 (patch)
tree5a73b59f2579e3d2b41e6bc6801d1bd78012f69b /tests/lib/AppFramework
parent069e3f50a7b972535957ad605865d62d9ba91141 (diff)
parent3ad7daeda5a320276021e72684bfed4469cbae37 (diff)
downloadnextcloud-server-a2db959f5c43ac6aa50b30c65ef73150c9b720b6.tar.gz
nextcloud-server-a2db959f5c43ac6aa50b30c65ef73150c9b720b6.zip
Merge pull request #8593 from eneiluj/master
Allow public page access to apps with group restrictions
Diffstat (limited to 'tests/lib/AppFramework')
-rw-r--r--tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php88
1 files changed, 78 insertions, 10 deletions
diff --git a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
index a631fe59a60..f51f7e9a1c6 100644
--- a/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
+++ b/tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
@@ -95,22 +95,19 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$this->contentSecurityPolicyManager = $this->createMock(ContentSecurityPolicyManager::class);
$this->csrfTokenManager = $this->createMock(CsrfTokenManager::class);
$this->cspNonceManager = $this->createMock(ContentSecurityPolicyNonceManager::class);
- $this->appManager = $this->createMock(IAppManager::class);
$this->l10n = $this->createMock(IL10N::class);
- $this->appManager->expects($this->any())
- ->method('isEnabledForUser')
- ->willReturn(true);
$this->middleware = $this->getMiddleware(true, true);
$this->secException = new SecurityException('hey', false);
$this->secAjaxException = new SecurityException('hey', true);
}
- /**
- * @param bool $isLoggedIn
- * @param bool $isAdminUser
- * @return SecurityMiddleware
- */
- private function getMiddleware($isLoggedIn, $isAdminUser) {
+ private function getMiddleware(bool $isLoggedIn, bool $isAdminUser, bool $isAppEnabledForUser = true): SecurityMiddleware {
+
+ $this->appManager = $this->createMock(IAppManager::class);
+ $this->appManager->expects($this->any())
+ ->method('isEnabledForUser')
+ ->willReturn($isAppEnabledForUser);
+
return new SecurityMiddleware(
$this->request,
$this->reader,
@@ -667,4 +664,75 @@ class SecurityMiddlewareTest extends \Test\TestCase {
$this->assertEquals($response, $this->middleware->afterController($this->controller, 'test', $response));
}
+
+ public function dataRestrictedApp() {
+ return [
+ [false, false, false,],
+ [false, false, true,],
+ [false, true, false,],
+ [false, true, true,],
+ [ true, false, false,],
+ [ true, false, true,],
+ [ true, true, false,],
+ [ true, true, true,],
+ ];
+ }
+
+ /**
+ * @PublicPage
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ */
+ public function testRestrictedAppLoggedInPublicPage() {
+ $middleware = $this->getMiddleware(true, false);
+ $this->reader->reflect(__CLASS__,__FUNCTION__);
+
+ $this->appManager->method('getAppPath')
+ ->with('files')
+ ->willReturn('foo');
+
+ $this->appManager->method('isEnabledForUser')
+ ->with('files')
+ ->willReturn(false);
+
+ $middleware->beforeController($this->controller, __FUNCTION__);
+ $this->addToAssertionCount(1);
+ }
+
+ /**
+ * @PublicPage
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ */
+ public function testRestrictedAppNotLoggedInPublicPage() {
+ $middleware = $this->getMiddleware(false, false);
+ $this->reader->reflect(__CLASS__,__FUNCTION__);
+
+ $this->appManager->method('getAppPath')
+ ->with('files')
+ ->willReturn('foo');
+
+ $this->appManager->method('isEnabledForUser')
+ ->with('files')
+ ->willReturn(false);
+
+ $middleware->beforeController($this->controller, __FUNCTION__);
+ $this->addToAssertionCount(1);
+ }
+
+ /**
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ */
+ public function testRestrictedAppLoggedIn() {
+ $middleware = $this->getMiddleware(true, false, false);
+ $this->reader->reflect(__CLASS__,__FUNCTION__);
+
+ $this->appManager->method('getAppPath')
+ ->with('files')
+ ->willReturn('foo');
+
+ $this->expectException(AppNotEnabledException::class);
+ $middleware->beforeController($this->controller, __FUNCTION__);
+ }
}