Skip to content

Commit 21079a1

Browse files
Merge pull request #167 from jaredhendrickson13/v132
v1.3.2 Fixes
2 parents 79b374a + 187656f commit 21079a1

File tree

9 files changed

+42
-31
lines changed

9 files changed

+42
-31
lines changed

pfSense-pkg-API/files/etc/inc/api/models/APISystemAPIVersionRead.inc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ class APISystemAPIVersionRead extends APIModel {
7777
# Variables
7878
$releases_file = "/usr/local/share/pfSense-pkg-API/releases.json";
7979
$releases = json_decode(file_get_contents($releases_file), true);
80+
$fetch_releases_cmd = "curl -s https://api.github.com/repos/jaredhendrickson13/pfsense-api/releases -m 10";
8081

8182
# Check if our previous releases data is older than 120 seconds
8283
if ($releases["last_updated"] + 120 < time()) {
8384
# Pull the releases data from Github and rewrite the releases file
84-
$api_resp = shell_exec("curl -s https://api.github.com/repos/jaredhendrickson13/pfsense-api/releases");
85+
$api_resp = shell_exec($fetch_releases_cmd);
8586
$api_resp = json_decode($api_resp, true);
8687
$releases = ["last_updated" => time(), "releases" => $api_resp];
8788
file_put_contents($releases_file, json_encode($releases));

pfSense-pkg-API/files/etc/inc/api/models/APISystemCACreate.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class APISystemCACreate extends APIModel {
168168
$this->errors[] = APIResponse\get(1035);
169169
}
170170
else {
171-
$this->validated_data["crt"] = $this->initial_data["crt"];
171+
$this->validated_data["crt"] = $crt;
172172
}
173173
}
174174

@@ -187,7 +187,7 @@ class APISystemCACreate extends APIModel {
187187
$this->errors[] = APIResponse\get(1049);
188188
}
189189
else {
190-
$this->validated_data["prv"] = $this->initial_data["prv"];
190+
$this->validated_data["prv"] = $key;
191191
}
192192
}
193193
}

