Skip to content

Commit df6e910

Browse files
authoredOct 24, 2018
Merge pull request nextcloud#11396 from nextcloud/wellknown-webfinger
adding .well-known/webfinger
2 parents 37718dd + 20a5ce2 commit df6e910

File tree

7 files changed

+43
-8
lines changed

7 files changed

+43
-8
lines changed
 

‎.htaccess

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
6161
RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
6262
RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
63+
RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
6364
RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
6465
RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
6566
RewriteRule ^remote/(.*) remote.php [QSA,L]

‎core/js/setupchecks.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,14 @@
5252
* @param url the URL to test
5353
* @param placeholderUrl the placeholder URL - can be found at oc_defaults.docPlaceholderUrl
5454
* @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
55+
* @param {int} expectedStatus the expected HTTP status to be returned by the URL, 207 by default
5556
* @return $.Deferred object resolved with an array of error messages
5657
*/
57-
checkWellKnownUrl: function(url, placeholderUrl, runCheck) {
58+
checkWellKnownUrl: function(url, placeholderUrl, runCheck, expectedStatus) {
59+
if (expectedStatus === undefined) {
60+
expectedStatus = 207;
61+
}
62+
5863
var deferred = $.Deferred();
5964

6065
if(runCheck === false) {
@@ -63,7 +68,7 @@
6368
}
6469
var afterCall = function(xhr) {
6570
var messages = [];
66-
if (xhr.status !== 207) {
71+
if (xhr.status !== expectedStatus) {
6772
var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL');
6873
messages.push({
6974
msg: t('core', 'Your web server is not properly set up to resolve "{url}". Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', { docLink: docUrl, url: url }),

‎core/js/tests/specs/setupchecksSpec.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ describe('OC.SetupChecks tests', function() {
6161
});
6262

6363
describe('checkWellKnownUrl', function() {
64-
it('should fail with another response status code than 207', function(done) {
65-
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true);
64+
it('should fail with another response status code than the expected one', function(done) {
65+
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207);
6666

6767
suite.server.requests[0].respond(200);
6868

@@ -75,7 +75,18 @@ describe('OC.SetupChecks tests', function() {
7575
});
7676
});
7777

78-
it('should return no error with a response status code of 207', function(done) {
78+
it('should return no error with the expected response status code', function(done) {
79+
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207);
80+
81+
suite.server.requests[0].respond(207);
82+
83+
async.done(function( data, s, x ){
84+
expect(data).toEqual([]);
85+
done();
86+
});
87+
});
88+
89+
it('should return no error with the default expected response status code', function(done) {
7990
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true);
8091

8192
suite.server.requests[0].respond(207);

‎public.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
list($service) = explode('/', $pathInfo);
5555
}
5656
$file = \OC::$server->getConfig()->getAppValue('core', 'public_' . strip_tags($service));
57-
if ($file === null) {
57+
if ($file === '') {
5858
http_response_code(404);
5959
exit;
6060
}

‎settings/Application.php

+16
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ public function register() {
121121

122122
Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
123123
Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');
124+
125+
Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig');
124126
}
125127

126128
/**
@@ -152,4 +154,18 @@ public function onChangeInfo(array $parameters) {
152154
$hooks = $this->getContainer()->query(Hooks::class);
153155
$hooks->onChangeEmail($parameters['user'], $parameters['old_value']);
154156
}
157+
158+
/**
159+
* @param array $settings
160+
*/
161+
public function extendJsConfig(array $settings) {
162+
$appConfig = json_decode($settings['array']['oc_appconfig'], true);
163+
164+
$publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', '');
165+
if (!empty($publicWebFinger)) {
166+
$appConfig['core']['public_webfinger'] = $publicWebFinger;
167+
}
168+
169+
$settings['array']['oc_appconfig'] = json_encode($appConfig);
170+
}
155171
}

‎settings/js/admin.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,14 @@ $(document).ready(function(){
248248
// run setup checks then gather error messages
249249
$.when(
250250
OC.SetupChecks.checkWebDAV(),
251+
OC.SetupChecks.checkWellKnownUrl('/.well-known/webfinger', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true && !!oc_appconfig.core.public_webfinger, 200),
251252
OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
252253
OC.SetupChecks.checkWellKnownUrl('/.well-known/carddav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
253254
OC.SetupChecks.checkSetup(),
254255
OC.SetupChecks.checkGeneric(),
255256
OC.SetupChecks.checkDataProtected()
256-
).then(function(check1, check2, check3, check4, check5, check6) {
257-
var messages = [].concat(check1, check2, check3, check4, check5, check6);
257+
).then(function(check1, check2, check3, check4, check5, check6, check7) {
258+
var messages = [].concat(check1, check2, check3, check4, check5, check6, check7);
258259
var $el = $('#postsetupchecks');
259260
$('#security-warning-state-loading').addClass('hidden');
260261

‎tests/data/setUploadLimit/htaccess

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ RewriteEngine on
3838
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
3939
RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
4040
RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
41+
RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
4142
RewriteRule ^\.well-known/carddav /remote.php/carddav/ [R=301,L]
4243
RewriteRule ^\.well-known/caldav /remote.php/caldav/ [R=301,L]
4344
RewriteRule ^apps/calendar/caldav\.php remote.php/caldav/ [QSA,L]

0 commit comments

Comments
 (0)
Please sign in to comment.