A free open source IT asset/license management system
Use intended() for redirect back to where you were
snipeec24da12a1fd
diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.phpindex 8d6cad6cef..825f0c4bd0 100644--- a/app/Http/Controllers/Assets/BulkAssetsController.php+++ b/app/Http/Controllers/Assets/BulkAssetsController.php@@ -78,6 +78,10 @@ class BulkAssetsController extends Controller}if ($request->input('bulk_actions') === 'checkin') {+ $referer = request()->headers->get('referer');+ if ($referer && parse_url($referer, PHP_URL_HOST) === parse_url(config('app.url'), PHP_URL_HOST)) {+ redirect()->setIntendedUrl($referer);+ }$request->session()->flashInput(['selected_assets' => $asset_ids]);return redirect()->route('hardware.bulkcheckin.show');@@ -867,7 +871,7 @@ class BulkAssetsController extends Controller});if (! $errors) {- return redirect()->to('hardware')->with('success', trans_choice('admin/hardware/message.multi-checkin.success', count($asset_ids)));+ return redirect()->intended(route('hardware.index'))->with('success', trans_choice('admin/hardware/message.multi-checkin.success', count($asset_ids)));}return redirect()->route('hardware.bulkcheckin.show')->withInput()diff --git a/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.php b/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.phpindex 30f8fd18f4..d6b13ff8e2 100644--- a/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.php+++ b/tests/Feature/Checkins/Ui/BulkAssetCheckinTest.php@@ -255,6 +255,61 @@ class BulkAssetCheckinTest extends TestCase$this->assertEquals($checkedOutLocation->id, $childAsset->fresh()->location_id);}+ public function test_origin_url_is_stored_when_routing_to_bulk_checkin()+ {+ $assets = Asset::factory()->assignedToUser()->count(2)->create();+ $originUrl = route('hardware.index').'?status_type=Deployed';++ $this->actingAs(User::factory()->checkinAssets()->viewAssets()->create())+ ->from($originUrl)+ ->post(route('hardware.bulkedit.show'), [+ 'ids' => $assets->pluck('id')->toArray(),+ 'bulk_actions' => 'checkin',+ 'sort' => 'id',+ 'order' => 'asc',+ ])+ ->assertSessionHas('url.intended', $originUrl);+ }++ public function test_successful_checkin_redirects_to_origin_url()+ {+ $asset = Asset::factory()->assignedToUser()->create();+ $originUrl = route('hardware.index').'?status_type=Deployed';++ $this->actingAs(User::factory()->checkinAssets()->create())+ ->withSession(['url.intended' => $originUrl])+ ->post(route('hardware.bulkcheckin.store'), [+ 'selected_assets' => [$asset->id],+ ])+ ->assertRedirect($originUrl);+ }++ public function test_external_referer_is_not_stored_as_intended_url()+ {+ $assets = Asset::factory()->assignedToUser()->count(2)->create();++ $this->actingAs(User::factory()->checkinAssets()->viewAssets()->create())+ ->from('https://evil.example.com/phish')+ ->post(route('hardware.bulkedit.show'), [+ 'ids' => $assets->pluck('id')->toArray(),+ 'bulk_actions' => 'checkin',+ 'sort' => 'id',+ 'order' => 'asc',+ ])+ ->assertSessionMissing('url.intended');+ }++ public function test_successful_checkin_falls_back_to_hardware_index_without_origin_url()+ {+ $asset = Asset::factory()->assignedToUser()->create();++ $this->actingAs(User::factory()->checkinAssets()->create())+ ->post(route('hardware.bulkcheckin.store'), [+ 'selected_assets' => [$asset->id],+ ])+ ->assertRedirect(route('hardware.index'));+ }+public function test_returns_error_when_no_assets_selected(){$this->actingAs(User::factory()->checkinAssets()->create())