Skip to content

Commit 6328750

Browse files
Merge pull request #513 from jaredhendrickson13/next_patch
2 parents b21981d + cc7e15b commit 6328750

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ provide you with the information you need to configure and use the package effec
2626

2727
## Quickstart
2828

29-
For new users, it is recommended to refer to the links in the [Getting Started section](#getting-started) to begin. Otherwise, the install
29+
For new users, it is recommended to refer to the links in the [Getting Started section](#getting-started) to begin. Otherwise, the install
3030
command is included below for quick reference:
3131

3232
```bash

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Model.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,11 @@ class Model {
626626
file_put_contents($lock_file, microtime());
627627

628628
# Start a temporary session to write the config that contains the user's username in the config history
629+
session_start();
629630
$_SESSION['Username'] = $this->client->username;
631+
$_SERVER['REMOTE_ADDR'] = $this->client->ip_address;
630632
write_config(sprintf(gettext(' ' . $change_note)));
633+
session_destroy();
631634

632635
# If a subsystem is specified for this Model, mark it as dirty
633636
if ($this->subsystem) {

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

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

55
use ReflectionClass;
6-
use ReflectionException;
76
use RESTAPI;
87
use RESTAPI\Caches\RESTAPIVersionReleasesCache;
8+
use RESTAPI\Core\Auth;
99
use RESTAPI\Core\Model;
1010
use RESTAPI\Models\FirewallAlias;
1111
use RESTAPI\Models\SystemStatus;
@@ -744,4 +744,24 @@ class APICoreModelTestCase extends RESTAPI\Core\TestCase {
744744
$this->assert_equals($alias->address->value, []);
745745
$this->assert_equals($alias->detail->value, []);
746746
}
747+
748+
/**
749+
* Ensures the authenticated username is properly retained whenever running Model::write_config() (#512)
750+
*/
751+
public function test_write_config_retains_authenticated_username(): void {
752+
# Authenticate a user
753+
$client = new Auth();
754+
$client->username = 'test_user';
755+
$client->ip_address = '1.2.3.4';
756+
757+
# Create a new alias with the authenticated user
758+
$alias = new FirewallAlias(name: 'test_alias', type: 'host', client: $client);
759+
$alias->create();
760+
761+
# Ensure the 'revision' section of the config contains the authenticated username
762+
$this->assert_equals($alias->get_config('revision/username'), 'test_user@1.2.3.4');
763+
764+
# Delete the alias
765+
$alias->delete();
766+
}
747767
}

0 commit comments

Comments
 (0)