Skip to content

Commit baad4e6

Browse files
committed
Add coverage
1 parent eaa09af commit baad4e6

File tree

2 files changed

+76
-8
lines changed

2 files changed

+76
-8
lines changed

config/module_oidc.php.dist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,9 +435,9 @@ $config = [
435435
* on how this works.
436436
*/
437437
// The federation (new) private key passphrase (optional).
438-
ModuleConfig::OPTION_PKI_FEDERATION_NEW_PRIVATE_KEY_PASSPHRASE => 'new-secret',
439-
ModuleConfig::OPTION_PKI_FEDERATION_NEW_PRIVATE_KEY_FILENAME => 'new_oidc_module_federation.key',
440-
ModuleConfig::OPTION_PKI_FEDERATION_NEW_CERTIFICATE_FILENAME => 'new_oidc_module_federation.crt',
438+
// ModuleConfig::OPTION_PKI_FEDERATION_NEW_PRIVATE_KEY_PASSPHRASE => 'new-secret',
439+
// ModuleConfig::OPTION_PKI_FEDERATION_NEW_PRIVATE_KEY_FILENAME => 'new_oidc_module_federation.key',
440+
// ModuleConfig::OPTION_PKI_FEDERATION_NEW_CERTIFICATE_FILENAME => 'new_oidc_module_federation.crt',
441441

442442
// Federation token signer, with given default.
443443
ModuleConfig::OPTION_FEDERATION_TOKEN_SIGNER => \Lcobucci\JWT\Signer\Rsa\Sha256::class,

tests/unit/src/Services/JsonWebKeySetServiceTest.php

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
class JsonWebKeySetServiceTest extends TestCase
3131
{
3232
private static string $pkGeneratePublic;
33+
private static string $pkGeneratePublicNew;
34+
private static string $pkGeneratePublicFederation;
35+
private static string $pkGeneratePublicFederationNew;
3336

3437
/**
3538
* @return void
@@ -42,15 +45,42 @@ public static function setUpBeforeClass(): void
4245
'private_key_bits' => 2048,
4346
'private_key_type' => OPENSSL_KEYTYPE_RSA,
4447
]);
48+
$pkGenerateNew = openssl_pkey_new([
49+
'private_key_bits' => 2048,
50+
'private_key_type' => OPENSSL_KEYTYPE_RSA,
51+
]);
52+
$pkGenerateFederation = openssl_pkey_new([
53+
'private_key_bits' => 2048,
54+
'private_key_type' => OPENSSL_KEYTYPE_RSA,
55+
]);
56+
$pkGenerateFederationNew = openssl_pkey_new([
57+
'private_key_bits' => 2048,
58+
'private_key_type' => OPENSSL_KEYTYPE_RSA,
59+
]);
4560

4661
// get the public key
4762
$pkGenerateDetails = openssl_pkey_get_details($pkGenerate);
63+
$pkGenerateDetailsNew = openssl_pkey_get_details($pkGenerateNew);
64+
$pkGenerateDetailsFederation = openssl_pkey_get_details($pkGenerateFederation);
65+
$pkGenerateDetailsFederationNew = openssl_pkey_get_details($pkGenerateFederationNew);
4866
self::$pkGeneratePublic = $pkGenerateDetails['key'];
67+
self::$pkGeneratePublicNew = $pkGenerateDetailsNew['key'];
68+
self::$pkGeneratePublicFederation = $pkGenerateDetailsFederation['key'];
69+
self::$pkGeneratePublicFederationNew = $pkGenerateDetailsFederationNew['key'];
4970

5071
file_put_contents(sys_get_temp_dir() . '/oidc_module.crt', self::$pkGeneratePublic);
72+
file_put_contents(sys_get_temp_dir() . '/new_oidc_module.crt', self::$pkGeneratePublicNew);
73+
file_put_contents(sys_get_temp_dir() . '/oidc_module_federation.crt', self::$pkGeneratePublicFederation);
74+
file_put_contents(
75+
sys_get_temp_dir() . '/new_oidc_module_federation.crt',
76+
self::$pkGeneratePublicFederationNew,
77+
);
5178

5279
Configuration::setPreLoadedConfig(
53-
Configuration::loadFromArray([]),
80+
Configuration::loadFromArray([
81+
ModuleConfig::OPTION_PKI_NEW_CERTIFICATE_FILENAME => 'new_oidc_module.crt',
82+
ModuleConfig::OPTION_PKI_FEDERATION_NEW_CERTIFICATE_FILENAME => 'new_oidc_module_federation.crt',
83+
]),
5484
ModuleConfig::DEFAULT_FILE_NAME,
5585
);
5686
}
@@ -62,27 +92,37 @@ public static function tearDownAfterClass(): void
6292
{
6393
Configuration::clearInternalState();
6494
unlink(sys_get_temp_dir() . '/oidc_module.crt');
95+
unlink(sys_get_temp_dir() . '/new_oidc_module.crt');
96+
unlink(sys_get_temp_dir() . '/oidc_module_federation.crt');
97+
unlink(sys_get_temp_dir() . '/new_oidc_module_federation.crt');
6598
}
6699

67100
/**
68101
* @return void
69102
* @throws \SimpleSAML\Error\Exception
70103
*/
71-
public function testKeys()
104+
public function testProtocolKeys()
72105
{
73106
$config = [
74107
'certdir' => sys_get_temp_dir(),
75108
];
76109
Configuration::loadFromArray($config, '', 'simplesaml');
77110

78111
$kid = FingerprintGenerator::forString(self::$pkGeneratePublic);
79-
80112
$jwk = JWKFactory::createFromKey(self::$pkGeneratePublic, null, [
81113
'kid' => $kid,
82114
'use' => 'sig',
83115
'alg' => 'RS256',
84116
]);
85-
$JWKSet = new JWKSet([$jwk]);
117+
118+
$kidNew = FingerprintGenerator::forString(self::$pkGeneratePublicNew);
119+
$jwkNew = JWKFactory::createFromKey(self::$pkGeneratePublicNew, null, [
120+
'kid' => $kidNew,
121+
'use' => 'sig',
122+
'alg' => 'RS256',
123+
]);
124+
125+
$JWKSet = new JWKSet([$jwk, $jwkNew]);
86126

87127
$jsonWebKeySetService = new JsonWebKeySetService(new ModuleConfig());
88128

@@ -92,7 +132,7 @@ public function testKeys()
92132
/**
93133
* @throws \SimpleSAML\Error\Exception
94134
*/
95-
public function testCertificationFileNotFound(): void
135+
public function testProtocolCertificateFileNotFound(): void
96136
{
97137
$this->expectException(Exception::class);
98138
$this->expectExceptionMessageMatches('/OIDC protocol public key file does not exists/');
@@ -104,4 +144,32 @@ public function testCertificationFileNotFound(): void
104144

105145
new JsonWebKeySetService(new ModuleConfig());
106146
}
147+
148+
public function testFederationKeys(): void
149+
{
150+
$config = [
151+
'certdir' => sys_get_temp_dir(),
152+
];
153+
Configuration::loadFromArray($config, '', 'simplesaml');
154+
155+
$kid = FingerprintGenerator::forString(self::$pkGeneratePublicFederation);
156+
$jwk = JWKFactory::createFromKey(self::$pkGeneratePublicFederation, null, [
157+
'kid' => $kid,
158+
'use' => 'sig',
159+
'alg' => 'RS256',
160+
]);
161+
162+
$kidNew = FingerprintGenerator::forString(self::$pkGeneratePublicFederationNew);
163+
$jwkNew = JWKFactory::createFromKey(self::$pkGeneratePublicFederationNew, null, [
164+
'kid' => $kidNew,
165+
'use' => 'sig',
166+
'alg' => 'RS256',
167+
]);
168+
169+
$JWKSet = new JWKSet([$jwk, $jwkNew]);
170+
171+
$jsonWebKeySetService = new JsonWebKeySetService(new ModuleConfig());
172+
173+
$this->assertEquals($JWKSet->all(), $jsonWebKeySetService->federationKeys());
174+
}
107175
}

0 commit comments

Comments
 (0)