File tree Expand file tree Collapse file tree
pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI Expand file tree Collapse file tree Original file line number Diff line number Diff 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
3030command is included below for quick reference:
3131
3232``` bash
Original file line number Diff line number Diff 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 ) {
Original file line number Diff line number Diff line change 33namespace RESTAPI \Tests ;
44
55use ReflectionClass ;
6- use ReflectionException ;
76use RESTAPI ;
87use RESTAPI \Caches \RESTAPIVersionReleasesCache ;
8+ use RESTAPI \Core \Auth ;
99use RESTAPI \Core \Model ;
1010use RESTAPI \Models \FirewallAlias ;
1111use 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}
You can’t perform that action at this time.
0 commit comments