Skip to content

Commit 4ff3f2f

Browse files
Merge pull request #865 from pfrest/next_patch
2 parents 5840104 + 5e47b43 commit 4ff3f2f

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/CertificateRevocationListRevokedCertificate.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ class CertificateRevocationListRevokedCertificate extends Model {
117117
}
118118
}
119119

120+
/**
121+
* Adds extra processing when loading internal objects for this model. This is primarily used to catch any value
122+
* that is not using the expected reason codes and convert them to a -1 (unspecified) reason code.
123+
*/
124+
public function from_internal_object(mixed $internal_object): void {
125+
# If the reason code is not a number, convert it to -1 (unspecified)
126+
if (!is_numeric($internal_object['reason'])) {
127+
$internal_object['reason'] = -1;
128+
}
129+
130+
parent::from_internal_object($internal_object);
131+
}
132+
120133
/**
121134
* Applies the newly created CRL by reloading the OpenVPN and IPsec services.
122135
*/

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/Service.inc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Service extends Model {
3030
write_only: true,
3131
help_text: 'The action to perform against this service.',
3232
);
33-
$this->name = new StringField(unique: true, read_only: true, help_text: 'The internal name of the service.');
33+
$this->name = new StringField(required: true, unique: true, help_text: 'The internal name of the service.');
3434
$this->description = new StringField(read_only: true, help_text: 'The full descriptive name of the service.');
3535
$this->enabled = new BooleanField(
3636
read_only: true,
@@ -54,7 +54,15 @@ class Service extends Model {
5454
* @return array An array of available pfSense services and their current statuses.
5555
*/
5656
public static function get_services(): array {
57-
return get_services();
57+
$services = get_services();
58+
59+
# For each service, determine if it's really enabled and running
60+
foreach ($services as $key => $service) {
61+
$services[$key]['enabled'] = is_service_enabled($service['name']);
62+
$services[$key]['status'] = get_service_status($service);
63+
}
64+
65+
return $services;
5866
}
5967

6068
/**

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,23 @@ class APIModelsCertificateRevocationListRevokedCertificateTestCase extends TestC
130130
},
131131
);
132132
}
133+
134+
/**
135+
* Ensures revoked certificates with non-numeric reasons are converted to -1 (unspecified) when reading #864
136+
*/
137+
public function test_non_numeric_reason_conversion(): void {
138+
# Mock a revoked certificate with a non-numeric reason
139+
Model::set_config("crl/{$this->crl->id}/cert/0", [
140+
'certref' => $this->cert->refid->value,
141+
'reason' => 'some-non-numeric-reason',
142+
'revoke_time' => time(),
143+
]);
144+
145+
# Read the CRL and ensure the reason was converted to -1
146+
$crl_revoked_cert = CertificateRevocationListRevokedCertificate::query(
147+
parent_id: $this->crl->id,
148+
id: 0,
149+
)->first();
150+
$this->assert_equals(-1, $crl_revoked_cert->reason->value);
151+
}
133152
}

0 commit comments

Comments
 (0)