From d143b43a0454528905c751579b4ab482abe39f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 10 Oct 2018 13:33:57 +0200 Subject: [PATCH] Make possible to set the expected status of the well known URL check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The check is based on the HTTP status returned by the URL, and different URLs may return different status (for example, DAV returns 207, while a service like WebFinger would return 200), so the expected status needs to be set depending on the URL. Signed-off-by: Daniel Calviño Sánchez --- core/js/setupchecks.js | 9 +++++++-- core/js/tests/specs/setupchecksSpec.js | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/core/js/setupchecks.js b/core/js/setupchecks.js index 62f0fb10c1..1fe9e77077 100644 --- a/core/js/setupchecks.js +++ b/core/js/setupchecks.js @@ -52,9 +52,14 @@ * @param url the URL to test * @param placeholderUrl the placeholder URL - can be found at oc_defaults.docPlaceholderUrl * @param {boolean} runCheck if this is set to false the check is skipped and no error is returned + * @param {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(url, placeholderUrl, runCheck) { + checkWellKnownUrl: function(url, placeholderUrl, runCheck, expectedStatus) { + if (expectedStatus === undefined) { + expectedStatus = 207; + } + var deferred = $.Deferred(); if(runCheck === false) { @@ -63,7 +68,7 @@ } var afterCall = function(xhr) { var messages = []; - if (xhr.status !== 207) { + if (xhr.status !== expectedStatus) { 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 documentation.', { docLink: docUrl, url: url }), diff --git a/core/js/tests/specs/setupchecksSpec.js b/core/js/tests/specs/setupchecksSpec.js index 38a39cdd74..a058a689ed 100644 --- a/core/js/tests/specs/setupchecksSpec.js +++ b/core/js/tests/specs/setupchecksSpec.js @@ -61,8 +61,8 @@ describe('OC.SetupChecks tests', function() { }); describe('checkWellKnownUrl', function() { - it('should fail with another response status code than 207', function(done) { - var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true); + it('should fail with another response status code than the expected one', function(done) { + var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207); suite.server.requests[0].respond(200); @@ -75,7 +75,18 @@ describe('OC.SetupChecks tests', function() { }); }); - it('should return no error with a response status code of 207', function(done) { + it('should return no error with the expected response status code', function(done) { + var async = OC.SetupChecks.checkWellKnownUrl('/.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('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true); suite.server.requests[0].respond(207);