Skip to content

Commit 19f3292

Browse files
test(IPsecPhase2Encryption): replace references to old get_supported_keylens
1 parent 187cc93 commit 19f3292

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsIPsecPhase2EncryptionTestCase.inc

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ use RESTAPI\Models\IPsecPhase2Encryption;
99
class APIModelsIPsecPhase2EncryptionTestCase extends TestCase {
1010
# NOTE: This model is partially tested by /RESTAPI/Tests/APIModelsIPsecPhase2TestCase
1111

12-
/**
13-
* Checks that the `keylen` field is a KeyLenField instance.
14-
*/
15-
public function test_keylen_field_type(): void {
16-
$p2 = new IPsecPhase2Encryption();
17-
$this->assert_is_true($p2->keylen instanceof KeyLenField);
18-
}
19-
2012
/**
2113
* Checks that the `keylen` field uses `get_supported_keylens` as its choices callable.
2214
*/
@@ -31,7 +23,9 @@ class APIModelsIPsecPhase2EncryptionTestCase extends TestCase {
3123
*/
3224
public function test_keylen_choices(): void {
3325
# Ensure that `get_supported_keylens` returns only valid key lengths for 'aes'
34-
$supported = IPsecPhase2Encryption::get_supported_keylens('aes');
26+
$p2e = new IPsecPhase2Encryption(name: 'aes');
27+
$supported = $p2e->get_supported_keylens();
28+
3529
$this->assert_is_true(in_array(128, $supported, true));
3630
$this->assert_is_true(in_array(256, $supported, true));
3731
$this->assert_is_false(in_array(257, $supported, true));
@@ -48,8 +42,8 @@ class APIModelsIPsecPhase2EncryptionTestCase extends TestCase {
4842
# Ensure an error is not thrown if `get_supported_keylens()` receives a valid `name`
4943
$this->assert_does_not_throw(
5044
callable: function () {
51-
$keylen_enabled_algo = IPsecPhase2Encryption::get_keylen_enabled_algos()[0];
52-
IPsecPhase2Encryption::get_supported_keylens(name: $keylen_enabled_algo);
45+
$p2e = new IPsecPhase2Encryption(name: 'aes');
46+
$p2e->get_supported_keylens();
5347
},
5448
);
5549

@@ -58,7 +52,8 @@ class APIModelsIPsecPhase2EncryptionTestCase extends TestCase {
5852
response_id: 'IPSEC_PHASE_2_ENCRYPTION_COULD_NOT_GET_KEYLENS_FOR_UNKNOWN_ALGO',
5953
code: 400,
6054
callable: function () {
61-
IPsecPhase2Encryption::get_supported_keylens(name: 'not a valid encryption algorithm');
55+
$p2e = new IPsecPhase2Encryption(name: 'not a valid encryption algorithm');
56+
$p2e->get_supported_keylens();
6257
},
6358
);
6459
}
@@ -70,10 +65,19 @@ class APIModelsIPsecPhase2EncryptionTestCase extends TestCase {
7065
public function test_get_supported_keylens(): void {
7166
global $p2_ealgos;
7267

68+
$p2e = new IPsecPhase2Encryption();
69+
7370
# Loop each encryption algorithm that supported variable key lengths
7471
foreach (IPsecPhase2Encryption::get_keylen_enabled_algos() as $algo) {
72+
$p2e->name->value = $algo;
73+
7574
# Loop through each key length option available to this algorithm and ensure it meets the correct parameters
76-
foreach (IPsecPhase2Encryption::get_supported_keylens(name: $algo) as $keylen) {
75+
foreach ($p2e->get_supported_keylens() as $keylen) {
76+
# Skip 0 as it's always considered valid
77+
if ($keylen === 0) {
78+
continue;
79+
}
80+
7781
# Obtain the parameters for supported key lengths
7882
$min_keylen = $p2_ealgos[$algo]['keysel']['lo'];
7983
$max_keylen = $p2_ealgos[$algo]['keysel']['hi'];

0 commit comments

Comments
 (0)