Skip to content

Commit f35530b

Browse files
Merge pull request #859 from pfrest/next_patch
v2.7.4 Fixes & Features
2 parents bb6c154 + 3308b44 commit f35530b

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ class ACMECertificateDomain extends Model {
305305
public StringField $zone_username;
306306
public StringField $zone_key;
307307
public StringField $zilore_key;
308+
public StringField $technitium_server;
309+
public StringField $technitium_token;
308310
public StringField $anydnschallengealias;
309311
public BooleanField $anydnschallengedomain;
310312

@@ -2524,6 +2526,21 @@ class ACMECertificateDomain extends Model {
25242526
conditions: ['method' => 'dns_zilore'],
25252527
help_text: 'Zilore API Key',
25262528
);
2529+
$this->technitium_server = new StringField(
2530+
default: '',
2531+
allow_empty: true,
2532+
internal_name: 'dns_technitiumtechnitium_server',
2533+
conditions: ['method' => 'dns_technitium'],
2534+
help_text: 'Technitium DNS Server address',
2535+
);
2536+
$this->technitium_token = new StringField(
2537+
default: '',
2538+
allow_empty: true,
2539+
sensitive: true,
2540+
internal_name: 'dns_technitiumtechnitium_token',
2541+
conditions: ['method' => 'dns_technitium'],
2542+
help_text: 'Technitium DNS Server API Token',
2543+
);
25272544
$this->anydnschallengealias = new StringField(
25282545
default: '',
25292546
allow_empty: true,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use RESTAPI\Fields\BooleanField;
88
use RESTAPI\Fields\IntegerField;
99
use RESTAPI\Fields\StringField;
1010
use RESTAPI\Fields\UIDField;
11+
use RESTAPI\Responses\ConflictError;
1112
use RESTAPI\Responses\ForbiddenError;
1213
use RESTAPI\Responses\ValidationError;
1314
use RESTAPI\Validators\RegexValidator;
@@ -115,8 +116,8 @@ class CertificateAuthority extends Model {
115116
*/
116117
public function _delete(): void {
117118
# Do not allow this CertificateAuthority to be deleted if it is in use
118-
if (cert_in_use($this->refid->value)) {
119-
throw new ForbiddenError(
119+
if (ca_in_use($this->refid->value)) {
120+
throw new ConflictError(
120121
message: 'Certificate authority cannot be deleted because it is in use.',
121122
response_id: 'CERTIFICATE_AUTHORITY_CANNOT_BE_DELETED_WHILE_IN_USE',
122123
);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ class CertificateRevocationList extends Model {
4040
$this->descr = new StringField(
4141
required: true,
4242
unique: true,
43-
editable: false,
4443
validators: [new RegexValidator(pattern: "/[\?\>\<\&\/\\\"\']/", invert: true)],
4544
help_text: 'The unique name/description for this CRL.',
4645
);
@@ -59,15 +58,13 @@ class CertificateRevocationList extends Model {
5958
);
6059
$this->lifetime = new IntegerField(
6160
default: 730,
62-
editable: false,
6361
minimum: 1,
6462
maximum: 8381,
6563
conditions: ['method' => 'internal'],
6664
help_text: 'The lifetime of this CRL in days.',
6765
);
6866
$this->serial = new IntegerField(
6967
default: 0,
70-
editable: false,
7168
conditions: ['method' => 'internal'],
7269
help_text: 'The serial number of the CRL.',
7370
);

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace RESTAPI\Tests;
44

55
use RESTAPI\Core\Command;
6+
use RESTAPI\Core\Model;
67
use RESTAPI\Core\TestCase;
78
use RESTAPI\Models\CertificateAuthority;
89

@@ -127,6 +128,25 @@ R02Pul8ulWQ8Kl3Q3pou8As7W1mMzA2DxQ==
127128
$ca->delete();
128129
}
129130

130-
# TODO: Need test to ensure CA cannot be deleted while in use
131+
/**
132+
* Checks that we cannot delete a CA that is in use.
133+
*/
134+
public function test_cannot_delete_ca_in_use(): void {
135+
# Create a CA to test with
136+
$ca = new CertificateAuthority(descr: 'test', crt: self::EXAMPLE_CRT, prv: self::EXAMPLE_PRV);
137+
$ca->create();
138+
139+
# Mock an OpenVPN server using this CA to be in use
140+
Model::set_config(path: 'openvpn/openvpn-server/0/caref', value: $ca->refid->value);
141+
142+
# Ensure an error is thrown if we try to delete the CA while it's in use
143+
$this->assert_throws_response(
144+
response_id: 'CERTIFICATE_AUTHORITY_CANNOT_BE_DELETED_WHILE_IN_USE',
145+
code: 409,
146+
callable: function () use ($ca) {
147+
$ca->delete();
148+
},
149+
);
150+
}
131151
# TODO: Need test to ensure crt must be CA capable
132152
}

0 commit comments

Comments
 (0)