]> BookStack Code Mirror - bookstack/commitdiff
Fixed social auth login audit log messages
authorDan Brown <redacted>
Wed, 15 Sep 2021 19:55:10 +0000 (20:55 +0100)
committerDan Brown <redacted>
Wed, 15 Sep 2021 19:55:10 +0000 (20:55 +0100)
Was logging the whole social account instance instead of just the
method.
Updated tests to cover.

Fixes #2930

app/Auth/Access/SocialAuthService.php
tests/Auth/SocialAuthTest.php
tests/TestCase.php

index 8cf243fe78eafa6aeedd0b2694bdbb42ff7cf690..d165e76b121bbe2b6f5064c1b844906272d04f99 100644 (file)
@@ -141,7 +141,7 @@ class SocialAuthService
         // When a user is not logged in and a matching SocialAccount exists,
         // Simply log the user into the application.
         if (!$isLoggedIn && $socialAccount !== null) {
-            $this->loginService->login($socialAccount->user, $socialAccount);
+            $this->loginService->login($socialAccount->user, $socialDriver);
 
             return redirect()->intended('/');
         }
index 5818cbb742bbe57c68292fef25ed59f0deacc473..44b9e4ce1ce94425654887ae404b80d8e9ec2644 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace Tests\Auth;
 
+use BookStack\Actions\ActivityType;
 use BookStack\Auth\SocialAccount;
 use BookStack\Auth\User;
 use DB;
@@ -82,6 +83,7 @@ class SocialAuthTest extends TestCase
         ]);
         $resp = $this->followingRedirects()->get('/login/service/github/callback');
         $resp->assertDontSee('login-form');
+        $this->assertActivityExists(ActivityType::AUTH_LOGIN, null, 'github; (' . $this->getAdmin()->id . ') ' . $this->getAdmin()->name);
     }
 
     public function test_social_account_detach()
index 080515173d67cdd6cdf3605dc9e66c7ad1de42a4..30b07da0fddf46c5e6de1628e4249753d78457d6 100644 (file)
@@ -62,7 +62,7 @@ abstract class TestCase extends BaseTestCase
      * Assert that an activity entry exists of the given key.
      * Checks the activity belongs to the given entity if provided.
      */
-    protected function assertActivityExists(string $type, Entity $entity = null)
+    protected function assertActivityExists(string $type, ?Entity $entity, ?string $detail)
     {
         $detailsToCheck = ['type' => $type];
 
@@ -71,6 +71,10 @@ abstract class TestCase extends BaseTestCase
             $detailsToCheck['entity_id'] = $entity->id;
         }
 
+        if ($detail) {
+            $detailsToCheck['detail'] = $detail;
+        }
+
         $this->assertDatabaseHas('activities', $detailsToCheck);
     }
 }