pfSense-pkg-API/files/etc/inc/api/models/APIUserCreate.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ class APIUserCreate extends APIModel {
201201
public function is_user_certificate($cert_ref_id) {
202202
# Loop through all certificates and check for matches
203203
foreach ($this->config["cert"] as $cert) {
204-
# Check if this is a user certificate and that ref ID matches
205-
if ($cert["type"] === "user" and $cert["refid"] === $cert_ref_id) {
204+
# Check if this certificate matches the specified ref id
205+
if ($cert["refid"] === $cert_ref_id) {
206206
return true;
207207
}
208208
}

pfSense-pkg-API/files/etc/inc/api/models/APIUserUpdate.inc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,13 @@ class APIUserUpdate extends APIModel {
179179
public function is_user_certificate($cert_ref_id) {
180180
# Loop through all certificates and check for matches
181181
foreach ($this->config["cert"] as $cert) {
182-
# Check if this is a user certificate and that ref ID matches
183-
if ($cert["type"] === "user" and $cert["refid"] === $cert_ref_id) {
182+
# Check if this certificate matches the specified ref id
183+
if ($cert["refid"] === $cert_ref_id) {
184184
return true;
185185
}
186186
}
187187

188188
return false;
189+
189190
}
190191
}

pfSense-pkg-API/files/usr/local/www/api/documentation/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,12 +2315,12 @@
23152315
function IsJsonString(str){try{JSON.parse(str);}catch(e){return false;}
23162316
return true;}
23172317
String.prototype.replaceAll=function(replaceThis,withThis){var re=new RegExp(RegExp.quote(replaceThis),"g");return this.replace(re,withThis);};RegExp.quote=function(str){return str.replace(/([.?*+^$[\]\\(){}-])/g,"\\$1");};function syntaxHighlight(json){json=json.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,function(match){var cls='number';if(/^"/.test(match)){if(/:$/.test(match)){cls='key';}else{cls='string';}}else if(/true|false/.test(match)){cls='boolean';}else if(/null/.test(match)){cls='null';}
2318-
return '<span class="'+cls+'">'+match+'</span>';});}</script><br><br><footer class="navbar-default navbar-fixed-bottom"><div class=container-fluid><div class="span12 text-center"><span data-toggle=tooltip title="If the application help you, please feel free to give a star to the project in github. Your star inspire me to work more on open-source projects like this!">Made with <em class=love-color>&#9829;</em> by <a href=https://github.com/thedevsaddam target=_blank class=text-muted>thedevsaddam</a> | Generated at: 2021-10-04 13:17:07 by <a href=https://github.com/thedevsaddam/docgen target=_blank class=text-muted>docgen</a></span></div></div></footer>
2318+
return '<span class="'+cls+'">'+match+'</span>';});}</script><br><br><footer class="navbar-default navbar-fixed-bottom"><div class=container-fluid><div class="span12 text-center"><span data-toggle=tooltip title="If the application help you, please feel free to give a star to the project in github. Your star inspire me to work more on open-source projects like this!">Made with <em class=love-color>&#9829;</em> by <a href=https://github.com/thedevsaddam target=_blank class=text-muted>thedevsaddam</a> | Generated at: 2021-10-18 16:28:46 by <a href=https://github.com/thedevsaddam/docgen target=_blank class=text-muted>docgen</a></span></div></div></footer>
23192319
<script type="text/javascript">
23202320
$(document).ready(function() {
23212321
document.title = 'pfSense REST API Documentation';
23222322
var curr_year = new Date().getFullYear();
2323-
document.querySelector('footer').innerHTML = "<a href='/api/'>Back to pfSense</a> | <a href='https://github.com/jaredhendrickson13/pfsense-api'>View on Github</a> | <a href='https://github.com/jaredhendrickson13/pfsense-api/issues/new'>Report an Issue</a><p>Copyright &copy; " + curr_year + " - Jared Hendrickson</p>";
2323+
document.querySelector('footer').innerHTML = "<a href='/api/'>Back to pfSense</a> | <a href='https://github.com/jaredhendrickson13/pfsense-api'>View on Github</a> | <a href='https://github.com/jaredhendrickson13/pfsense-api/issues/new/choose'>Report an Issue</a><p>Copyright &copy; " + curr_year + " - Jared Hendrickson</p>";
23242324
});
23252325

23262326
</script>

pfSense-pkg-API/files/usr/local/www/api/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@
366366
$rotate_btn->setOnclick("return confirm(\"Rotating the server key will void any existng API tokens and JWTs. Proceed?\");");
367367
$form->addGlobal(new Form_Button('save', 'Save', null, 'fa-save'))->addClass('btn btn-sm btn-primary api-save-btn');
368368
(in_array($pkg_config["authmode"], ["token", "jwt"])) ? $form->addGlobal($rotate_btn) : null;
369-
$form->addGlobal(new Form_Button('report', 'Report an Issue', 'https://github.com/jaredhendrickson13/pfsense-api/issues/new', ''))->addClass('fa fa-question-circle api-report');
369+
$form->addGlobal(new Form_Button('report', 'Report an Issue', 'https://github.com/jaredhendrickson13/pfsense-api/issues/new/choose', ''))->addClass('fa fa-question-circle api-report');
370370

371371
# Display the populated configuration form
372372
print $form;

tests/test_api_v1_system_ca.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unit_test_framework
2+
import base64
23

34

45
class APIUnitTestSystemCA(unit_test_framework.APIUnitTest):
@@ -208,4 +209,25 @@ class APIUnitTestSystemCA(unit_test_framework.APIUnitTest):
208209
# TODO: add test to check that CAs in use cannot be deleted
209210
]
210211

