Skip to content

A free open source IT asset/license management system

Added tests

snipe630e1196c4ff
diff --git a/tests/Feature/Maintenances/Ui/BulkMaintenanceActionsTest.php b/tests/Feature/Maintenances/Ui/BulkMaintenanceActionsTest.php
index c327cf4720..883c17901e 100644
--- a/tests/Feature/Maintenances/Ui/BulkMaintenanceActionsTest.php
+++ b/tests/Feature/Maintenances/Ui/BulkMaintenanceActionsTest.php
@@ -167,4 +167,33 @@ class BulkMaintenanceActionsTest extends TestCase
->assertRedirect(route('maintenances.index'))
->assertSessionHas('error');
}
+
+ public function test_same_origin_referer_is_used_for_post_action_redirect()
+ {
+ $maintenance = Maintenance::factory()->create();
+ $referer = config('app.url').'/maintenances?completed=true';
+
+ $this->actingAs(User::factory()->superuser()->create())
+ ->withHeader('referer', $referer)
+ ->post(route('maintenances.bulk'), [
+ 'bulk_actions' => 'delete',
+ 'ids' => [$maintenance->id],
+ ])
+ ->assertRedirect($referer);
+ }
+
+ public function test_offsite_referer_is_rejected_and_falls_back_to_index()
+ {
+ $maintenance = Maintenance::factory()->create();
+
+ // Attacker-controlled referer must not be honored — protects
+ // against open-redirect / phishing hand-offs after the POST.
+ $this->actingAs(User::factory()->superuser()->create())
+ ->withHeader('referer', 'https://evil.example.com/steal-session')
+ ->post(route('maintenances.bulk'), [
+ 'bulk_actions' => 'delete',
+ 'ids' => [$maintenance->id],
+ ])
+ ->assertRedirect(route('maintenances.index'));
+ }
}
diff --git a/tests/Feature/Maintenances/Ui/EditMaintenanceTest.php b/tests/Feature/Maintenances/Ui/EditMaintenanceTest.php
index bda47afe0e..d0960f72a5 100644
--- a/tests/Feature/Maintenances/Ui/EditMaintenanceTest.php
+++ b/tests/Feature/Maintenances/Ui/EditMaintenanceTest.php
@@ -262,6 +262,55 @@ class EditMaintenanceTest extends TestCase
$this->assertNull($maintenance->fresh()->completed_at);
}
+ public function test_edit_form_seeds_url_intended_from_referer_and_update_redirects_there()
+ {
+ $maintenance = Maintenance::factory()->create();
+ $type = MaintenanceType::factory()->create();
+ $filteredIndex = config('app.url').'/maintenances?completed=true';
+
+ $actor = User::factory()->superuser()->create();
+
+ // GET the edit form with a referer set (as the browser would)
+ // to seed session()['url.intended'].
+ $this->actingAs($actor)
+ ->from($filteredIndex)
+ ->get(route('maintenances.edit', $maintenance->id))
+ ->assertOk();
+
+ // The subsequent PUT should honor the seeded intended URL.
+ $this->actingAs($actor)
+ ->put(route('maintenances.update', $maintenance), [
+ 'name' => 'Post-edit',
+ 'asset_id' => $maintenance->asset_id,
+ 'maintenance_type_id' => $type->id,
+ 'start_date' => '2021-01-01 00:00:00',
+ 'completion_date' => '2021-01-10 00:00:00',
+ ])
+ ->assertSessionHasNoErrors()
+ ->assertRedirect($filteredIndex);
+ }
+
+ public function test_edit_update_falls_back_to_index_when_url_intended_is_offsite()
+ {
+ $maintenance = Maintenance::factory()->create();
+ $type = MaintenanceType::factory()->create();
+
+ // Seed url.intended with an attacker-controlled URL directly, as
+ // if SamlController RelayState or a stale session value slipped
+ // it in. Helper::sameOriginUrl must reject it.
+ $this->actingAs(User::factory()->superuser()->create())
+ ->withSession(['url.intended' => 'https://evil.example.com/steal-session'])
+ ->put(route('maintenances.update', $maintenance), [
+ 'name' => 'Post-edit',
+ 'asset_id' => $maintenance->asset_id,
+ 'maintenance_type_id' => $type->id,
+ 'start_date' => '2021-01-01 00:00:00',
+ 'completion_date' => '2021-01-10 00:00:00',
+ ])
+ ->assertSessionHasNoErrors()
+ ->assertRedirect(route('maintenances.index'));
+ }
+
public function test_user_cannot_edit_maintenance_for_another_company_when_fmcs_enabled()
{
$this->settings->enableMultipleFullCompanySupport();