Merge pull request #21546 from nextcloud/techdebt/noid/make-annotations-case-insensitive

Make annotations case insensitive
This commit is contained in:
Joas Schilling 2020-06-23 20:55:38 +02:00 committed by GitHub
commit 2651dfaf15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 24 additions and 21 deletions

View file

@ -114,7 +114,7 @@ class AuthSettingsController extends Controller {
/**
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
*
* @param string $name
@ -183,7 +183,7 @@ class AuthSettingsController extends Controller {
/**
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
*
* @param int $id
* @return array|JSONResponse
@ -205,7 +205,7 @@ class AuthSettingsController extends Controller {
/**
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
*
* @param int $id
* @param array $scope
@ -278,7 +278,7 @@ class AuthSettingsController extends Controller {
/**
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
*
* @param int $id

View file

@ -85,7 +85,7 @@ class ChangePasswordController extends Controller {
/**
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
* @BruteForceProtection(action=changePersonalPassword)
*/
public function changePersonalPassword(string $oldpassword = '', string $newpassword = null): JSONResponse {

View file

@ -67,7 +67,7 @@ class HelpController extends Controller {
*
* @NoCSRFRequired
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
*/
public function help(string $mode = 'user'): TemplateResponse {
$this->navigationManager->setActiveEntry('help');

View file

@ -61,7 +61,7 @@ class PersonalSettingsController extends Controller {
*
* @NoCSRFRequired
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
*/
public function index($section) {
return $this->getIndexResponse('personal', $section);

View file

@ -311,7 +311,7 @@ class UsersController extends Controller {
/**
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
*
* @param string $avatarScope
@ -440,7 +440,7 @@ class UsersController extends Controller {
* Set the mail address of a user
*
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
*
* @param string $account

View file

@ -65,7 +65,7 @@ class WebAuthnController extends Controller {
/**
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
* @UseSession
* @NoCSRFRequired
@ -83,7 +83,7 @@ class WebAuthnController extends Controller {
/**
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
* @UseSession
*/
@ -105,7 +105,7 @@ class WebAuthnController extends Controller {
/**
* @NoAdminRequired
* @NoSubadminRequired
* @NoSubAdminRequired
* @PasswordConfirmationRequired
*/
public function deleteRegistration(int $id): JSONResponse {

View file

@ -35,7 +35,7 @@ use OCP\IL10N;
/**
* Verifies whether an user has at least subadmin rights.
* To bypass use the `@NoSubadminRequired` annotation
* To bypass use the `@NoSubAdminRequired` annotation
*/
class SubadminMiddleware extends Middleware {
/** @var bool */
@ -65,7 +65,7 @@ class SubadminMiddleware extends Middleware {
* @throws \Exception
*/
public function beforeController($controller, $methodName) {
if (!$this->reflector->hasAnnotation('NoSubadminRequired')) {
if (!$this->reflector->hasAnnotation('NoSubAdminRequired')) {
if (!$this->isSubAdmin) {
throw new NotAdminException($this->l10n->t('Logged in user must be a subadmin'));
}

View file

@ -36,7 +36,7 @@ use OCP\IL10N;
/**
* Verifies whether an user has at least subadmin rights.
* To bypass use the `@NoSubadminRequired` annotation
* To bypass use the `@NoSubAdminRequired` annotation
*
* @package Tests\Settings\Middleware
*/
@ -64,14 +64,14 @@ class SubadminMiddlewareTest extends \Test\TestCase {
$this->subadminMiddleware = new SubadminMiddleware($this->reflector, false, $this->l10n);
}
public function testBeforeControllerAsUserWithExemption() {
$this->expectException(\OC\AppFramework\Middleware\Security\Exceptions\NotAdminException::class);
$this->reflector
->expects($this->once())
->method('hasAnnotation')
->with('NoSubadminRequired')
->with('NoSubAdminRequired')
->willReturn(false);
$this->subadminMiddleware->beforeController($this->controller, 'foo');
}
@ -81,7 +81,7 @@ class SubadminMiddlewareTest extends \Test\TestCase {
$this->reflector
->expects($this->once())
->method('hasAnnotation')
->with('NoSubadminRequired')
->with('NoSubAdminRequired')
->willReturn(true);
$this->subadminMiddleware->beforeController($this->controller, 'foo');
}
@ -90,7 +90,7 @@ class SubadminMiddlewareTest extends \Test\TestCase {
$this->reflector
->expects($this->once())
->method('hasAnnotation')
->with('NoSubadminRequired')
->with('NoSubAdminRequired')
->willReturn(false);
$this->subadminMiddlewareAsSubAdmin->beforeController($this->controller, 'foo');
}
@ -99,7 +99,7 @@ class SubadminMiddlewareTest extends \Test\TestCase {
$this->reflector
->expects($this->once())
->method('hasAnnotation')
->with('NoSubadminRequired')
->with('NoSubAdminRequired')
->willReturn(true);
$this->subadminMiddlewareAsSubAdmin->beforeController($this->controller, 'foo');
}
@ -110,7 +110,7 @@ class SubadminMiddlewareTest extends \Test\TestCase {
$this->assertEquals($expectedResponse, $this->subadminMiddleware->afterException($this->controller, 'foo', new NotAdminException('')));
}
public function testAfterRegularException() {
$this->expectException(\Exception::class);

View file

@ -55,6 +55,7 @@ class ControllerMethodReflector implements IControllerMethodReflector {
// extract everything prefixed by @ and first letter uppercase
preg_match_all('/^\h+\*\h+@(?P<annotation>[A-Z]\w+)((?P<parameter>.*))?$/m', $docs, $matches);
foreach ($matches['annotation'] as $key => $annontation) {
$annontation = strtolower($annontation);
$annotationValue = $matches['parameter'][$key];
if (isset($annotationValue[0]) && $annotationValue[0] === '(' && $annotationValue[\strlen($annotationValue) - 1] === ')') {
$cutString = substr($annotationValue, 1, -1);
@ -118,6 +119,7 @@ class ControllerMethodReflector implements IControllerMethodReflector {
* @return bool true if the annotation is found
*/
public function hasAnnotation(string $name): bool {
$name = strtolower($name);
return array_key_exists($name, $this->annotations);
}
@ -129,6 +131,7 @@ class ControllerMethodReflector implements IControllerMethodReflector {
* @return string
*/
public function getAnnotationParameter(string $name, string $key): string {
$name = strtolower($name);
if (isset($this->annotations[$name][$key])) {
return $this->annotations[$name][$key];
}