Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .php-cs-fixer.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"php":"8.3.6","version":"3.22.0","indent":"\t","lineEnding":"\n","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"class_definition":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"curly_braces_position":{"classes_opening_brace":"same_line","functions_opening_brace":"same_line"},"elseif":true,"function_declaration":{"closure_function_spacing":"one"},"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ignore"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["property","method","const"]},"align_multiline_comment":true,"array_indentation":true,"binary_operator_spaces":{"default":"single_space"},"blank_line_after_opening_tag":true,"no_unused_imports":true,"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"alpha"}},"hashes":{"tests\/unit\/Slup32JobToCircuitBreakerTest.php":"3cddb1dbf0e551152396ca4c3cc7a626","tests\/unit\/NmcProvisioningDependencyTest.php":"6789d96aa58bc1417cf75ffa2134dc84","tests\/unit\/Slup10ReceiverTest.php":"36a1cc8172421d7bd123cc7af49a9d3c","tests\/unit\/Slup30CircuitBreakerTest.php":"7f0600d1e0cb3d543c55160e8c8d65fa","tests\/unit\/SlupStatusApiTest.php":"3a9b2ab10d5ced2869cbc08f6c3bd096","tests\/unit\/Slup31ReceiverToCircuitBreakerTest.php":"4905d62e745e8cb836b831bdd738dd11","tests\/unit\/Slup20SendRegistrationTest.php":"cbb355aaa37e6221801c71ae987030b2","tests\/unit\/Slup40ControlJobTest.php":"0d37bcd66219db12958e5a447134aa82","tests\/integration\/SlupSendRegistrationTest.php":"ae88ec552eb22d54d45d5bae7f3932c3","tests\/bootstrap.php":"7b6b4c6e990e51019d1c294007ba4944","tests\/helper\/SoapTestCase.php":"8e8924474c4c0e3523d312940f95daf4","tests\/helper\/SoapTestServer.php":"c7a6b016c5ef51e693b77c5c80881104","lib\/Registration\/SlupCircuitControlJob.php":"210f15213cd9d5891093af9d33528f8a","lib\/Registration\/SoapWSSEToken.php":"aac183a2a0bd2aaf6213f33d65b70230","lib\/Registration\/SlupRegistrationManager.php":"409228c758aa49a0225704998f0e1473","lib\/Registration\/SlupConnectException.php":"325fdc7a16b7ce543a1b7018c5dd92e1","lib\/Registration\/SoapWSSEAuth.php":"67ffe9f6838bb54d491d91c4fee0e96f","lib\/Controller\/SlupApiController.php":"5991d2f7a7c3058fe5ca26dc0f4e89da","lib\/Controller\/SoapApiController.php":"43b7fda74264ad3f6fb2d7484306b6ec","lib\/Controller\/SoapResponse.php":"daf78124d2742871f917f6777ebd26fb","lib\/Controller\/SlupStatusController.php":"578cbbff767f71467a6d55a7a7c8ad68","lib\/AppInfo\/Application.php":"30552bc3efe5254a36531ac1cce8b499","appinfo\/routes.php":"b56345a424a32c7046d89975abf64406"}}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
},
"scripts": {
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"cs:check": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff",
"cs:fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix",
"psalm": "psalm.phar",
"test:unit": "phpunit -c tests/phpunit.xml"
},
Expand Down
11 changes: 5 additions & 6 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
use OCP\App\IAppManager;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;

use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

