Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed reading the QR code as text in the AuthenticationCommand on dev environments #205

Merged
merged 3 commits into from
Sep 11, 2024
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
195 changes: 195 additions & 0 deletions ci/qa/phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,200 @@
parameters:
ignoreErrors:
-
message: "#^Cannot access offset 'authenticationUrl' on mixed\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Cannot access offset 'id' on mixed\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Cannot access offset 'identities' on mixed\\.$#"
count: 2
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Cannot access offset 'ocraSuite' on mixed\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Cannot access offset 'secret' on mixed\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Cannot access offset int\\|string\\|false on mixed\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Cannot access offset string on mixed\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Parameter \\#1 \\$array of function array_keys expects array, mixed given\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Parameter \\#1 \\$file of method Surfnet\\\\Tiqr\\\\Dev\\\\Command\\\\AuthenticationCommand\\:\\:readAuthenticationLinkFromFile\\(\\) expects string, mixed given\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Parameter \\#1 \\$ocraSuite of static method OCRA\\:\\:generateOCRA\\(\\) expects string, mixed given\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Parameter \\#1 \\$uri of method GuzzleHttp\\\\Client\\:\\:post\\(\\) expects Psr\\\\Http\\\\Message\\\\UriInterface\\|string, mixed given\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Parameter \\#2 \\$key of static method OCRA\\:\\:generateOCRA\\(\\) expects string, mixed given\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#"
count: 1
path: ../../dev/Command/AuthenticationCommand.php

-
message: "#^Cannot access offset 'authenticationUrl' on mixed\\.$#"
count: 1
path: ../../dev/Command/RegistrationCommand.php

-
message: "#^Cannot access offset 'identities' on mixed\\.$#"
count: 2
path: ../../dev/Command/RegistrationCommand.php

-
message: "#^Cannot access offset 'ocraSuite' on mixed\\.$#"
count: 1
path: ../../dev/Command/RegistrationCommand.php

-
message: "#^Cannot access offset mixed on mixed\\.$#"
count: 5
path: ../../dev/Command/RegistrationCommand.php

-
message: "#^Cannot access property \\$service on mixed\\.$#"
count: 2
path: ../../dev/Command/RegistrationCommand.php

-
message: "#^Method Surfnet\\\\Tiqr\\\\Dev\\\\Command\\\\RegistrationCommand\\:\\:storeIdentity\\(\\) has parameter \\$metadata with no type specified\\.$#"
count: 1
path: ../../dev/Command/RegistrationCommand.php

-
message: "#^Method Surfnet\\\\Tiqr\\\\Dev\\\\Command\\\\RegistrationCommand\\:\\:storeIdentity\\(\\) has parameter \\$secret with no type specified\\.$#"
count: 1
path: ../../dev/Command/RegistrationCommand.php

-
message: "#^Parameter \\#1 \\$file of method Surfnet\\\\Tiqr\\\\Dev\\\\Command\\\\RegistrationCommand\\:\\:readRegistrationUrlFromFile\\(\\) expects string, mixed given\\.$#"
count: 1
path: ../../dev/Command/RegistrationCommand.php

-
message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#"
count: 1
path: ../../dev/Command/RegistrationCommand.php

-
message: "#^Call to an undefined method SAML2\\\\Message\\:\\:getStatus\\(\\)\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Cannot call method getValue\\(\\) on SAML2\\\\XML\\\\saml\\\\Issuer\\|null\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Cannot cast mixed to string\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Method Surfnet\\\\Tiqr\\\\Dev\\\\Controller\\\\SPController\\:\\:signRequestQuery\\(\\) has parameter \\$queryParams with no value type specified in iterable type array\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^PHPDoc tag @var has invalid value \\(\\$securityKey\\)\\: Unexpected token \"\\$securityKey\", expected type at offset 10$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Parameter \\#1 \\$key of method SAML2\\\\Certificate\\\\PrivateKeyLoader\\:\\:loadPrivateKey\\(\\) expects SAML2\\\\Configuration\\\\PrivateKey, mixed given\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Parameter \\#1 \\$nameId of method Surfnet\\\\SamlBundle\\\\SAML2\\\\AuthnRequest\\:\\:setSubject\\(\\) expects string, mixed given\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Parameter \\#1 \\$source of method DOMDocument\\:\\:loadXML\\(\\) expects string, bool\\|string given\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Parameter \\#1 \\$string of function base64_decode expects string, bool\\|float\\|int\\|string\\|null given\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Parameter \\#1 \\$string of function base64_encode expects string, string\\|false given\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Parameter \\#1 \\$xml of static method SAML2\\\\Message\\:\\:fromXML\\(\\) expects DOMElement, DOMElement\\|null given\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Parameter \\#2 \\$values of method Symfony\\\\Component\\\\HttpFoundation\\\\ResponseHeaderBag\\:\\:set\\(\\) expects array\\<string\\>\\|string\\|null, mixed given\\.$#"
count: 1
path: ../../dev/Controller/SPController.php

-
message: "#^Method Surfnet\\\\Tiqr\\\\Dev\\\\FileLogger\\:\\:getLogs\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: ../../dev/FileLogger.php

