mirror of https://github.com/nextcloud/server.git
Merge pull request #43607 from nextcloud/enh/migrate-ocx-providers-setupcheck
enh(setting): Migrate OCM / OCS provider tests to SetupCheckpull/39244/head^2
commit
f2f1074396
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
|
||||
*
|
||||
* @author Ferdinand Thiessen <opensource@fthiessen.de>
|
||||
*
|
||||
* @license AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
namespace OCA\Settings\SetupChecks;
|
||||
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\SetupCheck\ISetupCheck;
|
||||
use OCP\SetupCheck\SetupResult;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* Checks if the webserver serves the OCM and OCS providers
|
||||
*/
|
||||
class OcxProviders implements ISetupCheck {
|
||||
use CheckServerResponseTrait;
|
||||
|
||||
public function __construct(
|
||||
protected IL10N $l10n,
|
||||
protected IConfig $config,
|
||||
protected IURLGenerator $urlGenerator,
|
||||
protected IClientService $clientService,
|
||||
protected LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getCategory(): string {
|
||||
return 'network';
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return $this->l10n->t('OCS provider resolving');
|
||||
}
|
||||
|
||||
public function run(): SetupResult {
|
||||
// List of providers that work
|
||||
$workingProviders = [];
|
||||
// List of providers we tested (in case one or multiple do not yield any response)
|
||||
$testedProviders = [];
|
||||
// All providers that we need to test
|
||||
$providers = [
|
||||
'/ocm-provider/',
|
||||
'/ocs-provider/',
|
||||
];
|
||||
|
||||
foreach ($providers as $provider) {
|
||||
foreach ($this->runHEAD($this->urlGenerator->getWebroot() . $provider) as $response) {
|
||||
$testedProviders[$provider] = true;
|
||||
if ($response->getStatusCode() === 200) {
|
||||
$workingProviders[] = $provider;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($testedProviders) < count($providers)) {
|
||||
return SetupResult::warning(
|
||||
$this->l10n->t('Could not check if your web server properly resolves the OCM and OCS provider URLs.', ) . "\n" . $this->serverConfigHelp(),
|
||||
);
|
||||
}
|
||||
|
||||
$missingProviders = array_diff($providers, $workingProviders);
|
||||
if (empty($missingProviders)) {
|
||||
return SetupResult::success();
|
||||
}
|
||||
|
||||
return SetupResult::warning(
|
||||
$this->l10n->t('Your web server is not properly set up to resolve %1$s.
|
||||
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.
|
||||
On Nginx those are typically the lines starting with "location ~" that need an update.', [join(', ', array_map(fn ($s) => '"'.$s.'"', $missingProviders))]),
|
||||
$this->urlGenerator->linkToDocs('admin-nginx'),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
|
||||
*
|
||||
* @author Ferdinand Thiessen <opensource@fthiessen.de>
|
||||
*
|
||||
* @license AGPL-3.0-or-later
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
namespace OCA\Settings\Tests;
|
||||
|
||||
use OCA\Settings\SetupChecks\OcxProviders;
|
||||
use OCP\Http\Client\IClientService;
|
||||
use OCP\Http\Client\IResponse;
|
||||
use OCP\IConfig;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\SetupCheck\SetupResult;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
class OcxProvicersTest extends TestCase {
|
||||
private IL10N|MockObject $l10n;
|
||||
private IConfig|MockObject $config;
|
||||
private IURLGenerator|MockObject $urlGenerator;
|
||||
private IClientService|MockObject $clientService;
|
||||
private LoggerInterface|MockObject $logger;
|
||||
private OcxProviders|MockObject $setupcheck;
|
||||
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
/** @var IL10N|MockObject */
|
||||
$this->l10n = $this->getMockBuilder(IL10N::class)
|
||||
->disableOriginalConstructor()->getMock();
|
||||
$this->l10n->expects($this->any())
|
||||
->method('t')
|
||||
->willReturnCallback(function ($message, array $replace) {
|
||||
return vsprintf($message, $replace);
|
||||
});
|
||||
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->clientService = $this->createMock(IClientService::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$this->setupcheck = $this->getMockBuilder(OcxProviders::class)
|
||||
->onlyMethods(['runHEAD'])
|
||||
->setConstructorArgs([
|
||||
$this->l10n,
|
||||
$this->config,
|
||||
$this->urlGenerator,
|
||||
$this->clientService,
|
||||
$this->logger,
|
||||
])
|
||||
->getMock();
|
||||
}
|
||||
|
||||
public function testSuccess(): void {
|
||||
$response = $this->createMock(IResponse::class);
|
||||
$response->expects($this->any())->method('getStatusCode')->willReturn(200);
|
||||
|
||||
$this->setupcheck
|
||||
->expects($this->exactly(2))
|
||||
->method('runHEAD')
|
||||
->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([$response]));
|
||||
|
||||
$result = $this->setupcheck->run();
|
||||
$this->assertEquals(SetupResult::SUCCESS, $result->getSeverity());
|
||||
}
|
||||
|
||||
public function testLateSuccess(): void {
|
||||
$response1 = $this->createMock(IResponse::class);
|
||||
$response1->expects($this->exactly(3))->method('getStatusCode')->willReturnOnConsecutiveCalls(404, 500, 200);
|
||||
$response2 = $this->createMock(IResponse::class);
|
||||
$response2->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(200);
|
||||
|
||||
$this->setupcheck
|
||||
->expects($this->exactly(2))
|
||||
->method('runHEAD')
|
||||
->willReturnOnConsecutiveCalls($this->generate([$response1, $response1, $response1]), $this->generate([$response2])); // only one response out of two
|
||||
|
||||
$result = $this->setupcheck->run();
|
||||
$this->assertEquals(SetupResult::SUCCESS, $result->getSeverity());
|
||||
}
|
||||
|
||||
public function testNoResponse(): void {
|
||||
$response = $this->createMock(IResponse::class);
|
||||
$response->expects($this->any())->method('getStatusCode')->willReturn(200);
|
||||
|
||||
$this->setupcheck
|
||||
->expects($this->exactly(2))
|
||||
->method('runHEAD')
|
||||
->willReturnOnConsecutiveCalls($this->generate([]), $this->generate([])); // No responses
|
||||
|
||||
$result = $this->setupcheck->run();
|
||||
$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
|
||||
$this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
|
||||
}
|
||||
|
||||
public function testPartialResponse(): void {
|
||||
$response = $this->createMock(IResponse::class);
|
||||
$response->expects($this->any())->method('getStatusCode')->willReturn(200);
|
||||
|
||||
$this->setupcheck
|
||||
->expects($this->exactly(2))
|
||||
->method('runHEAD')
|
||||
->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([])); // only one response out of two
|
||||
|
||||
$result = $this->setupcheck->run();
|
||||
$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
|
||||
$this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
|
||||
}
|
||||
|
||||
public function testInvalidResponse(): void {
|
||||
$response = $this->createMock(IResponse::class);
|
||||
$response->expects($this->any())->method('getStatusCode')->willReturn(404);
|
||||
|
||||
$this->setupcheck
|
||||
->expects($this->exactly(2))
|
||||
->method('runHEAD')
|
||||
->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([$response])); // only one response out of two
|
||||
|
||||
$result = $this->setupcheck->run();
|
||||
$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
|
||||
$this->assertMatchesRegularExpression('/^Your web server is not properly set up/', $result->getDescription());
|
||||
}
|
||||
|
||||
public function testPartialInvalidResponse(): void {
|
||||
$response1 = $this->createMock(IResponse::class);
|
||||
$response1->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(200);
|
||||
$response2 = $this->createMock(IResponse::class);
|
||||
$response2->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(404);
|
||||
|
||||
$this->setupcheck
|
||||
->expects($this->exactly(2))
|
||||
->method('runHEAD')
|
||||
->willReturnOnConsecutiveCalls($this->generate([$response1]), $this->generate([$response2]));
|
||||
|
||||
$result = $this->setupcheck->run();
|
||||
$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
|
||||
$this->assertMatchesRegularExpression('/^Your web server is not properly set up/', $result->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function creates a nicer interface for mocking Generator behavior
|
||||
*/
|
||||
protected function generate(array $yield_values) {
|
||||
return $this->returnCallback(function () use ($yield_values) {
|
||||
yield from $yield_values;
|
||||
});
|
||||
}
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
({69129:function(){window.addEventListener("DOMContentLoaded",(()=>{$("#loglevel").change((function(){$.post(OC.generateUrl("/settings/admin/log/level"),{level:$(this).val()},(()=>{OC.Log.reload()}))})),$("#mail_smtpauth").change((function(){this.checked?$("#mail_credentials").removeClass("hidden"):$("#mail_credentials").addClass("hidden")})),$("#mail_smtpmode").change((function(){"smtp"!==$(this).val()?($("#setting_smtpauth").addClass("hidden"),$("#setting_smtphost").addClass("hidden"),$("#mail_smtpsecure_label").addClass("hidden"),$("#mail_smtpsecure").addClass("hidden"),$("#mail_credentials").addClass("hidden"),$("#mail_sendmailmode_label, #mail_sendmailmode").removeClass("hidden")):($("#setting_smtpauth").removeClass("hidden"),$("#setting_smtphost").removeClass("hidden"),$("#mail_smtpsecure_label").removeClass("hidden"),$("#mail_smtpsecure").removeClass("hidden"),$("#mail_smtpauth").is(":checked")&&$("#mail_credentials").removeClass("hidden"),$("#mail_sendmailmode_label, #mail_sendmailmode").addClass("hidden"))}));const e=function(){OC.PasswordConfirmation.requiresPasswordConfirmation()?OC.PasswordConfirmation.requirePasswordConfirmation(e):(OC.msg.startSaving("#mail_settings_msg"),$.ajax({url:OC.generateUrl("/settings/admin/mailsettings"),type:"POST",data:$("#mail_general_settings_form").serialize(),success:()=>{OC.msg.finishedSuccess("#mail_settings_msg",t("settings","Saved"))},error:e=>{OC.msg.finishedError("#mail_settings_msg",e.responseJSON)}}))},s=function(){OC.PasswordConfirmation.requiresPasswordConfirmation()?OC.PasswordConfirmation.requirePasswordConfirmation(s):(OC.msg.startSaving("#mail_settings_msg"),$.ajax({url:OC.generateUrl("/settings/admin/mailsettings/credentials"),type:"POST",data:$("#mail_credentials_settings").serialize(),success:()=>{OC.msg.finishedSuccess("#mail_settings_msg",t("settings","Saved"))},error:e=>{OC.msg.finishedError("#mail_settings_msg",e.responseJSON)}}))};$("#mail_general_settings_form").change(e),$("#mail_credentials_settings_submit").click(s),$("#mail_smtppassword").click((()=>{"text"===this.N&&"********"===this.U&&(this.N="password",this.U="")})),$("#sendtestemail").click((e=>{e.preventDefault(),OC.msg.startAction("#sendtestmail_msg",t("settings","Sending…")),$.ajax({url:OC.generateUrl("/settings/admin/mailtest"),type:"POST",success:()=>{OC.msg.finishedSuccess("#sendtestmail_msg",t("settings","Email sent"))},error:e=>{OC.msg.finishedError("#sendtestmail_msg",e.responseJSON)}})})),null!==document.getElementById("security-warning")&&$.when(OC.SetupChecks.checkWebDAV(),OC.SetupChecks.checkWellKnownUrl("GET","/.well-known/webfinger",OC.theme.docPlaceholderUrl,!0===$("#postsetupchecks").data("check-wellknown"),[200,404],!0),OC.SetupChecks.checkWellKnownUrl("GET","/.well-known/nodeinfo",OC.theme.docPlaceholderUrl,!0===$("#postsetupchecks").data("check-wellknown"),[200,404],!0),OC.SetupChecks.checkWellKnownUrl("PROPFIND","/.well-known/caldav",OC.theme.docPlaceholderUrl,!0===$("#postsetupchecks").data("check-wellknown")),OC.SetupChecks.checkWellKnownUrl("PROPFIND","/.well-known/carddav",OC.theme.docPlaceholderUrl,!0===$("#postsetupchecks").data("check-wellknown")),OC.SetupChecks.checkProviderUrl(OC.getRootPath()+"/ocm-provider/",OC.theme.docPlaceholderUrl,!0===$("#postsetupchecks").data("check-wellknown")),OC.SetupChecks.checkProviderUrl(OC.getRootPath()+"/ocs-provider/",OC.theme.docPlaceholderUrl,!0===$("#postsetupchecks").data("check-wellknown")),OC.SetupChecks.checkSetup(),OC.SetupChecks.checkGeneric(),OC.SetupChecks.checkDataProtected()).then(((e,s,t,n,i,a,l,d,r,c)=>{const o=[].concat(e,s,t,n,i,a,l,d,r,c),m=$("#postsetupchecks");$("#security-warning-state-loading").addClass("hidden");let h=!1;const C=m.find(".errors"),g=m.find(".warnings"),u=m.find(".info");for(let e=0;e<o.length;e++)switch(o[e].type){case OC.SetupChecks.MESSAGE_TYPE_INFO:u.append("<li>"+o[e].msg+"</li>");break;case OC.SetupChecks.MESSAGE_TYPE_WARNING:g.append("<li>"+o[e].msg+"</li>");break;case OC.SetupChecks.MESSAGE_TYPE_ERROR:default:C.append("<li>"+o[e].msg+"</li>")}C.find("li").length>0&&(C.removeClass("hidden"),h=!0),g.find("li").length>0&&(g.removeClass("hidden"),h=!0),u.find("li").length>0&&(u.removeClass("hidden"),h=!0),h?($("#postsetupchecks-hint").removeClass("hidden"),C.find("li").length>0?$("#security-warning-state-failure").removeClass("hidden"):$("#security-warning-state-warning").removeClass("hidden")):0===$("#security-warning").children("ul").children().length?$("#security-warning-state-ok").removeClass("hidden"):$("#security-warning-state-failure").removeClass("hidden")}))}))}})[69129]();
|
||||
//# sourceMappingURL=settings-legacy-admin.js.map?v=c2b25dad23230635bc3c
|
||||
({69129:function(){window.addEventListener("DOMContentLoaded",(()=>{$("#loglevel").change((function(){$.post(OC.generateUrl("/settings/admin/log/level"),{level:$(this).val()},(()=>{OC.Log.reload()}))})),$("#mail_smtpauth").change((function(){this.checked?$("#mail_credentials").removeClass("hidden"):$("#mail_credentials").addClass("hidden")})),$("#mail_smtpmode").change((function(){"smtp"!==$(this).val()?($("#setting_smtpauth").addClass("hidden"),$("#setting_smtphost").addClass("hidden"),$("#mail_smtpsecure_label").addClass("hidden"),$("#mail_smtpsecure").addClass("hidden"),$("#mail_credentials").addClass("hidden"),$("#mail_sendmailmode_label, #mail_sendmailmode").removeClass("hidden")):($("#setting_smtpauth").removeClass("hidden"),$("#setting_smtphost").removeClass("hidden"),$("#mail_smtpsecure_label").removeClass("hidden"),$("#mail_smtpsecure").removeClass("hidden"),$("#mail_smtpauth").is(":checked")&&$("#mail_credentials").removeClass("hidden"),$("#mail_sendmailmode_label, #mail_sendmailmode").addClass("hidden"))}));const e=function(){OC.PasswordConfirmation.requiresPasswordConfirmation()?OC.PasswordConfirmation.requirePasswordConfirmation(e):(OC.msg.startSaving("#mail_settings_msg"),$.ajax({url:OC.generateUrl("/settings/admin/mailsettings"),type:"POST",data:$("#mail_general_settings_form").serialize(),success:()=>{OC.msg.finishedSuccess("#mail_settings_msg",t("settings","Saved"))},error:e=>{OC.msg.finishedError("#mail_settings_msg",e.responseJSON)}}))},s=function(){OC.PasswordConfirmation.requiresPasswordConfirmation()?OC.PasswordConfirmation.requirePasswordConfirmation(s):(OC.msg.startSaving("#mail_settings_msg"),$.ajax({url:OC.generateUrl("/settings/admin/mailsettings/credentials"),type:"POST",data:$("#mail_credentials_settings").serialize(),success:()=>{OC.msg.finishedSuccess("#mail_settings_msg",t("settings","Saved"))},error:e=>{OC.msg.finishedError("#mail_settings_msg",e.responseJSON)}}))};$("#mail_general_settings_form").change(e),$("#mail_credentials_settings_submit").click(s),$("#mail_smtppassword").click((()=>{"text"===this.N&&"********"===this.U&&(this.N="password",this.U="")})),$("#sendtestemail").click((e=>{e.preventDefault(),OC.msg.startAction("#sendtestmail_msg",t("settings","Sending…")),$.ajax({url:OC.generateUrl("/settings/admin/mailtest"),type:"POST",success:()=>{OC.msg.finishedSuccess("#sendtestmail_msg",t("settings","Email sent"))},error:e=>{OC.msg.finishedError("#sendtestmail_msg",e.responseJSON)}})})),null!==document.getElementById("security-warning")&&$.when(OC.SetupChecks.checkWebDAV(),OC.SetupChecks.checkWellKnownUrl("GET","/.well-known/webfinger",OC.theme.docPlaceholderUrl,!0===$("#postsetupchecks").data("check-wellknown"),[200,404],!0),OC.SetupChecks.checkWellKnownUrl("GET","/.well-known/nodeinfo",OC.theme.docPlaceholderUrl,!0===$("#postsetupchecks").data("check-wellknown"),[200,404],!0),OC.SetupChecks.checkWellKnownUrl("PROPFIND","/.well-known/caldav",OC.theme.docPlaceholderUrl,!0===$("#postsetupchecks").data("check-wellknown")),OC.SetupChecks.checkWellKnownUrl("PROPFIND","/.well-known/carddav",OC.theme.docPlaceholderUrl,!0===$("#postsetupchecks").data("check-wellknown")),OC.SetupChecks.checkSetup(),OC.SetupChecks.checkGeneric(),OC.SetupChecks.checkDataProtected()).then(((e,s,t,n,i,a,l,d)=>{const r=[].concat(e,s,t,n,i,a,l,d),c=$("#postsetupchecks");$("#security-warning-state-loading").addClass("hidden");let m=!1;const o=c.find(".errors"),h=c.find(".warnings"),g=c.find(".info");for(let e=0;e<r.length;e++)switch(r[e].type){case OC.SetupChecks.MESSAGE_TYPE_INFO:g.append("<li>"+r[e].msg+"</li>");break;case OC.SetupChecks.MESSAGE_TYPE_WARNING:h.append("<li>"+r[e].msg+"</li>");break;case OC.SetupChecks.MESSAGE_TYPE_ERROR:default:o.append("<li>"+r[e].msg+"</li>")}o.find("li").length>0&&(o.removeClass("hidden"),m=!0),h.find("li").length>0&&(h.removeClass("hidden"),m=!0),g.find("li").length>0&&(g.removeClass("hidden"),m=!0),m?($("#postsetupchecks-hint").removeClass("hidden"),o.find("li").length>0?$("#security-warning-state-failure").removeClass("hidden"):$("#security-warning-state-warning").removeClass("hidden")):0===$("#security-warning").children("ul").children().length?$("#security-warning-state-ok").removeClass("hidden"):$("#security-warning-state-failure").removeClass("hidden")}))}))}})[69129]();
|
||||
//# sourceMappingURL=settings-legacy-admin.js.map?v=689487601db452849a35
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue