Skip to content

Commit

Permalink
Merge pull request #513 from jaredhendrickson13/next_patch
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhendrickson13 authored Jul 18, 2024
2 parents b21981d + cc7e15b commit 6328750
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ provide you with the information you need to configure and use the package effec

## Quickstart

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

```bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,11 @@ class Model {
file_put_contents($lock_file, microtime());

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

# If a subsystem is specified for this Model, mark it as dirty
if ($this->subsystem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace RESTAPI\Tests;

use ReflectionClass;
use ReflectionException;
use RESTAPI;
use RESTAPI\Caches\RESTAPIVersionReleasesCache;
use RESTAPI\Core\Auth;
use RESTAPI\Core\Model;
use RESTAPI\Models\FirewallAlias;
use RESTAPI\Models\SystemStatus;
Expand Down Expand Up @@ -744,4 +744,24 @@ class APICoreModelTestCase extends RESTAPI\Core\TestCase {
$this->assert_equals($alias->address->value, []);
$this->assert_equals($alias->detail->value, []);
}

/**
* Ensures the authenticated username is properly retained whenever running Model::write_config() (#512)
*/
public function test_write_config_retains_authenticated_username(): void {
# Authenticate a user
$client = new Auth();
$client->username = 'test_user';
$client->ip_address = '1.2.3.4';

# Create a new alias with the authenticated user
$alias = new FirewallAlias(name: 'test_alias', type: 'host', client: $client);
$alias->create();

# Ensure the 'revision' section of the config contains the authenticated username
$this->assert_equals($alias->get_config('revision/username'), '[email protected]');

# Delete the alias
$alias->delete();
}
}

0 comments on commit 6328750

Please sign in to comment.