-
message: "#^Method Surfnet\\\\Tiqr\\\\Dev\\\\FileLogger\\:\\:log\\(\\) has parameter \\$context with no value type specified in iterable type array\\.$#"
count: 1
path: ../../dev/FileLogger.php

-
message: "#^Parameter \\#1 \\$record of method League\\\\Csv\\\\Writer\\:\\:insertOne\\(\\) expects array\\<float\\|int\\|string\\|Stringable\\|null\\>, array\\<int, mixed\\> given\\.$#"
count: 1
path: ../../dev/FileLogger.php

-
message: "#^Parameter \\#1 \\$stream of static method League\\\\Csv\\\\AbstractCsv\\:\\:createFromStream\\(\\) expects resource, resource\\|false given\\.$#"
count: 1
path: ../../dev/FileLogger.php

-
message: "#^Parameter \\#3 \\$response of method Surfnet\\\\Tiqr\\\\Tiqr\\\\AuthenticationRateLimitServiceInterface\\:\\:authenticate\\(\\) expects string, mixed given\\.$#"
count: 1
Expand Down
1 change: 1 addition & 0 deletions ci/qa/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ parameters:
level: 9
paths:
- ../../src
- ../../dev
21 changes: 13 additions & 8 deletions dev/Command/AuthenticationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
[$serviceId, $session, $challenge, $sp, $version] = explode('/', $authn);

$userId = null;
if (strpos($serviceId, '@') >= 0) {
if (str_contains($serviceId, '@')) {
[$userId, $serviceId] = explode('@', $serviceId);
}

Expand All @@ -101,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'sp' => $sp,
'version' => $version,
'userId' => $userId,
], JSON_PRETTY_PRINT)),
], JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)),
]);

$service = $this->getService($serviceId);
Expand All @@ -126,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$service['id'] = $serviceId;
$output->writeln([
'<comment>Generate OCRA for service:</comment>',
$this->decorateResult(json_encode($service, JSON_PRETTY_PRINT)),
$this->decorateResult(json_encode($service, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)),
]);

$response = OCRA::generateOCRA($ocraSuite, $secret, '', $challenge, '', $session, '');
Expand All @@ -143,16 +143,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'sessionKey' => $session,
'userId' => $userId,
'response' => $response,
'notificationType' => $input->getOption('notificationType', ''),
'notificationAddress' => $input->getOption('notificationAddress', ''),
'notificationType' => $input->getOption('notificationType'),
'notificationAddress' => $input->getOption('notificationAddress'),
];

$output->writeln([
sprintf(
'<comment>Send authentication data to "%s" with body:</comment>',
$authenticationUrl
),
$this->decorateResult(json_encode($authenticationBody, JSON_PRETTY_PRINT)),
$this->decorateResult(json_encode($authenticationBody, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)),
]);

$result = $this->client->post($authenticationUrl, [
Expand All @@ -166,22 +166,27 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::SUCCESS;
}

protected function decorateResult($text): string
protected function decorateResult(string $text): string
{
return "<options=bold>$text</>";
}

protected function readAuthenticationLinkFromFile(string $file, OutputInterface $output): string
{
$qrcode = new QrReader(file_get_contents($file), QrReader::SOURCE_TYPE_BLOB);
/** @phpstan-var mixed $link */
$link = $qrcode->text();

if (!is_string($link)) {
throw new RuntimeException('Unable to read a link from the QR code');
}

$output->writeln([
'Registration link result: ',
$this->decorateResult($link),
]);

return $link->toString();
return $link;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions dev/Command/RegistrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$metadata = json_decode($metadataBody);
$output->writeln([
'Metadata result:',
$this->decorateResult(json_encode($metadata, JSON_PRETTY_PRINT)),
$this->decorateResult(json_encode($metadata, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)),
]);
if ($metadata === false) {
$output->writeln('<error>Metadata has expired</error>');
Expand All @@ -99,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'<comment>Send registration data to enrollmentUrl "%s" with body:</comment>',
$metadata->service->enrollmentUrl
),
$this->decorateResult(json_encode($registrationBody, JSON_PRETTY_PRINT)),
$this->decorateResult(json_encode($registrationBody, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)),
]);

$result = $this->client->post($metadata->service->enrollmentUrl, ['form_params' => $registrationBody]);
Expand All @@ -121,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return Command::SUCCESS;
}

protected function decorateResult($text): string
protected function decorateResult(string $text): string
{
return "<options=bold>$text</>";
}
Expand Down
4 changes: 4 additions & 0 deletions dev/FileLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function log($level, $message, array $context = []): void
return;
}
$file = fopen($this->getCSVFile(), 'ab+');
if (!$file) {
return;
}

$csv = Writer::createFromStream($file);
$csv->setDelimiter(';');
$csv->insertOne([$level, $message, json_encode($context)]);
Expand Down
2 changes: 1 addition & 1 deletion dev/Twig/GsspExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function generateDemoSPUrl(): string
{
return sprintf(
'https://pieter.aai.surfnet.nl/simplesamlphp/sp.php?idp=%s',
urlencode($this->hostedEntities->getIdentityProvider()->getEntityId())
urlencode($this->hostedEntities->getIdentityProvider()?->getEntityId() ?? '')
);
}
}