212+
def post_post(self):
213+
# Check if this is after the first POST test
214+
if len(self.post_responses) == 1:
215+
self.is_return_crt_base64(self.post_responses[0])
216+
217+
218+
def is_return_crt_base64(self, response):
219+
"""
220+
Takes a test response and checks if the return 'crt' data field is a Base64 encoded certificate
221+
"""
222+
# Variables
223+
test_params = {"name": "Ensure cert is Base64 encoded"}
224+
crt = base64.b64decode(response["data"]["crt"])
225+
226+
# Ensure the returned Base64 decoded crt value is a certificate
227+
if "BEGIN CERTIFICATE" not in crt.decode():
228+
self.exit_code = 1
229+
print(self.__format_msg__("POST", test_params, "Returned certificate is not Base64 encoded"))
230+
else:
231+
print(self.__format_msg__("POST", test_params, "Response is valid", "ok"))
232+
211233
APIUnitTestSystemCA()

tests/test_api_v1_user.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,7 @@ class APIUnitTestUser(unit_test_framework.APIUnitTest):
154154
"password": "changeme",
155155
"cert": "INVALID"
156156
}
157-
},
158-
{
159-
"name": "Check inability to add server certificate as a user certificate",
160-
"status": 400,
161-
"return": 5041,
162-
"server_cert": True,
163-
"payload": {
164-
"username": "another_user",
165-
"password": "changeme"
166-
}
167-
},
168-
157+
}
169158
]
170159
put_tests = [
171160
{
@@ -213,9 +202,7 @@ class APIUnitTestUser(unit_test_framework.APIUnitTest):
213202
}
214203
},
215204
{
216-
"name": "Check inability to add server certificate as a user certificate",
217-
"status": 400,
218-
"return": 5041,
205+
"name": "Check ability to add server certificate as a user certificate",
219206
"server_cert": True,
220207
"payload": {
221208
"username": "new_user",
@@ -245,11 +232,6 @@ class APIUnitTestUser(unit_test_framework.APIUnitTest):
245232
"return": 1005,
246233
"payload": {"descr": "USER_CERT"}
247234
},
248-
{
249-
"name": "Delete server certificate used for testing",
250-
"uri": "/api/v1/system/certificate",
251-
"payload": {"descr": "SERVER_CERT"}
252-
},
253235
{
254236
"name": "Delete local user",
255237
"payload": {"username": "new_user"}
@@ -275,6 +257,11 @@ class APIUnitTestUser(unit_test_framework.APIUnitTest):
275257
"uri": "/api/v1/system/certificate",
276258
"payload": {"descr": "USER_CERT"}
277259
},
260+
{
261+
"name": "Delete server certificate used for testing",
262+
"uri": "/api/v1/system/certificate",
263+
"payload": {"descr": "SERVER_CERT"}
264+
},
278265
{
279266
"name": "Delete CA used for testing",
280267
"uri": "/api/v1/system/ca",

tools/make_documentation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
$(document).ready(function() {
128128
document.title = 'pfSense REST API Documentation';
129129
var curr_year = new Date().getFullYear();
130-
document.querySelector('footer').innerHTML = "<a href='/api/'>Back to pfSense</a> | <a href='https://github.com/jaredhendrickson13/pfsense-api'>View on Github</a> | <a href='https://github.com/jaredhendrickson13/pfsense-api/issues/new'>Report an Issue</a><p>Copyright &copy; " + curr_year + " - Jared Hendrickson</p>";
130+
document.querySelector('footer').innerHTML = "<a href='/api/'>Back to pfSense</a> | <a href='https://github.com/jaredhendrickson13/pfsense-api'>View on Github</a> | <a href='https://github.com/jaredhendrickson13/pfsense-api/issues/new/choose'>Report an Issue</a><p>Copyright &copy; " + curr_year + " - Jared Hendrickson</p>";
131131
});
132132
133133
</script>

0 commit comments

Comments
 (0)