diff options
Diffstat (limited to 'core/js/tests')
-rw-r--r-- | core/js/tests/html-domparser.js | 26 | ||||
-rw-r--r-- | core/js/tests/specHelper.js | 34 | ||||
-rw-r--r-- | core/js/tests/specs/coreSpec.js | 175 | ||||
-rw-r--r-- | core/js/tests/specs/files/clientSpec.js | 23 | ||||
-rw-r--r-- | core/js/tests/specs/jquery.avatarSpec.js | 10 | ||||
-rw-r--r-- | core/js/tests/specs/jquery.contactsmenuSpec.js | 9 | ||||
-rw-r--r-- | core/js/tests/specs/jquery.placeholderSpec.js | 9 | ||||
-rw-r--r-- | core/js/tests/specs/l10nSpec.js | 81 | ||||
-rw-r--r-- | core/js/tests/specs/mimeTypeSpec.js | 20 | ||||
-rw-r--r-- | core/js/tests/specs/oc-backbone-webdavSpec.js | 23 | ||||
-rw-r--r-- | core/js/tests/specs/public/commentsSpec.js | 19 | ||||
-rw-r--r-- | core/js/tests/specs/setupchecksSpec.js | 1033 | ||||
-rw-r--r-- | core/js/tests/specs/systemtags/systemtagsSpec.js | 23 | ||||
-rw-r--r-- | core/js/tests/specs/systemtags/systemtagscollectionSpec.js | 22 | ||||
-rw-r--r-- | core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js | 23 |
15 files changed, 82 insertions, 1448 deletions
diff --git a/core/js/tests/html-domparser.js b/core/js/tests/html-domparser.js index ea22f9b8752..945d4b1f441 100644 --- a/core/js/tests/html-domparser.js +++ b/core/js/tests/html-domparser.js @@ -1,10 +1,13 @@ -/* +/** * DOMParser HTML extension * 2012-09-04 * * By Eli Grey, http://eligrey.com * Public domain. * NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. + * + * SPDX-FileCopyrightText: 2012 Eli Grey, http://eligrey.com + * SPDX-License-Identifier: CC0-1.0 */ /*! @source https://gist.github.com/1129031 */ @@ -13,10 +16,8 @@ (function(DOMParser) { "use strict"; - var - DOMParser_proto = DOMParser.prototype - , real_parseFromString = DOMParser_proto.parseFromString - ; + var DOMParser_proto = DOMParser.prototype; + var real_parseFromString = DOMParser_proto.parseFromString; // Firefox/Opera/IE throw errors on unsupported types try { @@ -29,15 +30,12 @@ DOMParser_proto.parseFromString = function(markup, type) { if (/^\s*text\/html\s*(?:;|$)/i.test(type)) { - var - doc = document.implementation.createHTMLDocument("") - ; - if (markup.toLowerCase().indexOf('<!doctype') > -1) { - doc.documentElement.innerHTML = markup; - } - else { - doc.body.innerHTML = markup; - } + var doc = document.implementation.createHTMLDocument(""); + if (markup.toLowerCase().indexOf('<!doctype') > -1) { + doc.documentElement.innerHTML = markup; + } else { + doc.body.innerHTML = markup; + } return doc; } else { return real_parseFromString.apply(this, arguments); diff --git a/core/js/tests/specHelper.js b/core/js/tests/specHelper.js index 498eed757d6..77958488df7 100644 --- a/core/js/tests/specHelper.js +++ b/core/js/tests/specHelper.js @@ -1,23 +1,8 @@ /** -* ownCloud -* -* @author Vincent Petry -* @copyright 2014 Vincent Petry <pvince81@owncloud.com> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2014 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ /** * Simulate the variables that are normally set by PHP code @@ -95,11 +80,14 @@ window._oc_capabilities = { } // FIXME: OC.webroot is supposed to be only the path!!! -OC.webroot = location.href + '/'; -OC.appswebroots = { +window._oc_webroot = location.href + '/'; +window._oc_appswebroots = { "files": window.webroot + '/apps/files/', "files_sharing": window.webroot + '/apps/files_sharing/' }; + +window.OC ??= {}; + OC.config = { session_lifetime: 600 * 1000, session_keepalive: false, @@ -126,6 +114,10 @@ window.Snap.prototype = { window.isPhantom = /phantom/i.test(navigator.userAgent); document.documentElement.lang = navigator.language; +const el = document.createElement('input'); +el.id = 'initial-state-core-config'; +el.value = btoa(JSON.stringify(window.OC.config)) +document.body.append(el); // global setup for all tests (function setupTests() { diff --git a/core/js/tests/specs/coreSpec.js b/core/js/tests/specs/coreSpec.js index b7339ce7188..3cbd7623a47 100644 --- a/core/js/tests/specs/coreSpec.js +++ b/core/js/tests/specs/coreSpec.js @@ -1,23 +1,8 @@ /** -* ownCloud -* -* @author Vincent Petry -* @copyright 2014 Vincent Petry <pvince81@owncloud.com> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2014 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ describe('Core base tests', function() { var debounceStub @@ -42,16 +27,16 @@ describe('Core base tests', function() { describe('Base values', function() { it('Sets webroots', function() { expect(OC.getRootPath()).toBeDefined(); - expect(OC.appswebroots).toBeDefined(); + expect(window._oc_appswebroots).toBeDefined(); }); }); describe('filePath', function() { beforeEach(function() { - OC.webroot = 'http://localhost'; - OC.appswebroots.files = OC.getRootPath() + '/apps3/files'; + window._oc_webroot = 'http://localhost'; + window._oc_appswebroots.files = OC.getRootPath() + '/apps3/files'; }); afterEach(function() { - delete OC.appswebroots.files; + delete window._oc_appswebroots.files; }); it('Uses a direct link for css and images,' , function() { @@ -70,11 +55,11 @@ describe('Core base tests', function() { var TESTAPP_ROOT = OC.getRootPath() + '/appsx/testapp'; beforeEach(function() { - OC.appswebroots[TESTAPP] = TESTAPP_ROOT; + window._oc_appswebroots[TESTAPP] = TESTAPP_ROOT; }); afterEach(function() { // restore original array - delete OC.appswebroots[TESTAPP]; + delete window._oc_appswebroots[TESTAPP]; }); it('Generates correct links for core apps', function() { expect(OC.linkTo('core', 'somefile.php')).toEqual(OC.getRootPath() + '/core/somefile.php'); @@ -134,93 +119,6 @@ describe('Core base tests', function() { })).toEqual('number=123'); }); }); - describe('Session heartbeat', function() { - var clock, - oldConfig, - counter; - - beforeEach(function() { - clock = sinon.useFakeTimers(); - oldConfig = OC.config; - counter = 0; - - fakeServer.autoRespond = true; - fakeServer.autoRespondAfter = 0; - fakeServer.respondWith(/\/csrftoken/, function(xhr) { - counter++; - xhr.respond(200, {'Content-Type': 'application/json'}, '{"token": "pgBEsb3MzTb1ZPd2mfDZbQ6/0j3OrXHMEZrghHcOkg8=:3khw5PSa+wKQVo4f26exFD3nplud9ECjJ8/Y5zk5/k4="}'); - }); - $(document).off('ajaxComplete'); // ignore previously registered heartbeats - }); - afterEach(function() { - clock.restore(); - /* jshint camelcase: false */ - OC.config = oldConfig; - $(document).off('ajaxError'); - $(document).off('ajaxComplete'); - }); - it('sends heartbeat half the session lifetime when heartbeat enabled', function() { - /* jshint camelcase: false */ - OC.config = { - session_keepalive: true, - session_lifetime: 300 - }; - window.initCore(); - - expect(counter).toEqual(0); - - // less than half, still nothing - clock.tick(100 * 1000); - expect(counter).toEqual(0); - - // reach past half (160), one call - clock.tick(55 * 1000); - expect(counter).toEqual(1); - - // almost there to the next, still one - clock.tick(140 * 1000); - expect(counter).toEqual(1); - - // past it, second call - clock.tick(20 * 1000); - expect(counter).toEqual(2); - }); - it('does not send heartbeat when heartbeat disabled', function() { - /* jshint camelcase: false */ - OC.config = { - session_keepalive: false, - session_lifetime: 300 - }; - window.initCore(); - - expect(counter).toEqual(0); - - clock.tick(1000000); - - // still nothing - expect(counter).toEqual(0); - }); - it('limits the heartbeat between one minute and one day', function() { - /* jshint camelcase: false */ - var setIntervalStub = sinon.stub(window, 'setInterval'); - OC.config = { - session_keepalive: true, - session_lifetime: 5 - }; - window.initCore(); - expect(setIntervalStub.getCall(0).args[1]).toEqual(60 * 1000); - setIntervalStub.reset(); - - OC.config = { - session_keepalive: true, - session_lifetime: 48 * 3600 - }; - window.initCore(); - expect(setIntervalStub.getCall(0).args[1]).toEqual(24 * 3600 * 1000); - - setIntervalStub.restore(); - }); - }); describe('Parse query string', function() { it('Parses query string from full URL', function() { var query = OC.parseQueryString('http://localhost/stuff.php?q=a&b=x'); @@ -374,7 +272,7 @@ describe('Core base tests', function() { // to make sure they run. var cit = window.isPhantom?xit:it; - // must provide the same results as \OC_Util::naturalSortCompare + // must provide the same results as \OCP\Util::naturalSortCompare it('sorts alphabetically', function() { var a = [ 'def', @@ -780,6 +678,7 @@ describe('Core base tests', function() { OC.currentUser = 'dummy'; clock = sinon.useFakeTimers(); reloadStub = sinon.stub(OC, 'reload'); + document.head.dataset.user = 'dummy' notificationStub = sinon.stub(OC.Notification, 'show'); // unstub the error processing method ajaxErrorStub = OC._processAjaxError; @@ -793,47 +692,6 @@ describe('Core base tests', function() { clock.restore(); }); - it('reloads current page in case of auth error', function() { - var dataProvider = [ - [200, false], - [400, false], - [0, false], - [401, true], - [302, true], - [303, true], - [307, true] - ]; - - for (var i = 0; i < dataProvider.length; i++) { - var xhr = { status: dataProvider[i][0] }; - var expectedCall = dataProvider[i][1]; - - reloadStub.reset(); - OC._reloadCalled = false; - - $(document).trigger(new $.Event('ajaxError'), xhr); - - // trigger timers - clock.tick(waitTimeMs); - - if (expectedCall) { - expect(reloadStub.calledOnce).toEqual(true); - } else { - expect(reloadStub.notCalled).toEqual(true); - } - } - }); - it('reload only called once in case of auth error', function() { - var xhr = { status: 401 }; - - $(document).trigger(new $.Event('ajaxError'), xhr); - $(document).trigger(new $.Event('ajaxError'), xhr); - - // trigger timers - clock.tick(waitTimeMs); - - expect(reloadStub.calledOnce).toEqual(true); - }); it('does not reload the page if the user was navigating away', function() { var xhr = { status: 0 }; OC._userIsNavigatingAway = true; @@ -844,16 +702,7 @@ describe('Core base tests', function() { clock.tick(waitTimeMs); expect(reloadStub.notCalled).toEqual(true); }); - it('displays notification', function() { - var xhr = { status: 401 }; - - notificationUpdateStub = sinon.stub(OC.Notification, 'showUpdate'); - - $(document).trigger(new $.Event('ajaxError'), xhr); - clock.tick(waitTimeMs); - expect(notificationUpdateStub.notCalled).toEqual(false); - }); it('shows a temporary notification if the connection is lost', function() { var xhr = { status: 0 }; spyOn(OC, '_ajaxConnectionLostHandler'); diff --git a/core/js/tests/specs/files/clientSpec.js b/core/js/tests/specs/files/clientSpec.js index 94d52bebacf..105af079ced 100644 --- a/core/js/tests/specs/files/clientSpec.js +++ b/core/js/tests/specs/files/clientSpec.js @@ -1,23 +1,8 @@ /** -* ownCloud -* -* @author Vincent Petry -* @copyright 2015 Vincent Petry <pvince81@owncloud.com> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2015 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ /* global dav */ diff --git a/core/js/tests/specs/jquery.avatarSpec.js b/core/js/tests/specs/jquery.avatarSpec.js index 420c72d2e9b..c01cd9b9603 100644 --- a/core/js/tests/specs/jquery.avatarSpec.js +++ b/core/js/tests/specs/jquery.avatarSpec.js @@ -1,11 +1,7 @@ /** - * Copyright (c) 2015 Roeland Jago Douma <roeland@famdouma.nl> - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2015 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later */ describe('jquery.avatar tests', function() { diff --git a/core/js/tests/specs/jquery.contactsmenuSpec.js b/core/js/tests/specs/jquery.contactsmenuSpec.js index fb2514eb0de..62aaef89edc 100644 --- a/core/js/tests/specs/jquery.contactsmenuSpec.js +++ b/core/js/tests/specs/jquery.contactsmenuSpec.js @@ -1,11 +1,6 @@ /** - * Copyright (c) 2017 Georg Ehrke <oc.list@georgehrke.com> - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * + * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ describe('jquery.contactsMenu tests', function() { diff --git a/core/js/tests/specs/jquery.placeholderSpec.js b/core/js/tests/specs/jquery.placeholderSpec.js index 4937b99625f..436defdd703 100644 --- a/core/js/tests/specs/jquery.placeholderSpec.js +++ b/core/js/tests/specs/jquery.placeholderSpec.js @@ -1,11 +1,6 @@ /** - * Copyright (c) 2019 Serhii Shliakhov <shlyakhov.up@gmail.com> - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * + * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ describe('jquery.placeholder tests', function() { diff --git a/core/js/tests/specs/l10nSpec.js b/core/js/tests/specs/l10nSpec.js index eaa9f5744c2..bd93a13fe74 100644 --- a/core/js/tests/specs/l10nSpec.js +++ b/core/js/tests/specs/l10nSpec.js @@ -1,22 +1,23 @@ /** - * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2014 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later */ describe('OC.L10N tests', function() { var TEST_APP = 'jsunittestapp'; beforeEach(function() { - OC.appswebroots[TEST_APP] = OC.getRootPath() + '/apps3/jsunittestapp'; + window._oc_appswebroots[TEST_APP] = OC.getRootPath() + '/apps3/jsunittestapp'; + + window.OC = window.OC ?? {} + window.OC.appswebroots = window.OC.appswebroots || {} + window.OC.appswebroots[TEST_APP] = OC.getRootPath() + '/apps3/jsunittestapp' }); afterEach(function() { OC.L10N._unregister(TEST_APP); - delete OC.appswebroots[TEST_APP]; + delete window._oc_appswebroots[TEST_APP]; + delete window.OC.appswebroots[TEST_APP]; }); describe('text translation', function() { @@ -109,66 +110,4 @@ describe('OC.L10N tests', function() { checkPlurals(); }); }); - describe('async loading of translations', function() { - afterEach(() => { - document.documentElement.removeAttribute('data-locale') - }) - it('loads bundle for given app and calls callback', function(done) { - document.documentElement.setAttribute('data-locale', 'zh_CN') - var callbackStub = sinon.stub(); - var promiseStub = sinon.stub(); - var loading = OC.L10N.load(TEST_APP, callbackStub); - expect(callbackStub.notCalled).toEqual(true); - var req = fakeServer.requests[0]; - - loading - .then(promiseStub) - .then(function() { - expect(fakeServer.requests.length).toEqual(1); - expect(req.url).toEqual( - OC.getRootPath() + '/apps3/' + TEST_APP + '/l10n/zh_CN.json' - ); - - expect(callbackStub.calledOnce).toEqual(true); - expect(promiseStub.calledOnce).toEqual(true); - expect(t(TEST_APP, 'Hello world!')).toEqual('你好世界!'); - }) - .then(done) - .catch(e => expect(e).toBe('No error expected!')); - - expect(promiseStub.notCalled).toEqual(true); - req.respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ - translations: {'Hello world!': '你好世界!'}, - pluralForm: 'nplurals=2; plural=(n != 1);' - }) - ); - }); - it('calls callback if translation already available', function(done) { - var callbackStub = sinon.stub(); - spyOn(console, 'warn'); - OC.L10N.register(TEST_APP, { - 'Hello world!': 'Hallo Welt!' - }); - OC.L10N.load(TEST_APP, callbackStub) - .then(function() { - expect(callbackStub.calledOnce).toEqual(true); - expect(fakeServer.requests.length).toEqual(0); - }) - .then(done); - - }); - it('calls callback if locale is en', function(done) { - var callbackStub = sinon.stub(); - OC.L10N.load(TEST_APP, callbackStub) - .then(function() { - expect(callbackStub.calledOnce).toEqual(true); - expect(fakeServer.requests.length).toEqual(0); - }) - .then(done) - .catch(done); - }); - }); }); diff --git a/core/js/tests/specs/mimeTypeSpec.js b/core/js/tests/specs/mimeTypeSpec.js index c9497a7c574..4fe5481541d 100644 --- a/core/js/tests/specs/mimeTypeSpec.js +++ b/core/js/tests/specs/mimeTypeSpec.js @@ -1,21 +1,7 @@ /** - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2015 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ describe('MimeType tests', function() { diff --git a/core/js/tests/specs/oc-backbone-webdavSpec.js b/core/js/tests/specs/oc-backbone-webdavSpec.js index 6f48d0c92d2..bf4d6eef6ca 100644 --- a/core/js/tests/specs/oc-backbone-webdavSpec.js +++ b/core/js/tests/specs/oc-backbone-webdavSpec.js @@ -1,23 +1,8 @@ /** -* ownCloud -* -* @author Vincent Petry -* @copyright 2014 Vincent Petry <pvince81@owncloud.com> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2014 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ /* global dav */ diff --git a/core/js/tests/specs/public/commentsSpec.js b/core/js/tests/specs/public/commentsSpec.js index e77947bea9d..6e15ddca6a7 100644 --- a/core/js/tests/specs/public/commentsSpec.js +++ b/core/js/tests/specs/public/commentsSpec.js @@ -1,20 +1,7 @@ /** -* @copyright 2018 Joas Schilling <nickvergessen@owncloud.com> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ describe('OCP.Comments tests', function() { function dataProvider() { diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js index 857156f1437..9f75ad501d1 100644 --- a/core/js/tests/specs/setupchecksSpec.js +++ b/core/js/tests/specs/setupchecksSpec.js @@ -1,11 +1,7 @@ /** - * Copyright (c) 2015 Lukas Reschke <lukas@owncloud.com> - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2015 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later */ describe('OC.SetupChecks tests', function() { @@ -22,197 +18,6 @@ describe('OC.SetupChecks tests', function() { protocolStub.restore(); }); - describe('checkWebDAV', function() { - it('should fail with another response status code than 201 or 207', function(done) { - var async = OC.SetupChecks.checkWebDAV(); - - suite.server.requests[0].respond(200); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'Your web server is not yet properly set up to allow file synchronization, because the WebDAV interface seems to be broken.', - type: OC.SetupChecks.MESSAGE_TYPE_ERROR - }]); - done(); - }); - }); - - it('should return no error with a response status code of 207', function(done) { - var async = OC.SetupChecks.checkWebDAV(); - - suite.server.requests[0].respond(207); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no error with a response status code of 401', function(done) { - var async = OC.SetupChecks.checkWebDAV(); - - suite.server.requests[0].respond(401); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - }); - - describe('checkWellKnownUrl', function() { - it('should fail with another response status code than the expected one', function(done) { - var async = OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207); - - suite.server.requests[0].respond(200); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'Your web server is not properly set up to resolve "/.well-known/caldav". Further information can be found in the <a target="_blank" rel="noreferrer noopener" class="external" href="http://example.org/admin-setup-well-known-URL">documentation ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_INFO - }]); - done(); - }); - }); - - it('should return no error with the expected response status code', function(done) { - var async = OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207); - - suite.server.requests[0].respond(207); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no error with the default expected response status code', function(done) { - var async = OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/caldav', 'http://example.org/PLACEHOLDER', true); - - suite.server.requests[0].respond(207); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no error when no check should be run', function(done) { - var async = OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/caldav', 'http://example.org/PLACEHOLDER', false); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - }); - - describe('checkProviderUrl', function() { - it('should fail with another response status code than the expected one', function(done) { - var async = OC.SetupChecks.checkProviderUrl('/ocm-provider/', 'http://example.org/PLACEHOLDER', true); - - suite.server.requests[0].respond(302); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'Your web server is not properly set up to resolve "/ocm-provider/". This is most likely related to a web server configuration that was not updated to deliver this folder directly. Please compare your configuration against the shipped rewrite rules in ".htaccess" for Apache or the provided one in the documentation for Nginx at it\'s <a target="_blank" rel="noreferrer noopener" class="external" href="http://example.org/admin-nginx">documentation page ↗</a>. On Nginx those are typically the lines starting with "location ~" that need an update.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }]); - done(); - }); - }); - - it('should return no error with the expected response status code', function(done) { - var async = OC.SetupChecks.checkProviderUrl('/ocm-provider/', 'http://example.org/PLACEHOLDER', true); - - suite.server.requests[0].respond(200); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no error when no check should be run', function(done) { - var async = OC.SetupChecks.checkProviderUrl('/ocm-provider/', 'http://example.org/PLACEHOLDER', false); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - }); - - describe('checkWOFF2Loading', function() { - it('should fail with another response status code than the expected one', function(done) { - var async = OC.SetupChecks.checkWOFF2Loading(OC.filePath('core', '', 'fonts/NotoSans-Regular-latin.woff2'), 'http://example.org/PLACEHOLDER'); - - suite.server.requests[0].respond(302); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'Your web server is not properly set up to deliver .woff2 files. This is typically an issue with the Nginx configuration. For Nextcloud 15 it needs an adjustement to also deliver .woff2 files. Compare your Nginx configuration to the recommended configuration in our <a target="_blank" rel="noreferrer noopener" class="external" href="http://example.org/admin-nginx">documentation ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }]); - done(); - }); - }); - - it('should return no error with the expected response status code', function(done) { - var async = OC.SetupChecks.checkWOFF2Loading(OC.filePath('core', '', 'fonts/NotoSans-Regular-latin.woff2'), 'http://example.org/PLACEHOLDER'); - - suite.server.requests[0].respond(200); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - }); - - describe('checkDataProtected', function() { - - oc_dataURL = "data"; - - it('should return an error if data directory is not protected', function(done) { - var async = OC.SetupChecks.checkDataProtected(); - - suite.server.requests[0].respond(200, {'Content-Type': 'text/plain'}, ''); - - async.done(function( data, s, x ){ - expect(data).toEqual([ - { - msg: 'Your data directory and files are probably accessible from the internet. The .htaccess file is not working. It is strongly recommended that you configure your web server so that the data directory is no longer accessible, or move the data directory outside the web server document root.', - type: OC.SetupChecks.MESSAGE_TYPE_ERROR - }]); - done(); - }); - }); - - it('should not return an error if data directory is protected', function(done) { - var async = OC.SetupChecks.checkDataProtected(); - - suite.server.requests[0].respond(403); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return an error if data directory is a boolean', function(done) { - - oc_dataURL = false; - - var async = OC.SetupChecks.checkDataProtected(); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - }); - describe('checkSetup', function() { it('should return an error if server has no internet connection', function(done) { var async = OC.SetupChecks.checkSetup(); @@ -223,12 +28,6 @@ describe('OC.SetupChecks tests', function() { 'Content-Type': 'application/json' }, JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyGeneratedURL: 'https://server', - temporaryDirectoryWritable: true, generic: { network: { "Internet connectivity": { @@ -261,12 +60,6 @@ describe('OC.SetupChecks tests', function() { 'Content-Type': 'application/json' }, JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyGeneratedURL: 'https://server', - temporaryDirectoryWritable: true, generic: { network: { "Internet connectivity": { @@ -299,12 +92,6 @@ describe('OC.SetupChecks tests', function() { 'Content-Type': 'application/json', }, JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyGeneratedURL: 'https://server', - temporaryDirectoryWritable: true, generic: { network: { "Internet connectivity": { @@ -337,13 +124,6 @@ describe('OC.SetupChecks tests', function() { 'Content-Type': 'application/json', }, JSON.stringify({ - isFairUseOfFreePushService: true, - reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html', - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyGeneratedURL: 'https://server', - temporaryDirectoryWritable: true, generic: { network: { "Internet connectivity": { @@ -406,12 +186,6 @@ describe('OC.SetupChecks tests', function() { 'Content-Type': 'application/json', }, JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyGeneratedURL: 'https://server', - temporaryDirectoryWritable: true, generic: { network: { "Internet connectivity": { @@ -440,83 +214,6 @@ describe('OC.SetupChecks tests', function() { }); }); - it('should return an error if the php version is no longer supported', function(done) { - var async = OC.SetupChecks.checkSetup(); - - suite.server.requests[0].respond( - 200, - { - 'Content-Type': 'application/json', - }, - JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: true, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyGeneratedURL: 'https://server', - temporaryDirectoryWritable: true, - generic: { - network: { - "Internet connectivity": { - severity: "success", - description: null, - linkToDoc: null - } - }, - }, - }) - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'MySQL is used as database but does not support 4-byte characters. To be able to handle 4-byte characters (like emojis) without issues in filenames or comments for example it is recommended to enable the 4-byte support in MySQL. For further details read <a target="_blank" rel="noreferrer noopener" class="external" href="https://docs.example.org/admin-mysql-utf8mb4">the documentation page about this ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }]); - done(); - }); - }); - - // THe following test is invalid as the code in core/js/setupchecks.js is calling - // window.location.protocol which always return http during tests - // if there is a way to trick window.location.protocol during test, then we could re-activate it - /* - it('should return an error if the protocol is https but the server generates http links', function(done) { - var async = OC.SetupChecks.checkSetup(); - - suite.server.requests[0].respond( - 200, - { - 'Content-Type': 'application/json', - }, - JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html', - reverseProxyGeneratedURL: 'http://server', - temporaryDirectoryWritable: true, - generic: { - network: { - "Internet connectivity": { - severity: "success", - description: null, - linkToDoc: null - } - }, - }, - }) - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'You are accessing your instance over a secure connection, however your instance is generating insecure URLs. This most likely means that you are behind a reverse proxy and the overwrite config variables are not set correctly. Please read <a target="_blank" rel="noreferrer noopener" class="external" href="https://docs.nextcloud.com/foo/bar.html">the documentation page about this ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }]); - done(); - }); - }); - */ it('should not return an error if the protocol is http and the server generates http links', function(done) { var async = OC.SetupChecks.checkSetup(); @@ -526,13 +223,6 @@ describe('OC.SetupChecks tests', function() { 'Content-Type': 'application/json', }, JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html', - reverseProxyGeneratedURL: 'http://server', - temporaryDirectoryWritable: true, generic: { network: { "Internet connectivity": { @@ -551,78 +241,6 @@ describe('OC.SetupChecks tests', function() { }); }); - it('should return an error if there is not enough free space in the temp directory', function(done) { - var async = OC.SetupChecks.checkSetup(); - - suite.server.requests[0].respond( - 200, - { - 'Content-Type': 'application/json', - }, - JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: false, - reverseProxyGeneratedURL: 'https://server', - temporaryDirectoryWritable: true, - generic: { - network: { - "Internet connectivity": { - severity: "success", - description: null, - linkToDoc: null - } - }, - }, - }) - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'This instance uses an S3 based object store as primary storage. The uploaded files are stored temporarily on the server and thus it is recommended to have 50 GB of free space available in the temp directory of PHP. Check the logs for full details about the path and the available space. To improve this please change the temporary directory in the php.ini or make more space available in that path.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }]); - done(); - }); - }); - - it('should return an error if gmp or bcmath are not enabled', function(done) { - var async = OC.SetupChecks.checkSetup(); - - suite.server.requests[0].respond( - 200, - { - 'Content-Type': 'application/json', - }, - JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: false, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyGeneratedURL: 'https://server', - temporaryDirectoryWritable: true, - generic: { - network: { - "Internet connectivity": { - severity: "success", - description: null, - linkToDoc: null - } - }, - }, - }) - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'The PHP modules "gmp" and/or "bcmath" are not enabled. If you use WebAuthn passwordless authentication, these modules are required.', - type: OC.SetupChecks.MESSAGE_TYPE_INFO - }]); - done(); - }); - }); - it('should return an info if there is no default phone region', function(done) { var async = OC.SetupChecks.checkSetup(); @@ -632,12 +250,6 @@ describe('OC.SetupChecks tests', function() { 'Content-Type': 'application/json', }, JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyGeneratedURL: 'https://server', - temporaryDirectoryWritable: true, generic: { network: { "Internet connectivity": { @@ -665,644 +277,5 @@ describe('OC.SetupChecks tests', function() { done(); }); }); - - it('should return an info if the temporary directory is either non-existent or non-writable', function(done) { - var async = OC.SetupChecks.checkSetup(); - - suite.server.requests[0].respond( - 200, - { - 'Content-Type': 'application/json', - }, - JSON.stringify({ - isFairUseOfFreePushService: true, - areWebauthnExtensionsEnabled: true, - isMysqlUsedWithoutUTF8MB4: false, - isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true, - reverseProxyGeneratedURL: 'https://server', - temporaryDirectoryWritable: false, - generic: { - network: { - "Internet connectivity": { - severity: "success", - description: null, - linkToDoc: null - } - }, - }, - }) - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'The temporary directory of this instance points to an either non-existing or non-writable directory.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }]); - done(); - }); - }); - }); - - describe('checkGeneric', function() { - it('should return an error if the response has no statuscode 200', function(done) { - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond( - 500, - { - 'Content-Type': 'application/json' - } - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'Error occurred while checking server setup', - type: OC.SetupChecks.MESSAGE_TYPE_ERROR - },{ - msg: 'Error occurred while checking server setup', - type: OC.SetupChecks.MESSAGE_TYPE_ERROR - }]); - done(); - }); - }); - - it('should return all errors if all headers are missing', function(done) { - protocolStub.returns('https'); - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond( - 200, - { - 'Content-Type': 'application/json', - 'Strict-Transport-Security': 'max-age=15768000' - }, - '{}' - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([ - { - msg: 'The "X-Content-Type-Options" HTTP header is not set to "nosniff". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }, { - msg: 'The "X-Robots-Tag" HTTP header is not set to "noindex, nofollow". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }, { - msg: 'The "X-Frame-Options" HTTP header is not set to "SAMEORIGIN". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }, { - msg: 'The "X-Permitted-Cross-Domain-Policies" HTTP header is not set to "none". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }, { - msg: 'The "X-XSS-Protection" HTTP header does not contain "1; mode=block". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }, { - msg: 'The "Referrer-Policy" HTTP header is not set to "no-referrer", "no-referrer-when-downgrade", "strict-origin", "strict-origin-when-cross-origin" or "same-origin". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">W3C Recommendation ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_INFO - } - ]); - done(); - }); - }); - - it('should return only some errors if just some headers are missing', function(done) { - protocolStub.returns('https'); - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond( - 200, - { - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'Strict-Transport-Security': 'max-age=15768000;preload', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - } - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([ - { - msg: 'The "X-Content-Type-Options" HTTP header is not set to "nosniff". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }, { - msg: 'The "X-XSS-Protection" HTTP header does not contain "1; mode=block". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING, - } - ]); - done(); - }); - }); - - it('should return none errors if all headers are there', function(done) { - protocolStub.returns('https'); - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond( - 200, - { - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'Strict-Transport-Security': 'max-age=15768000', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer' - } - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - describe('check X-Robots-Tag header', function() { - it('should return no message if X-Robots-Tag is set to noindex,nofollow without space', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex,nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - result.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return a message if X-Robots-Tag is set to none', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'none', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - result.done(function( data, s, x ){ - expect(data).toEqual([ - { - msg: 'The "X-Robots-Tag" HTTP header is not set to "noindex, nofollow". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - } - ]); - done(); - }); - }); - }); - - describe('check X-XSS-Protection header', function() { - it('should return no message if X-XSS-Protection is set to 1; mode=block; report=https://example.com', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block; report=https://example.com', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no message if X-XSS-Protection is set to 1; mode=block', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return a message if X-XSS-Protection is set to 1', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([ - { - msg: 'The "X-XSS-Protection" HTTP header does not contain "1; mode=block". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - } - ]); - done(); - }); - }); - - it('should return a message if X-XSS-Protection is set to 0', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '0', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([ - { - msg: 'The "X-XSS-Protection" HTTP header does not contain "1; mode=block". This is a potential security or privacy risk, as it is recommended to adjust this setting accordingly.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - } - ]); - done(); - }); - }); - }); - - describe('check Referrer-Policy header', function() { - it('should return no message if Referrer-Policy is set to no-referrer', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no message if Referrer-Policy is set to no-referrer-when-downgrade', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer-when-downgrade', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no message if Referrer-Policy is set to strict-origin', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'strict-origin', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no message if Referrer-Policy is set to strict-origin-when-cross-origin', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'strict-origin-when-cross-origin', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no message if Referrer-Policy is set to same-origin', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'same-origin', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return a message if Referrer-Policy is set to origin', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'origin', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([ - { - msg: 'The "Referrer-Policy" HTTP header is not set to "no-referrer", "no-referrer-when-downgrade", "strict-origin", "strict-origin-when-cross-origin" or "same-origin". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">W3C Recommendation ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_INFO - } - ]); - done(); - }); - }); - - it('should return a message if Referrer-Policy is set to origin-when-cross-origin', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'origin-when-cross-origin', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([ - { - msg: 'The "Referrer-Policy" HTTP header is not set to "no-referrer", "no-referrer-when-downgrade", "strict-origin", "strict-origin-when-cross-origin" or "same-origin". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">W3C Recommendation ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_INFO - } - ]); - done(); - }); - }); - - it('should return a message if Referrer-Policy is set to unsafe-url', function(done) { - protocolStub.returns('https'); - var result = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'unsafe-url', - }); - - result.done(function( data, s, x ){ - expect(data).toEqual([ - { - msg: 'The "Referrer-Policy" HTTP header is not set to "no-referrer", "no-referrer-when-downgrade", "strict-origin", "strict-origin-when-cross-origin" or "same-origin". This can leak referer information. See the <a target="_blank" rel="noreferrer noopener" class="external" href="https://www.w3.org/TR/referrer-policy/">W3C Recommendation ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_INFO - } - ]); - done(); - }); - }); - }); - }); - - it('should return an error if the response has no statuscode 200', function(done) { - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond( - 500, - { - 'Content-Type': 'application/json' - }, - JSON.stringify({data: {serverHasInternetConnectionProblems: true}}) - ); - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'Error occurred while checking server setup', - type: OC.SetupChecks.MESSAGE_TYPE_ERROR - }, { - msg: 'Error occurred while checking server setup', - type: OC.SetupChecks.MESSAGE_TYPE_ERROR - }]); - done(); - }); - }); - - it('should return a SSL warning if SSL used without Strict-Transport-Security-Header', function(done) { - protocolStub.returns('https'); - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, - { - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - } - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'The "Strict-Transport-Security" HTTP header is not set to at least "15552000" seconds. For enhanced security, it is recommended to enable HSTS as described in the <a target="_blank" rel="noreferrer noopener" class="external" href="https://docs.example.org/admin-security">security tips ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }]); - done(); - }); - }); - - it('should return a SSL warning if SSL used with to small Strict-Transport-Security-Header', function(done) { - protocolStub.returns('https'); - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, - { - 'Strict-Transport-Security': 'max-age=15551999', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - } - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'The "Strict-Transport-Security" HTTP header is not set to at least "15552000" seconds. For enhanced security, it is recommended to enable HSTS as described in the <a target="_blank" rel="noreferrer noopener" class="external" href="https://docs.example.org/admin-security">security tips ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }]); - done(); - }); - }); - - it('should return a SSL warning if SSL used with to a bogus Strict-Transport-Security-Header', function(done) { - protocolStub.returns('https'); - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, - { - 'Strict-Transport-Security': 'iAmABogusHeader342', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - } - ); - - async.done(function( data, s, x ){ - expect(data).toEqual([{ - msg: 'The "Strict-Transport-Security" HTTP header is not set to at least "15552000" seconds. For enhanced security, it is recommended to enable HSTS as described in the <a target="_blank" rel="noreferrer noopener" class="external" href="https://docs.example.org/admin-security">security tips ↗</a>.', - type: OC.SetupChecks.MESSAGE_TYPE_WARNING - }]); - done(); - }); - }); - - it('should return no SSL warning if SSL used with to exact the minimum Strict-Transport-Security-Header', function(done) { - protocolStub.returns('https'); - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=15768000', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header', function(done) { - protocolStub.returns('https'); - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=99999999', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header and includeSubDomains parameter', function(done) { - protocolStub.returns('https'); - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=99999999; includeSubDomains', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); - }); - - it('should return no SSL warning if SSL used with to more than the minimum Strict-Transport-Security-Header and includeSubDomains and preload parameter', function(done) { - protocolStub.returns('https'); - var async = OC.SetupChecks.checkGeneric(); - - suite.server.requests[0].respond(200, { - 'Strict-Transport-Security': 'max-age=99999999; preload; includeSubDomains', - 'X-XSS-Protection': '1; mode=block', - 'X-Content-Type-Options': 'nosniff', - 'X-Robots-Tag': 'noindex, nofollow', - 'X-Frame-Options': 'SAMEORIGIN', - 'X-Permitted-Cross-Domain-Policies': 'none', - 'Referrer-Policy': 'no-referrer', - }); - - async.done(function( data, s, x ){ - expect(data).toEqual([]); - done(); - }); }); }); diff --git a/core/js/tests/specs/systemtags/systemtagsSpec.js b/core/js/tests/specs/systemtags/systemtagsSpec.js index 376a25c7d83..52fe954f454 100644 --- a/core/js/tests/specs/systemtags/systemtagsSpec.js +++ b/core/js/tests/specs/systemtags/systemtagsSpec.js @@ -1,23 +1,8 @@ /** -* ownCloud -* -* @author Joas Schilling -* @copyright 2016 Joas Schilling <nickvergessen@owncloud.com> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ describe('OC.SystemTags tests', function() { it('describes non existing tag', function() { diff --git a/core/js/tests/specs/systemtags/systemtagscollectionSpec.js b/core/js/tests/specs/systemtags/systemtagscollectionSpec.js index 6f2d8361754..f2a3bd067a5 100644 --- a/core/js/tests/specs/systemtags/systemtagscollectionSpec.js +++ b/core/js/tests/specs/systemtags/systemtagscollectionSpec.js @@ -1,23 +1,7 @@ /** -* ownCloud -* -* @author Vincent Petry -* @copyright 2016 Vincent Petry <pvince81@owncloud.com> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * SPDX-FileCopyrightText: 2016 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ describe('OC.SystemTags.SystemTagsCollection tests', function() { var collection; diff --git a/core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js b/core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js index b69054e647e..988bcfc8c24 100644 --- a/core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js +++ b/core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js @@ -1,23 +1,8 @@ /** -* ownCloud -* -* @author Vincent Petry -* @copyright 2016 Vincent Petry <pvince81@owncloud.com> -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud Inc. + * SPDX-License-Identifier: AGPL-3.0-or-later + */ describe('OC.SystemTags.SystemTagsInputField tests', function() { var view, select2Stub, clock; |