request = $this->createMock(IRequest::class); $this->config = $this->createMock(IConfig::class); $this->appConfig = $this->createMock(IAppConfig::class); $this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->l10n = $this->createMock(L10N::class); $this->appManager = $this->createMock(IAppManager::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->imageManager = $this->createMock(ImageManager::class); $this->themesService = $this->createMock(ThemesService::class); $this->navigationManager = $this->createMock(INavigationManager::class); $timeFactory = $this->createMock(ITimeFactory::class); $timeFactory->expects($this->any()) ->method('getTime') ->willReturn(123); $this->overwriteService(ITimeFactory::class, $timeFactory); $this->themingController = new ThemingController( 'theming', $this->request, $this->config, $this->appConfig, $this->themingDefaults, $this->l10n, $this->urlGenerator, $this->appManager, $this->imageManager, $this->themesService, $this->navigationManager, ); parent::setUp(); } public function dataUpdateStylesheetSuccess() { return [ ['name', str_repeat('a', 250), 'Saved'], ['url', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'], ['slogan', str_repeat('a', 500), 'Saved'], ['color', '#0082c9', 'Saved'], ['color', '#0082C9', 'Saved'], ['color', '#0082C9', 'Saved'], ['imprintUrl', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'], ['privacyUrl', 'https://nextcloud.com/' . str_repeat('a', 478), 'Saved'], ]; } /** * @dataProvider dataUpdateStylesheetSuccess * * @param string $setting * @param string $value * @param string $message */ public function testUpdateStylesheetSuccess($setting, $value, $message): void { $this->themingDefaults ->expects($this->once()) ->method('set') ->with($setting, $value); $this->l10n ->expects($this->once()) ->method('t') ->willReturnCallback(function ($str) { return $str; }); $expected = new DataResponse( [ 'data' => [ 'message' => $message, ], 'status' => 'success', ] ); $this->assertEquals($expected, $this->themingController->updateStylesheet($setting, $value)); } public function dataUpdateStylesheetError() { $urls = [ 'url' => 'web address', 'imprintUrl' => 'legal notice address', 'privacyUrl' => 'privacy policy address', ]; $urlTests = []; foreach ($urls as $urlKey => $urlName) { // Check length limit $urlTests[] = [$urlKey, 'http://example.com/' . str_repeat('a', 501), "The given {$urlName} is too long"]; // Check potential evil javascript $urlTests[] = [$urlKey, 'javascript:alert(1)', "The given {$urlName} is not a valid URL"]; // Check XSS $urlTests[] = [$urlKey, 'https://example.com/">