Skip to content

Commit feab5b3

Browse files
committed
Run only failing sso-on-2fa test
1 parent 0125b5b commit feab5b3

File tree

7 files changed

+45
-12
lines changed

7 files changed

+45
-12
lines changed

.github/workflows/test-integration.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ jobs:
2626
- name: Run CI tests
2727
run: |
2828
cd ci/docker && docker compose exec -T gateway bash -c '
29-
ls -lah /var/www/html/var/cache && \
30-
ls -lah /var/www/html/var/cache/smoketest && \
3129
composer check
3230
'
3331

src/Surfnet/StepupGateway/GatewayBundle/Entity/InstitutionConfiguration.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ class InstitutionConfiguration
3939
*/
4040
public $ssoOn2faEnabled;
4141

42-
private function __construct(string $institution, bool $ssoOn2faEnabled)
42+
/**
43+
* * @ORM\Column(type="boolean")
44+
*
45+
* @var bool is the SSO registration bypass feature enabled?
46+
*/
47+
public bool $ssoRegistrationBypass;
48+
49+
private function __construct(string $institution, bool $ssoOn2faEnabled, bool $ssoRegistrationBypass)
4350
{
4451
$this->institution = $institution;
4552
$this->ssoOn2faEnabled = $ssoOn2faEnabled;
53+
$this->ssoRegistrationBypass = $ssoRegistrationBypass;
4654
}
4755
}

src/Surfnet/StepupGateway/GatewayBundle/Sso2fa/ValueObject/CookieValue.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace Surfnet\StepupGateway\GatewayBundle\Sso2fa\ValueObject;
2020

2121
use DateTime;
22+
use Surfnet\StepupGateway\GatewayBundle\Sso2fa\Exception\InvalidAuthenticationTimeException;
2223
use function strtolower;
2324
use function strtotime;
2425

@@ -43,7 +44,7 @@ public static function from(string $identityId, string $secondFactorId, float $l
4344
$cookieValue->identityId = $identityId;
4445
$cookieValue->loa = $loa;
4546
$dateTime = new DateTime();
46-
$cookieValue->authenticationTime = $dateTime->format(DATE_ATOM);
47+
$cookieValue->authenticationTime = $dateTime->format(DATE_RFC3339_EXTENDED);
4748
return $cookieValue;
4849
}
4950

@@ -96,6 +97,13 @@ public function issuedTo(string $identityNameId): bool
9697

9798
public function authenticationTime(): int
9899
{
99-
return strtotime($this->authenticationTime);
100+
$dateTime = DateTime::createFromFormat(DATE_RFC3339_EXTENDED, $this->authenticationTime);
101+
if (!$dateTime) {
102+
$dateTime = DateTime::createFromFormat(DATE_RFC3339, $this->authenticationTime);
103+
}
104+
if (!$dateTime) {
105+
throw new InvalidAuthenticationTimeException();
106+
}
107+
return $dateTime->getTimestamp();
100108
}
101109
}

src/Surfnet/StepupGateway/GatewayBundle/Tests/Sso2fa/DateTime/ExpirationHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private function makeCookieValue(int $authenticationTime) : CookieValueInterface
106106
'tokenId' => 'tokenId',
107107
'identityId' => 'identityId',
108108
'loa' => 2.0,
109-
'authenticationTime' => $dateTime->format(DATE_ATOM),
109+
'authenticationTime' => $dateTime->format(DATE_RFC3339_EXTENDED),
110110
];
111111
return CookieValue::deserialize(json_encode($data));
112112
}

src/Surfnet/StepupGateway/GatewayBundle/Tests/Sso2fa/ValueObject/CookieValueTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function test_serialize(): void
3939
self::assertIsString($serialized);
4040
}
4141

42-
public function test_deserialization(): void
42+
public function test_serialize_and_deserialization(): void
4343
{
4444
$secondFactor = Mockery::mock(SecondFactor::class);
4545
$secondFactor->secondFactorId = 'abcdef-1234';
@@ -51,6 +51,24 @@ public function test_deserialization(): void
5151
self::assertInstanceOf(CookieValue::class, $cookieValue);
5252
}
5353

54+
55+
public function test_deserialization_authentication_time_without_millis(): void
56+
{
57+
$serialized = '{"tokenId":"abcdef-1234","identityId":"abcdef-1234","loa":3,"authenticationTime":"2025-05-07T11:01:38+02:00"}';
58+
$cookieValue = CookieValue::deserialize($serialized);
59+
self::assertInstanceOf(CookieValue::class, $cookieValue);
60+
self::assertSame(1746608498, $cookieValue->authenticationTime());
61+
}
62+
63+
public function test_deserialization_authentication_time_with_millis(): void
64+
{
65+
$serialized = '{"tokenId":"abcdef-1234","identityId":"abcdef-1234","loa":3,"authenticationTime":"2025-05-07T11:01:38.457+02:00"}';
66+
$cookieValue = CookieValue::deserialize($serialized);
67+
self::assertInstanceOf(CookieValue::class, $cookieValue);
68+
self::assertSame(1746608498, $cookieValue->authenticationTime());
69+
}
70+
71+
5472
/**
5573
* @dataProvider loaProvider
5674
*/

tests/features/bootstrap/FeatureContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public function theSSO2FACookieIsRewritten(): void
376376

377377
if ($this->previousSsoOn2faCookieValue === $cookieValue) {
378378
throw new ExpectationException(
379-
'The SSO on 2FA cookie did not change since the previous response',
379+
sprintf('The SSO on 2FA cookie did not change since the previous response: "%s" !== "%s"', $this->previousSsoOn2faCookieValue, $cookieValue),
380380
$this->minkContext->getSession()->getDriver()
381381
);
382382
}

tests/src/Repository/InstitutionConfigurationRepository.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public function configure(string $institution, string $option, bool $value)
4848
$data = [
4949
'institution' => $institution,
5050
'sso_on2fa_enabled' => $value,
51+
'sso_registration_bypass' => $value,
5152
];
5253
$sql = <<<SQL
53-
INSERT INTO institution_configuration (institution, sso_on2fa_enabled)
54-
VALUES (:institution, :sso_on2fa_enabled);
54+
INSERT INTO institution_configuration (institution, sso_on2fa_enabled, sso_registration_bypass)
55+
VALUES (:institution, :sso_on2fa_enabled, :sso_registration_bypass);
5556
SQL;
5657
$stmt = $this->connection->prepare($sql);
5758
if ($stmt->execute($data)) {
@@ -70,8 +71,8 @@ public function configure(string $institution, string $option, bool $value)
7071
'value' => $value,
7172
];
7273
$sql = <<<SQL
73-
update gateway.institution_configuration
74-
set sso_on2fa_enabled = :value
74+
update institution_configuration
75+
set `$option` = :value
7576
where institution = :institution
7677
;
7778
SQL;

0 commit comments

Comments
 (0)