Skip to content

Commit 9d924a9

Browse files
test(CertificateAuthority): ensure CAs can't be deleted while in use #856
1 parent 07bdfa1 commit 9d924a9

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

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

Lines changed: 26 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,30 @@ 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+
{
136+
# Create a CA to test with
137+
$ca = new CertificateAuthority(
138+
descr: 'test',
139+
crt: self::EXAMPLE_CRT,
140+
prv: self::EXAMPLE_PRV,
141+
);
142+
$ca->create();
143+
144+
# Mock an OpenVPN server using this CA to be in use
145+
Model::set_config(path: "openvpn/openvpn-server/0/caref", value: $ca->refid->value);
146+
147+
# Ensure an error is thrown if we try to delete the CA while it's in use
148+
$this->assert_throws_response(
149+
response_id: 'CERTIFICATE_AUTHORITY_CANNOT_BE_DELETED_WHILE_IN_USE',
150+
code: 409,
151+
callable: function () use ($ca) {
152+
$ca->delete();
153+
},
154+
);
155+
}
131156
# TODO: Need test to ensure crt must be CA capable
132157
}

0 commit comments

Comments
 (0)