Skip to content

Commit

Permalink
Fix tests and config
Browse files Browse the repository at this point in the history
  • Loading branch information
parijke committed Feb 12, 2024
1 parent 1927e18 commit b044832
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 29 deletions.
6 changes: 3 additions & 3 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ security:
pattern: ^/(_(profiler|wdt)|css|images|js)/|^/_trans(/|$)
security: false

default:
pattern: ^/authentication/(metadata|session-expired)$
login_firewall:
pattern: ^/saml/metadata

monitor:
pattern: ^/(info|health)$
Expand All @@ -31,5 +31,5 @@ security:
ROLE_RA: ROLE_USER

access_control:
- { path: ^/authentication, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
- { path: ^/saml, roles: PUBLIC_ACCESS, requires_channel: https }
- { path: ^/, roles: ROLE_RA, requires_channel: https }
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function __construct(
array $roles = [],
) {
parent::__construct($roles);
$this->setAuthenticated(count($roles));
}

/**
Expand All @@ -47,22 +46,17 @@ public function getLoa(): Loa
return $this->loa;
}

public function serialize(): array|string
public function __serialize(): array
{
return serialize(
[
parent::serialize(),
$this->loa,
],
);
return [
'parent_data' => parent::__serialize(),
'loa' => $this->loa,
];
}

public function unserialize($serialized): void
public function __unserialize(array $data): void
{
[$parent, $this->loa, ] = unserialize(
$serialized,
);

parent::unserialize($parent);
parent::__unserialize($data['parent_data']);
$this->loa = $data['loa'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public function saml_token_is_correctly_serialized_and_unserialized()
['ROLE_RAA'],
);

$serialized = $samlToken->serialize();
$serialized = $samlToken->__serialize();

$deserialized = new SamlToken(new Loa(Loa::LOA_2, 'http://some.url.tld/authentication/loa2'));
$deserialized->unserialize($serialized);
$deserialized->__unserialize($serialized);

$this->assertEquals($samlToken, $deserialized);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function has($name): bool
return array_key_exists($name, $this->sessionContent);
}

public function get($name, $default = null)
public function get($name, $default = null): mixed
{
return $this->has($name) ? $this->sessionContent[$name] : $default;
}
Expand All @@ -125,7 +125,7 @@ public function replace(array $attributes): void
$this->sessionContent = $attributes;
}

public function remove($name)
public function remove($name): mixed
{
$return = null;
if ($this->has($name)) {
Expand All @@ -152,7 +152,7 @@ public function registerBag(SessionBagInterface $bag): void
$this->bags[$bag->getName()] = $bag;
}

public function getBag($name)
public function getBag($name): SessionBagInterface
{
if (array_key_exists($name, $this->bags)) {
return $this->bags[$name];
Expand All @@ -161,7 +161,7 @@ public function getBag($name)
return null;
}

public function getMetadataBag()
public function getMetadataBag(): MetadataBag
{
if (isset($this->bags['_sf_meta'])) {
return $this->bags['_sf_meta'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public function getPageTitle(): string
private function getTranslation(array $translations): mixed
{
$currentLocale = $this->requestStack->getCurrentRequest()->getLocale();
if (is_null($currentLocale)) {
throw new LogicException('The current language is not set');
}

if (isset($translations[$currentLocale])) {
return $translations[$currentLocale];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public function view_config_translates_correctly()
*/
public function translation_fails_when_no_current_language_set()
{
$this->expectExceptionMessage("The current language is not set");
$this->expectExceptionMessage("The requested translation is not available in this language");
$this->expectException(LogicException::class);

$viewConfig = $this->buildViewConfig(null);
$viewConfig = $this->buildViewConfig('');
$viewConfig->getExplanation();
}

Expand All @@ -78,7 +78,7 @@ public function view_config_cannot_serve_french_translations()
$viewConfig->getGssfIdMismatch();
}

private function buildViewConfig(?string $locale = ''): ViewConfig
private function buildViewConfig(string $locale = ''): ViewConfig
{
$request = m::mock(RequestStack::class);
$request->shouldReceive('getCurrentRequest->getLocale')->andReturn($locale)->byDefault();
Expand Down

0 comments on commit b044832

Please sign in to comment.