Skip to content

Commit

Permalink
Merge pull request #291 from owncloud/update-php-cs-fixer
Browse files Browse the repository at this point in the history
[Tests-Only][CI] Update php cs fixer to version 3
  • Loading branch information
phil-davis authored Jun 15, 2021
2 parents ec02589 + 4a38423 commit 4ab10b0
Show file tree
Hide file tree
Showing 28 changed files with 303 additions and 133 deletions.
52 changes: 42 additions & 10 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ def main(ctx):

dependsOn(before, coverageTests)

nonCoverageTests = nonCoveragePipelines(ctx)
if (nonCoverageTests == False):
print('Errors detected in nonCoveragePipelines. Review messages above.')
return []

dependsOn(before, nonCoverageTests)

stages = stagePipelines(ctx)
if (stages == False):
print('Errors detected. Review messages above.')
Expand All @@ -71,18 +78,28 @@ def main(ctx):
dependsOn(coverageTests, afterCoverageTests)

after = afterPipelines(ctx)
dependsOn(afterCoverageTests + stages, after)
dependsOn(afterCoverageTests + nonCoverageTests + stages, after)

return before + coverageTests + afterCoverageTests + stages + after
return before + coverageTests + afterCoverageTests + nonCoverageTests + stages + after

def beforePipelines():
return codestyle() + jscodestyle() + phpstan() + phan()

def coveragePipelines(ctx):
# All pipelines that might have coverage or other test analysis reported
jsPipelines = javascript(ctx)
phpUnitPipelines = phpTests(ctx, 'phpunit')
phpIntegrationPipelines = phpTests(ctx, 'phpintegration')
# All unit test pipelines that have coverage or other test analysis reported
jsPipelines = javascript(ctx, True)
phpUnitPipelines = phpTests(ctx, 'phpunit', True)
phpIntegrationPipelines = phpTests(ctx, 'phpintegration', True)
if (jsPipelines == False) or (phpUnitPipelines == False) or (phpIntegrationPipelines == False):
return False

return jsPipelines + phpUnitPipelines + phpIntegrationPipelines

def nonCoveragePipelines(ctx):
# All unit test pipelines that do not have coverage or other test analysis reported
jsPipelines = javascript(ctx, False)
phpUnitPipelines = phpTests(ctx, 'phpunit', False)
phpIntegrationPipelines = phpTests(ctx, 'phpintegration', False)
if (jsPipelines == False) or (phpUnitPipelines == False) or (phpIntegrationPipelines == False):
return False

Expand Down Expand Up @@ -458,7 +475,7 @@ def build():

return pipelines

def javascript(ctx):
def javascript(ctx, withCoverage):
pipelines = []

if 'javascript' not in config:
Expand Down Expand Up @@ -496,6 +513,14 @@ def javascript(ctx):
if params['skip']:
return pipelines

# if we only want pipelines with coverage, and this pipeline does not do coverage, then do not include it
if withCoverage and not params['coverage']:
return pipelines

# if we only want pipelines without coverage, and this pipeline does coverage, then do not include it
if not withCoverage and params['coverage']:
return pipelines

result = {
'kind': 'pipeline',
'type': 'docker',
Expand Down Expand Up @@ -558,7 +583,7 @@ def javascript(ctx):

return [result]

def phpTests(ctx, testType):
def phpTests(ctx, testType, withCoverage):
pipelines = []

if testType not in config:
Expand Down Expand Up @@ -611,6 +636,14 @@ def phpTests(ctx, testType):
if params['skip']:
continue

# if we only want pipelines with coverage, and this pipeline does not do coverage, then do not include it
if withCoverage and not params['coverage']:
continue

# if we only want pipelines without coverage, and this pipeline does coverage, then do not include it
if not withCoverage and params['coverage']:
continue

cephS3Params = params['cephS3']
if type(cephS3Params) == "bool":
cephS3Needed = cephS3Params
Expand Down Expand Up @@ -797,7 +830,7 @@ def acceptance(ctx):
suites[suite] = suite
else:
suites = matrix['suites']

if 'debugSuites' in matrix and len(matrix['debugSuites']) != 0:
if type(matrix['debugSuites']) == "list":
suites = {}
Expand Down Expand Up @@ -1194,7 +1227,6 @@ def ldapService(ldapNeeded):
'LDAP_ORGANISATION': 'owncloud',
'LDAP_ADMIN_PASSWORD': 'admin',
'LDAP_TLS_VERIFY_CLIENT': 'never',
'HOSTNAME': 'ldap',
}
}]

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/build/
/l10n/.transifexrc
.php_cs.cache
.php-cs-fixer.cache

