Skip to content

Commit 6e625ef

Browse files
Merge pull request #172 from jaredhendrickson13/v140
v1.4.0 Features & Fixes
2 parents 019e66a + d0d3685 commit 6e625ef

182 files changed

Lines changed: 17813 additions & 24291 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.idea
2-
tests/unit_test_framework/__pycache__/
2+
tests/e2e_test_framework/__pycache__/
33
*.DS_Store
44
.phplint-cache
5-
5+
*.pyc

README.md

Lines changed: 606 additions & 8316 deletions
Large diffs are not rendered by default.

docs/CONTRIBUTING.md

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ If you plan on contributing, please follow these basic requirements
1414

1515
Testing
1616
-------
17-
It is preferred that any API endpoints or core features of this package include unit tests at the time they are written.
17+
It is preferred that any API endpoints or core features of this package include E2E tests at the time they are written.
1818
This will help speed up pull requests, and assist in future regression testing. For example, if you write a new API
19-
endpoint please include a unit test that will thoroughly test the extent of that endpoint. Python3 is the preferred
20-
language for unit tests. Seeing as changes will primarily be to API endpoints, please consider Python3's `requests`
19+
endpoint please include a E2E test that will thoroughly test the extent of that endpoint. Python3 is the preferred
20+
language for E2E tests. Seeing as changes will primarily be to API endpoints, please consider Python3's `requests`
2121
module.
2222

2323
Proposing Changes
@@ -92,6 +92,13 @@ utilizes the same permissions as the pfSense webConfigurator. Specify the privil
9292
format. Defaults to `["page-all"]` which requires client to have the 'WebCfg - All Pages' permission. A list of pfSense
9393
privileges can be found here: https://github.com/pfsense/pfsense/blob/master/src/etc/inc/priv.defs.inc
9494

95+
- `$this->packages` : Allows you to specify any add-on packages required for the model to operate. This must use the
96+
full pfSense package name (including `pfSense-pkg-`). All packages must be present on the system in order for the API
97+
model to operate. If any packages are missing, the API will return a 500 error. Defaults to `[]`.
98+
99+
- `$this->package_includes` : Allows you to specify additional PHP files to include for add-on packages. These files
100+
will only attempt to be included if ALL packages specified in `$this->packages` are present. Defaults to `[]`.
101+
95102
- `$this->requires_auth` : Specify whether authentication and authorization is required for the API model. If set to
96103
`false` clients will not have to authenticate or have privilege to access. Defaults to `true`.
97104

@@ -360,26 +367,26 @@ Often times you will need to create functions to condense redundant tasks. You c
360367
`$some_variable = APITools\your_custom_tool_function();`
361368

362369

363-
## Writing API Unit Tests ##
364-
Unit tests are written using Python3. pfSense API includes a an unit_test_framework module in the `tests` directory to make
365-
this process simple. Unit tests help to ensure each endpoint remains functional when changes have been made.
370+
## Writing API E2E Tests ##
371+
E2E tests are written using Python3. pfSense API includes a an e2e_test_framework module in the `tests` directory to make
372+
this process simple. E2E tests help to ensure each endpoint remains functional when changes have been made.
366373

367374
#### Getting Started ####
368-
To get started creating a new API unit test, you first need to create a new Python3 file in `/tests`. This file must
375+
To get started creating a new API E2E test, you first need to create a new Python3 file in `/tests`. This file must
369376
start with `test` and end with `.py` to be included in the `run_all_tests.py` script. Once you have created this file,
370-
you must create a new class that extends our APIUnitTest framework class:
377+
you must create a new class that extends our APIE2ETest framework class:
371378

372379
```python
373-
import unit_test_framework
380+
import e2e_test_framework
374381

375-
class NewAPIUnitTest(unit_test_framework.APIUnitTest):
382+
class NewAPIE2ETest(e2e_test_framework.APIE2ETest):
376383
# ...
377384
```
378385

379386
#### Overriding Base Model Properties ####
380-
The APIUnitTest class requires you to override a some properties to function correctly:
387+
The APIE2ETest class requires you to override a some properties to function correctly:
381388

382-
- `url` : A string specifying the URL this unit test will be testing
389+
- `url` : A string specifying the URL this E2E test will be testing
383390
- `time_delay` : An integer specifying how many seconds should be waited between requests. Defaults to `1`.
384391
- `get_tests` : A list of dictionary formatted test parameters for GET requests. If this endpoint does not support
385392
GET requests, you do not need to override this property. If this endpoint does support GET request, but does not require
@@ -438,7 +445,7 @@ included.
438445
included.
439446

440447
#### Other Base Model Properties
441-
The APIUnitTest class also contains a few properties that are not intended to be overridden:
448+
The APIE2ETest class also contains a few properties that are not intended to be overridden:
442449

443450
- `uid` : a unique ID that can be used for payload fields that required a unique value
444451

@@ -456,14 +463,14 @@ overridden:
456463
- `pre_delete()` : Runs before the DELETE request is made.
457464
- `post_delete()` : Runs after the DELETE request is made.
458465

459-
#### Running Unit Tests ####
460-
Once you have written your unit test class, you must ensure you create the unit test object at the end of the file
466+
#### Running E2E Tests ####
467+
Once you have written your E2E test class, you must ensure you create the E2E test object at the end of the file
461468
you've created like so:
462469