class Application extends App implements IBootstrap {
public const APP_ID = 'nmcslup';


public function __construct() {
parent::__construct(self::APP_ID);
}

public function register(IRegistrationContext $context): void {
// Register the composer autoloader for packages shipped by this app, if applicable
//include_once __DIR__ . '/../../vendor/autoload.php';
// include_once __DIR__ . '/../../vendor/autoload.php';
}

/**
Expand All @@ -31,9 +29,10 @@ public function register(IRegistrationContext $context): void {
*/
public function boot(IBootContext $context): void {
$appMgr = $this->getContainer()->get(IAppManager::class);
$logger = $this->getContainer()->get(ILogger::class);
$logger = $this->getContainer()->get(LoggerInterface::class);

if (!$appMgr->isInstalled('nmcprovisioning')) {
$logger->error("NmcProvisioning app not installed or enabled, but NmcSlup depends on it!");
$logger->error('NmcProvisioning app not installed or enabled, but NmcSlup depends on it!');
}

// TODO: may check also for minimal version of dependent app
Expand Down
10 changes: 4 additions & 6 deletions lib/Controller/SlupApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
use OCA\NextMagentaCloudSlup\Service\ForbiddenException;
use OCA\NextMagentaCloudSlup\Service\NotFoundException;
use OCA\NextMagentaCloudSlup\User\UserExistException;

use OCP\ILogger;
use OCP\IRequest;
use Psr\Log\LoggerInterface;

class SlupApiController extends SoapApiController {
public const PROVIDER_PREFIX = 'Telekom';


/** ILogger already comes from parent class */
/** LoggerInterface already comes from parent class */

/** @var SlupRegistrationManager */
private $slupRegistrationMgr;
Expand Down Expand Up @@ -68,7 +66,7 @@ class SlupApiController extends SoapApiController {
*/
public function __construct($appName,
IRequest $request,
ILogger $logger,
LoggerInterface $logger,
SlupRegistrationManager $slupRegistrationMgr,
TariffRules $tariffRules,
DisplaynameRules $displaynameRules,
Expand Down Expand Up @@ -206,7 +204,7 @@ public function SLUP($request) {
} catch (\InvalidArgumentException | ForbiddenException | NotFoundException | UserExistException | \Exception $e) {
$this->logger->logException($e, [
'message' => "SLUP processing error: {$e->getMessage()}): " . PHP_EOL . json_encode($request),
'level' => ILogger::ERROR,
'level' => LoggerInterface::ERROR,
'app' => 'nmcslup'
]);
}
Expand Down
8 changes: 3 additions & 5 deletions lib/Controller/SlupStatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@

use OCA\NextMagentaCloudSlup\Registration\SlupRegistrationManager;
use OCP\AppFramework\ApiController;

use OCP\AppFramework\Http\DataResponse;
use OCP\ILogger;

use OCP\IRequest;
use Psr\Log\LoggerInterface;

class SlupStatusController extends ApiController {

/** @var ILogger */
/** @var LoggerInterface */
protected $logger;

/** @var SlupRegistrationManager */
Expand All @@ -55,7 +53,7 @@ class SlupStatusController extends ApiController {
*/
public function __construct($appName,
IRequest $request,
ILogger $logger,
LoggerInterface $logger,
SlupRegistrationManager $slupRegistrationMgr,
$corsMethods = 'POST',
$corsAllowedHeaders = 'Authorization, Content-Type, Accept',
Expand Down
7 changes: 3 additions & 4 deletions lib/Controller/SoapApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@

use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\Response;

use OCP\ILogger;
use OCP\IRequest;
use Psr\Log\LoggerInterface;

/**
* Base class to inherit a Soap API handling controller from
* common API controller to provide SOAP style API
*/
abstract class SoapApiController extends ApiController {

/** @var ILogger */
/** @var LoggerInterface */
protected $logger;

/**
Expand All @@ -64,7 +63,7 @@ abstract class SoapApiController extends ApiController {
public function __construct($appName,
IRequest $request,
string $wsdlPath,
ILogger $logger,
LoggerInterface $logger,
$corsMethods = 'POST',
$corsAllowedHeaders = 'Authorization, Content-Type, Accept',
$corsMaxAge = 1728000) {
Expand Down
7 changes: 3 additions & 4 deletions lib/Registration/SlupCircuitControlJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@

use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;

use OCP\ILogger;
use Psr\Log\LoggerInterface;

class SlupCircuitControlJob extends TimedJob {

/** @var ILogger */
/** @var LoggerInterface */
private $logger;

/** @var SlupRegistrationManager */
private $registrationManager;

public function __construct(ITimeFactory $time,
ILogger $logger,
LoggerInterface $logger,
SlupRegistrationManager $registrationManager) {
parent::__construct($time);
$this->logger = $logger;
Expand Down
18 changes: 8 additions & 10 deletions lib/Registration/SlupRegistrationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
use OCP\Http\Client\IClientService;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\ILogger;

use OCP\IURLGenerator;
use Psr\Log\LoggerInterface;
use SoapClient;

/**
Expand Down Expand Up @@ -36,7 +35,7 @@ class SlupRegistrationManager {
public const CIRCUIT_HALFOPEN = 'halfopen';
public const CIRCUIT_CLOSED = 'closed';

/** @var ILogger */
/** @var LoggerInterface */
protected $logger;

/** @var IURLGenerator */
Expand Down Expand Up @@ -66,13 +65,13 @@ class SlupRegistrationManager {
private $controlIntervalSec; // time to next half-open try

/**
* @param ILogger $logger
* @param LoggerInterface $logger
* @param IURLGenerator $urlGenerator
* @param IClientService $clientService
* @param IConfig $config
* @param ICacheFactory $cachefactory
*/
public function __construct(ILogger $logger,
public function __construct(LoggerInterface $logger,
IURLGenerator $urlGenerator,
IClientService $clientService,
IConfig $config,
Expand Down Expand Up @@ -279,13 +278,12 @@ public function registerSlup($wait = 5) {
$slupid = $this->config->getAppValue('nmcslup', 'slupid', "10TVL0SLUP0000004901NEXTMAGENTACLOUD0000");
$slupsecret = $this->config->getAppValue('nmcslup', 'slupsecret', "<no default secret>");
$slupGwEndpoint = $this->config->getAppValue('nmcslup', 'slupgwendpoint', 'https://slup2soap00.idm.ver.sul.t-online.de/slupService/');
$trace = ($this->config->getSystemValue('loglevel', ILogger::WARN) == ILogger::DEBUG);

try {
// in case of short hick ups, try a onetime single retry
// to not delay next retry too much
// by going into open state
$token = $this->sendRegistration($slupGwEndpoint, $slupid, $slupsecret, $trace);
$token = $this->sendRegistration($slupGwEndpoint, $slupid, $slupsecret);
$this->setToken($token);
return true;
} catch (\SoapFault $sf) {
Expand Down Expand Up @@ -422,9 +420,9 @@ public function sendRegistration($gwendpoint, $appid, $appsec, $trace = false) {
// and handled as "good" state; so this special sitation
// is only logged in debug mode
if ($slupDetailCode == 'A007') {
$level = ILogger::DEBUG;
$level = 0;
} else {
$level = ILogger::ERROR;
$level = 3;
}
if (!$soapClient) {
$this->logger->debug($fault->getMessage());
Expand All @@ -446,7 +444,7 @@ public function sendRegistration($gwendpoint, $appid, $appsec, $trace = false) {
} catch (\Throwable $e) {
$this->logger->logException($e, [
'message' => "Error code: {$e->getCode()}, message: {$e->getMessage()})",
'level' => ILogger::ERROR,
'level' => 3,
'app' => Application::APP_ID]);
throw $e;
}
Expand Down
8 changes: 3 additions & 5 deletions tests/integration/SlupSendRegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
use OCA\NextMagentaCloudSlup\Registration\SlupRegistrationManager;
use OCP\Http\Client\IClientService;
use OCP\ICacheFactory;

use OCP\IConfig;

use OCP\ILogger;
use OCP\IURLGenerator;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class SlupSendRegistrationTest extends TestCase {

Expand All @@ -29,15 +27,15 @@ public function setUp(): void {
$app = new \OCP\AppFramework\App(Application::APP_ID);
$this->config = $app->getContainer()->get(IConfig::class);
$this->urlGenerator = $app->getContainer()->get(IURLGenerator::class);
$this->registrationManager = new SlupRegistrationManager($app->getContainer()->get(ILogger::class),
$this->registrationManager = new SlupRegistrationManager($app->getContainer()->get(LoggerInterface::class),
$this->urlGenerator,
$app->getContainer()->get(IClientService::class),
$this->config,
$app->getContainer()->get(ICacheFactory::class));
$this->soapClientMock = $this->getMockFromWsdl($this->registrationManager->getWsdlPath());
$this->registrationManager->replaceSoapClient($this->soapClientMock);

$this->realConnectManager = new SlupRegistrationManager($app->getContainer()->get(ILogger::class),
$this->realConnectManager = new SlupRegistrationManager($app->getContainer()->get(LoggerInterface::class),
$this->urlGenerator,
$app->getContainer()->get(IClientService::class),
$this->config,
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/NmcProvisioningDependencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use OCP\App\IAppManager;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\IAppContainer;

use OCP\ILogger;

use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class NmcProvisioningDependencyTest extends TestCase {
public function setUp(): void {
Expand All @@ -24,7 +22,7 @@ public function setUp(): void {
$this->app = $this->getMockBuilder(Application::class)
->onlyMethods(['getContainer'])
->getMock();
$this->logger = $this->getMockForAbstractClass(ILogger::class);
$this->logger = $this->getMockForAbstractClass(LoggerInterface::class);
$containerMock = $this->createMock(IAppContainer::class);
$containerMock->expects($this->at(0))
->method('get')
Expand Down
11 changes: 3 additions & 8 deletions tests/unit/Slup10ReceiverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@
namespace OCA\NextMagentaCloudSlup\UnitTest;

use OCA\NextMagentaCloudProvisioning\Rules\TariffRules;

use OCA\NextMagentaCloudProvisioning\Rules\UserAccountRules;

use OCA\NextMagentaCloudProvisioning\User\NmcUserService;
use OCA\NextMagentaCloudSlup\AppInfo\Application;
use OCA\NextMagentaCloudSlup\Controller\SlupApiController;

use OCA\NextMagentaCloudSlup\Registration\SlupRegistrationManager;
use OCA\NextMagentaCloudSlup\TestHelper\SoapTestCase;
use OCA\UserOIDC\Db\User;

use OCP\IConfig;

use OCP\ILogger;
use OCP\IRequest;
use Psr\Log\LoggerInterface;

/**
* This test must be run with --stderr, e.g.
Expand Down Expand Up @@ -49,11 +44,11 @@ public function setUp(): void {
$this->config = $this->getMockForAbstractClass(IConfig::class);
$app = new \OCP\AppFramework\App(Application::APP_ID);
$this->accountRules = new UserAccountRules($this->config,
$app->getContainer()->get(ILogger::class),
$app->getContainer()->get(LoggerInterface::class),
$this->userServiceMock);
$this->slupController = new SlupApiController(Application::APP_ID,
$app->getContainer()->get(IRequest::class),
$app->getContainer()->get(ILogger::class),
$app->getContainer()->get(LoggerInterface::class),
$this->registrationManagerMock,
$app->getContainer()->get(TariffRules::class),
$this->accountRules);
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/Slup20SendRegistrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
use OCA\NextMagentaCloudSlup\Registration\SlupRegistrationManager;
use OCP\Http\Client\IClientService;
use OCP\ICacheFactory;

use OCP\IConfig;

use OCP\ILogger;
use OCP\IURLGenerator;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

class Slup20SendRegistrationTest extends TestCase {

Expand All @@ -29,15 +27,15 @@ public function setUp(): void {
$app = new \OCP\AppFramework\App(Application::APP_ID);
$this->config = $app->getContainer()->get(IConfig::class);
$this->urlGenerator = $app->getContainer()->get(IURLGenerator::class);
$this->registrationManager = new SlupRegistrationManager($app->getContainer()->get(ILogger::class),
$this->registrationManager = new SlupRegistrationManager($app->getContainer()->get(LoggerInterface::class),
$this->urlGenerator,
$app->getContainer()->get(IClientService::class),
$this->config,
$app->getContainer()->get(ICacheFactory::class));
$this->soapClientMock = $this->getMockFromWsdl($this->registrationManager->getWsdlPath());
$this->registrationManager->replaceSoapClient($this->soapClientMock);

$this->realConnectManager = new SlupRegistrationManager($app->getContainer()->get(ILogger::class),
$this->realConnectManager = new SlupRegistrationManager($app->getContainer()->get(LoggerInterface::class),
$this->urlGenerator,
$app->getContainer()->get(IClientService::class),
$this->config,
Expand Down
7 changes: 2 additions & 5 deletions tests/unit/Slup30CircuitBreakerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
use OCA\NextMagentaCloudSlup\TestHelper\SoapTestCase;
use OCP\AppFramework\App;
use OCP\Http\Client\IClientService;

use OCP\ICacheFactory;

use OCP\IConfig;

use OCP\ILogger;
use OCP\IURLGenerator;
use PHPUnit\Framework\Assert;
use Psr\Log\LoggerInterface;

class Slup30CircuitBreakerTest extends SoapTestCase {

Expand All @@ -37,7 +34,7 @@ public function setUp(): void {
$this->urlGenerator = $app->getContainer()->get(IURLGenerator::class);
$this->registrationManager = $this->getMockBuilder(SlupRegistrationManager::class)
->onlyMethods(['sendRegistration'])
->setConstructorArgs([ $app->getContainer()->get(ILogger::class),
->setConstructorArgs([ $app->getContainer()->get(LoggerInterface::class),
$this->urlGenerator,
$app->getContainer()->get(IClientService::class),
$this->config,
Expand Down
Loading
Loading