File tree Expand file tree Collapse file tree
pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33namespace RESTAPI \Tests ;
44
55use RESTAPI \Core \Command ;
6+ use RESTAPI \Core \Model ;
67use RESTAPI \Core \TestCase ;
78use 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}
You can’t perform that action at this time.
0 commit comments