Skip to content

Commit

Permalink
fix(settings): Remove migrated SetupCheck from legacy JS code
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Mar 1, 2024
1 parent f6a1bae commit f5c3416
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 140 deletions.
8 changes: 2 additions & 6 deletions apps/settings/src/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,10 @@ window.addEventListener('DOMContentLoaded', () => {
// run setup checks then gather error messages
$.when(
OC.SetupChecks.checkWebDAV(),
OC.SetupChecks.checkWellKnownUrl('GET', '/.well-known/webfinger', OC.theme.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true, [200, 404], true),
OC.SetupChecks.checkWellKnownUrl('GET', '/.well-known/nodeinfo', OC.theme.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true, [200, 404], true),
OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/caldav', OC.theme.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
OC.SetupChecks.checkWellKnownUrl('PROPFIND', '/.well-known/carddav', OC.theme.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
OC.SetupChecks.checkSetup(),
OC.SetupChecks.checkGeneric(),
).then((check1, check2, check3, check4, check5, check6, check7) => {
const messages = [].concat(check1, check2, check3, check4, check5, check6, check7)
).then((check1, check2, check3) => {
const messages = [].concat(check1, check2, check3)
const $el = $('#postsetupchecks')
$('#security-warning-state-loading').addClass('hidden')

Expand Down
48 changes: 0 additions & 48 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,54 +47,6 @@
return deferred.promise();
},

/**
* Check whether the .well-known URLs works.
*
* @param url the URL to test
* @param placeholderUrl the placeholder URL - can be found at OC.theme.docPlaceholderUrl
* @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
* @param {int|int[]} expectedStatus the expected HTTP status to be returned by the URL, 207 by default
* @return $.Deferred object resolved with an array of error messages
*/
checkWellKnownUrl: function(verb, url, placeholderUrl, runCheck, expectedStatus, checkCustomHeader) {
if (expectedStatus === undefined) {
expectedStatus = [207];
}

if (!Array.isArray(expectedStatus)) {
expectedStatus = [expectedStatus];
}

var deferred = $.Deferred();

if(runCheck === false) {
deferred.resolve([]);
return deferred.promise();
}
var afterCall = function(xhr) {
var messages = [];
var customWellKnown = xhr.getResponseHeader('X-NEXTCLOUD-WELL-KNOWN')
if (expectedStatus.indexOf(xhr.status) === -1 || (checkCustomHeader && !customWellKnown)) {
var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL');
messages.push({
msg: t('core', 'Your web server is not properly set up to resolve "{url}". Further information can be found in the {linkstart}documentation ↗{linkend}.', { url: url })
.replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + docUrl + '">')
.replace('{linkend}', '</a>'),
type: OC.SetupChecks.MESSAGE_TYPE_INFO
});
}
deferred.resolve(messages);
};

$.ajax({
type: verb,
url: url,
complete: afterCall,
allowAuthErrors: true
});
return deferred.promise();
},

/**
* Runs setup checks on the server side
*
Expand Down
83 changes: 0 additions & 83 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,53 +60,6 @@ describe('OC.SetupChecks tests', function() {
});
});

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('checkSetup', function() {
it('should return an error if server has no internet connection', function(done) {
var async = OC.SetupChecks.checkSetup();
Expand Down Expand Up @@ -309,42 +262,6 @@ describe('OC.SetupChecks tests', function() {
});
});

// 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({
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
reverseProxyGeneratedURL: 'http://server',
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();

Expand Down
4 changes: 2 additions & 2 deletions dist/settings-legacy-admin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f5c3416

Please sign in to comment.