mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Reviewed adding IP recording to activity & audit log
Review of #2936 - Added testing to cover - Added APP_PROXIES to .env.example.complete with details. - Renamed migration to better align the name and to set the migration date to fit with production deploy order. - Removed index from IP column in migration since an index does not yet provide any value. - Updated table header text label. - Prevented IP recording when in demo mode.
This commit is contained in:
@@ -140,4 +140,53 @@ class AuditLogTest extends TestCase
|
||||
$resp->assertSeeText($chapter->name);
|
||||
$resp->assertDontSeeText($page->name);
|
||||
}
|
||||
|
||||
public function test_ip_address_logged_and_visible()
|
||||
{
|
||||
config()->set('app.proxies', '*');
|
||||
$editor = $this->getEditor();
|
||||
/** @var Page $page */
|
||||
$page = Page::query()->first();
|
||||
|
||||
$this->actingAs($editor)->put($page->getUrl(), [
|
||||
'name' => 'Updated page',
|
||||
'html' => '<p>Updated content</p>',
|
||||
], [
|
||||
'X-Forwarded-For' => '192.123.45.1'
|
||||
])->assertRedirect($page->refresh()->getUrl());
|
||||
|
||||
$this->assertDatabaseHas('activities', [
|
||||
'type' => ActivityType::PAGE_UPDATE,
|
||||
'ip' => '192.123.45.1',
|
||||
'user_id' => $editor->id,
|
||||
'entity_id' => $page->id,
|
||||
]);
|
||||
|
||||
$resp = $this->asAdmin()->get('/settings/audit');
|
||||
$resp->assertSee('192.123.45.1');
|
||||
}
|
||||
|
||||
public function test_ip_address_not_logged_in_demo_mode()
|
||||
{
|
||||
config()->set('app.proxies', '*');
|
||||
config()->set('app.env', 'demo');
|
||||
$editor = $this->getEditor();
|
||||
/** @var Page $page */
|
||||
$page = Page::query()->first();
|
||||
|
||||
$this->actingAs($editor)->put($page->getUrl(), [
|
||||
'name' => 'Updated page',
|
||||
'html' => '<p>Updated content</p>',
|
||||
], [
|
||||
'X-Forwarded-For' => '192.123.45.1',
|
||||
'REMOTE_ADDR' => '192.123.45.2',
|
||||
])->assertRedirect($page->refresh()->getUrl());
|
||||
|
||||
$this->assertDatabaseHas('activities', [
|
||||
'type' => ActivityType::PAGE_UPDATE,
|
||||
'ip' => '127.0.0.1',
|
||||
'user_id' => $editor->id,
|
||||
'entity_id' => $page->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user