# Composer
vendor/
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ test-php-unit-dbg: $(composer_deps)
.PHONY: test-php-style
test-php-style: ## Run php-cs-fixer and check owncloud code-style
test-php-style: vendor-bin/owncloud-codestyle/vendor vendor-bin/php_codesniffer/vendor
$(PHP_CS_FIXER) fix -v --diff --diff-format udiff --allow-risky yes --dry-run
$(PHP_CS_FIXER) fix -v --diff --allow-risky yes --dry-run
$(PHP_CODESNIFFER) --runtime-set ignore_warnings_on_exit --standard=phpcs.xml tests/acceptance

.PHONY: test-php-style-fix
test-php-style-fix: ## Run php-cs-fixer and fix code style issues
test-php-style-fix: vendor-bin/owncloud-codestyle/vendor
$(PHP_CS_FIXER) fix -v --diff --diff-format udiff --allow-risky yes
$(PHP_CS_FIXER) fix -v --diff --allow-risky yes

.PHONY: test-php-phan
test-php-phan: ## Run phan
Expand Down
6 changes: 4 additions & 2 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ public function __construct(array $urlParams = []) {
$authPlugin = $event->getServer()->getPlugin('auth');
if ($authPlugin instanceof Plugin) {
$authPlugin->addBackend(
new OAuth2(\OC::$server->getSession(),
new OAuth2(
\OC::$server->getSession(),
\OC::$server->getUserSession(),
\OC::$server->getRequest(),
new AuthModule(),
'principals/')
'principals/'
)
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/BackgroundJob/CleanUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class CleanUp extends TimedJob {

public function __construct(
AuthorizationCodeMapper $authorizationCodeMapper,
AccessTokenMapper $accessTokenMapper) {
AccessTokenMapper $accessTokenMapper
) {
$this->authorizationCodeMapper = $authorizationCodeMapper;
$this->accessTokenMapper = $accessTokenMapper;
}
Expand Down
35 changes: 25 additions & 10 deletions lib/Commands/AddClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,32 @@ protected function configure() {
$this
->setName('oauth2:add-client')
->setDescription('Adds an OAuth2 client')
->addArgument('name', InputArgument::REQUIRED,
'name of the client - will be displayed in the authorization page to the user')
->addArgument('client-id', InputArgument::REQUIRED,
'identifier of the client - used by the client during the implicit and authorization code flow')
->addArgument('client-secret', InputArgument::REQUIRED,
'secret of the client - used by the client during the authorization code flow')
->addArgument('redirect-url', InputArgument::REQUIRED,
'Redirect URL - used in the OAuth flows to post back tokens and authorization codes to the client')
->addArgument('allow-sub-domains', InputArgument::OPTIONAL,
->addArgument(
'name',
InputArgument::REQUIRED,
'name of the client - will be displayed in the authorization page to the user'
)
->addArgument(
'client-id',
InputArgument::REQUIRED,
'identifier of the client - used by the client during the implicit and authorization code flow'
)
->addArgument(
'client-secret',
InputArgument::REQUIRED,
'secret of the client - used by the client during the authorization code flow'
)
->addArgument(
'redirect-url',
InputArgument::REQUIRED,
'Redirect URL - used in the OAuth flows to post back tokens and authorization codes to the client'
)
->addArgument(
'allow-sub-domains',
InputArgument::OPTIONAL,
'Defines if the redirect url is allowed to use sub domains. Enter true or false',
'false');
'false'
);
}

/**
Expand Down
7 changes: 5 additions & 2 deletions lib/Commands/RemoveClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ protected function configure() {
$this
->setName('oauth2:remove-client')
->setDescription('Removes an OAuth2 client')
->addArgument('client-id', InputArgument::REQUIRED,
'identifier of the client - used by the client during the implicit and authorization code flow');
->addArgument(
'client-id',
InputArgument::REQUIRED,
'identifier of the client - used by the client during the implicit and authorization code flow'
);
}

/**
Expand Down
28 changes: 18 additions & 10 deletions lib/Controller/OAuthApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,17 @@ class OAuthApiController extends ApiController {
* @param IURLGenerator $urlGenerator The URL generator.
* @param ILogger $logger The logger.
*/
public function __construct($AppName, IRequest $request,
ClientMapper $clientMapper,
AuthorizationCodeMapper $authorizationCodeMapper,
AccessTokenMapper $accessTokenMapper,
RefreshTokenMapper $refreshTokenMapper,
IUserManager $userManager,
IURLGenerator $urlGenerator,
ILogger $logger) {
public function __construct(
$AppName,
IRequest $request,
ClientMapper $clientMapper,
AuthorizationCodeMapper $authorizationCodeMapper,
AccessTokenMapper $accessTokenMapper,
RefreshTokenMapper $refreshTokenMapper,
IUserManager $userManager,
IURLGenerator $urlGenerator,
ILogger $logger
) {
parent::__construct($AppName, $request);

$this->clientMapper = $clientMapper;
Expand All @@ -105,8 +108,13 @@ public function __construct($AppName, IRequest $request,
* @PublicPage
* @CORS
*/
public function generateToken($grant_type, $code = null,
$redirect_uri = null, $refresh_token = null, $code_verifier = null) {
public function generateToken(
$grant_type,
$code = null,
$redirect_uri = null,
$refresh_token = null,
$code_verifier = null
) {
if (!\is_string($grant_type)) {
return new JSONResponse(['error' => 'invalid_request'], Http::STATUS_BAD_REQUEST);
}
Expand Down
11 changes: 7 additions & 4 deletions lib/Controller/OpenIdConnectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ class OpenIdConnectController extends ApiController {
* @param IURLGenerator $urlGenerator The URL generator.
* @param IAvatarManager $avatarManager
*/
public function __construct($AppName, IRequest $request,
IUserSession $userSession,
IURLGenerator $urlGenerator,
IAvatarManager $avatarManager) {
public function __construct(
$AppName,
IRequest $request,
IUserSession $userSession,
IURLGenerator $urlGenerator,
IAvatarManager $avatarManager
) {
parent::__construct($AppName, $request);

$this->userSession = $userSession;
Expand Down
51 changes: 33 additions & 18 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,16 @@ class PageController extends Controller {
* @param IUserSession $userSession
* @param IUserManager $userManager
*/
public function __construct($AppName, IRequest $request,
ClientMapper $clientMapper,
AuthorizationCodeMapper $authorizationCodeMapper,
AccessTokenMapper $accessTokenMapper,
ILogger $logger,
IURLGenerator $urlGenerator,
IUserSession $userSession,
IUserManager $userManager
public function __construct(
$AppName,
IRequest $request,
ClientMapper $clientMapper,
AuthorizationCodeMapper $authorizationCodeMapper,
AccessTokenMapper $accessTokenMapper,
ILogger $logger,
IURLGenerator $urlGenerator,
IUserSession $userSession,
IUserManager $userManager
) {
parent::__construct($AppName, $request);

Expand Down Expand Up @@ -106,22 +108,29 @@ public function __construct($AppName, IRequest $request,
* @NoAdminRequired
* @NoCSRFRequired
*/
public function authorize($response_type, $client_id, $redirect_uri,
$state = null, $user = null) {
public function authorize(
$response_type,
$client_id,
$redirect_uri,
$state = null,
$user = null
) {
if (!\is_string($response_type) || !\is_string($client_id)
|| !\is_string($redirect_uri) || ($state !== null && !\is_string($state))
) {
$this->logger->error('Invalid OAuth request - one of the mandatory query parameters is missing');
return new TemplateResponse(
$this->appName,
'authorize-error',
['client_name' => null], 'guest'
['client_name' => null],
'guest'
);
}

if ($user !== null && $user !== $this->userSession->getUser()->getUserName()) {
$logoutUrl = $this->urlGenerator->linkToRouteAbsolute(
'oauth2.page.logout', [
'oauth2.page.logout',
[
'user' => $user,
'requesttoken' => Util::callRegister(),
'response_type' => $response_type,
Expand All @@ -137,7 +146,8 @@ public function authorize($response_type, $client_id, $redirect_uri,
$this->appName,
'switch-user',
['current_user' => $currentUser, 'requested_user' => $requestedUser,
'logout_url' => $logoutUrl], 'guest'
'logout_url' => $logoutUrl],
'guest'
);
}
try {
Expand All @@ -148,7 +158,8 @@ public function authorize($response_type, $client_id, $redirect_uri,
return new TemplateResponse(
$this->appName,
'authorize-error',
['client_name' => null], 'guest'
['client_name' => null],
'guest'
);
}

Expand All @@ -157,7 +168,8 @@ public function authorize($response_type, $client_id, $redirect_uri,
return new TemplateResponse(
$this->appName,
'authorize-error',
['client_name' => $client->getName()], 'guest'
['client_name' => $client->getName()],
'guest'
);
}

Expand All @@ -174,7 +186,8 @@ public function authorize($response_type, $client_id, $redirect_uri,
}

$logoutUrl = $this->urlGenerator->linkToRouteAbsolute(
'oauth2.page.logout', [
'oauth2.page.logout',
[
'user' => $user,
'requesttoken' => Util::callRegister(),
'response_type' => $response_type,
Expand Down Expand Up @@ -336,11 +349,13 @@ public function logout($user, $response_type, $client_id, $redirect_uri, $state
]);

// redirect the browser to the login page and set the redirect_url to the authorize page of oauth2
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute('core.login.showLoginForm',
return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute(
'core.login.showLoginForm',
[
'user' => $user,
'redirect_url' => $redirectUrl
]));
]
));
}

/**
Expand Down
Loading

0 comments on commit 4ab10b0

Please sign in to comment.