463470
```python
464-
import unit_test_framework
471+
import e2e_test_framework
465472

466-
class NewAPIUnitTest(unit_test_framework.APIUnitTest):
473+
class NewAPIE2ETest(e2e_test_framework.APIE2ETest):
467474
url = "/api/v1/your_endpoint"
468475
get_requests = [{}]
469476
post_requests = [
@@ -512,16 +519,16 @@ class NewAPIUnitTest(unit_test_framework.APIUnitTest):
512519
},
513520
]
514521

515-
NewAPIUnitTest()
522+
NewAPIE2ETest()
516523
```
517524

518-
Once this is done, you can run the unit test via command line by running:<br>
519-
`python3 test/test_your_unit_test_framework.py --host <ENTER PFSENSE IP/HOSTNAME HERE>`
525+
Once this is done, you can run the E2E test via command line by running:<br>
526+
`python3 test/test_your_e2e_test_framework.py --host <ENTER PFSENSE IP/HOSTNAME HERE>`
520527

521-
Or you may run all the unit tests by running:<br>
528+
Or you may run all the E2E tests by running:<br>
522529
`python3 test/run_all_tests.py`
523530

524-
Unit tests will check API responses for the following:
531+
E2E tests will check API responses for the following:
525532
- Ability to connect to API endpoint
526533
- API responses properly return data in a JSON format
527534
- API responses include the correct HTTP status code
@@ -536,12 +543,10 @@ directories needed to build our package from the `files` directory. For more inf
536543
to `tools/README.md`
537544

538545
## Creating or Updating Documentation ##
539-
Documentation is written and maintained using Postman. The JSON export of the Postman collection can be found in
540-
`tools/templates/documentation.json`. Both the README.md and embedded documentation are generated using this JSON file. To update
541-
or add documentation, you can either import this collection to Postman, make your changes in Postman and then export the
542-
updated collection as JSON, or you may edit the JSON file directly if you are familiar with the structure. To generate
543-
the README.md and embedded documentation pages, you may use the `tools/make_documentation.py` script. For more info on
544-
running the script, refer to `tools/README.md`
546+
Documentation is written using Swagger/OpenAPIv3. The OpenAPI configuration can be found at
547+
`pfSense-pkg-API/files/usr/local/www/api/documentation/openapi.yml`. Whenever new functionality is added or updated,
548+
the OpenAPI configuration must also be updated to reflect the changes. The OpenAPI configuration
549+
must be in OpenAPIv3 spec at all times.
545550

546551
Questions
547552
---------

docs/SECURITY.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
Below are versions that are currently supported and will receive security updates when available.
66

77
| Version | Supported |
8-
| ------- | ------------------ |
8+
|---------| ------------------ |
9+
| 1.4.x | :white_check_mark: |
910
| 1.3.x | :white_check_mark: |
10-
| 1.2.x | :white_check_mark: |
11-
| 1.1.x | :x: |
11+
| 1.2.x | :x: |
1212

1313
## Reporting a Vulnerability
1414

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
// Copyright 2022 Jared Hendrickson
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once("api/framework/APIEndpoint.inc");
17+
18+
class APIFirewallRuleSort extends APIEndpoint {
19+
public function __construct() {
20+
$this->url = "/api/v1/firewall/rule/sort";
21+
}
22+
23+
protected function put() {
24+
return (new APIFirewallRuleSortUpdate())->call();
25+
}
26+
27+
}

pfSense-pkg-API/files/etc/inc/api/endpoints/APIFirewallStates.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ class APIFirewallStates extends APIEndpoint {
2323
protected function get() {
2424
return (new APIFirewallStatesRead())->call();
2525
}
26+
27+
protected function delete() {
28+
return (new APIFirewallStatesDelete())->call();
29+
}
2630
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
// Copyright 2022 Jared Hendrickson
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once("api/framework/APIEndpoint.inc");
17+
18+
class APIServicesDHCPdOptions extends APIEndpoint {
19+
public function __construct() {
20+
$this->url = "/api/v1/services/dhcpd/options";
21+
}
22+
23+
protected function post() {
24+
return (new APIServicesDHCPdOptionsCreate())->call();
25+
}
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// Copyright 2021 Jared Hendrickson
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once("api/framework/APIEndpoint.inc");
17+
18+
class APISystemCRL extends APIEndpoint {
19+
public function __construct() {
20+
$this->url = "/api/v1/system/crl";
21+
}
22+
23+
protected function get() {
24+
return (new APISystemCRLRead())->call();
25+
}
26+
27+
protected function post() {
28+
return (new APISystemCRLCreate())->call();
29+
}
30+
31+
protected function delete() {
32+
return (new APISystemCRLDelete())->call();
33+
}
34+
}

pfSense-pkg-API/files/etc/inc/api/endpoints/APISystemCertificate.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class APISystemCertificate extends APIEndpoint {
2828
return (new APISystemCertificateCreate())->call();
2929
}
3030

31+
protected function put() {
32+
return (new APISystemCertificateUpdate())->call();
33+
}
34+
3135
protected function delete() {
3236
return (new APISystemCertificateDelete())->call();
3337
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
// Copyright 2022 Jared Hendrickson
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once("api/framework/APIEndpoint.inc");
17+
18+
class APISystemPackage extends APIEndpoint {
19+
public function __construct() {
20+
$this->url = "/api/v1/system/package";
21+
$this->query_excludes = ["all"];
22+
}
23+
24+
protected function get() {
25+
return (new APISystemPackageRead())->call();
26+
}
27+
28+
protected function post() {
29+
return (new APISystemPackageCreate())->call();
30+
}
31+
32+
protected function delete() {
33+
return (new APISystemPackageDelete())->call();
34+
}
35+
}

0 commit comments

Comments
 (0)