Skip to content

Commit

Permalink
Merge pull request #14312 from nextcloud/backport/14255/stable15
Browse files Browse the repository at this point in the history
[stable15] Fix ocm end-point discovery discovery
  • Loading branch information
MorrisJobke authored Feb 20, 2019
2 parents 52662fb + 2e76bc3 commit 37cb480
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 3 deletions.
3 changes: 2 additions & 1 deletion apps/cloud_federation_api/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public function getCapabilities() {
'enabled' => true,
'apiVersion' => '1.0-proposal1',
'endPoint' => substr($url, 0, strrpos($url, '/')),
'shareTypes' => [
'resourceTypes' => [
[
'name' => 'file',
'shareTypes' => ['user', 'group'],
'protocols' => [
'webdav' => '/public.php/webdav/',
]
Expand Down
40 changes: 40 additions & 0 deletions core/js/setupchecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,46 @@
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_defaults.docPlaceholderUrl
* @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
*
* @return $.Deferred object resolved with an array of error messages
*/
checkProviderUrl: function(url, placeholderUrl, runCheck) {
var expectedStatus = [200];
var deferred = $.Deferred();

if(runCheck === false) {
deferred.resolve([]);
return deferred.promise();
}
var afterCall = function(xhr) {
var messages = [];
if (expectedStatus.indexOf(xhr.status) === -1) {
var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-nginx');
messages.push({
msg: t('core', 'Your web server is not properly set up to resolve "{url}". 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" href="{docLink}">documentation page</a>. On Nginx those are typically the lines starting with "location ~" that need an update.', { docLink: docUrl, url: url }),
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
});
}
deferred.resolve(messages);
};

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


/**
* Check whether the WOFF2 URLs works.
*
Expand Down
36 changes: 36 additions & 0 deletions core/js/tests/specs/setupchecksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,42 @@ describe('OC.SetupChecks tests', function() {
});
});

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 href="http://example.org/admin-nginx" rel="noreferrer noopener">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/Nunito-Regular.woff2'), 'http://example.org/PLACEHOLDER');
Expand Down
1 change: 1 addition & 0 deletions lib/private/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ public static function updateHtaccess() {
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/robots.txt";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/updater/";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs-provider/";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocm-provider/";
$content .= "\n RewriteCond %{REQUEST_URI} !^/\\.well-known/(acme-challenge|pki-validation)/.*";
$content .= "\n RewriteRule . index.php [PT,E=PATH_INFO:$1]";
$content .= "\n RewriteBase " . $rewriteBase;
Expand Down
6 changes: 4 additions & 2 deletions settings/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,14 @@ $(document).ready(function(){
OC.SetupChecks.checkWellKnownUrl('/.well-known/webfinger', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true && !!oc_appconfig.core.public_webfinger, [200, 501]),
OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
OC.SetupChecks.checkWellKnownUrl('/.well-known/carddav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
OC.SetupChecks.checkProviderUrl('/ocm-provider/', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
OC.SetupChecks.checkProviderUrl('/ocs-provider/', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
OC.SetupChecks.checkSetup(),
OC.SetupChecks.checkGeneric(),
OC.SetupChecks.checkWOFF2Loading(OC.filePath('core', '', 'fonts/Nunito-Regular.woff2'), oc_defaults.docPlaceholderUrl),
OC.SetupChecks.checkDataProtected()
).then(function(check1, check2, check3, check4, check5, check6, check7, check8) {
var messages = [].concat(check1, check2, check3, check4, check5, check6, check7, check8);
).then(function(check1, check2, check3, check4, check5, check6, check7, check8, check9, check10) {
var messages = [].concat(check1, check2, check3, check4, check5, check6, check7, check8, check9, check10);
var $el = $('#postsetupchecks');
$('#security-warning-state-loading').addClass('hidden');

Expand Down

0 comments on commit 37cb480

Please sign in to comment.