mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve testing of middleware.
This commit is contained in:
@@ -88,7 +88,17 @@ abstract class TestCase extends BaseTestCase
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function emptyUser()
|
||||
public function demoUser(): User
|
||||
{
|
||||
$user = User::find(4);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function emptyUser(): User
|
||||
{
|
||||
$user = User::find(2);
|
||||
|
||||
@@ -98,7 +108,7 @@ abstract class TestCase extends BaseTestCase
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function user()
|
||||
public function user(): User
|
||||
{
|
||||
$user = User::find(1);
|
||||
|
||||
|
94
tests/Unit/Middleware/IsAdminTest.php
Normal file
94
tests/Unit/Middleware/IsAdminTest.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* IsAdminTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Helpers;
|
||||
|
||||
use FireflyIII\Http\Middleware\IsAdmin;
|
||||
use Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IsAdminTest
|
||||
*/
|
||||
class IsAdminTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\IsAdmin::handle
|
||||
*/
|
||||
public function testMiddleware()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$response = $this->get('/_test/is-admin');
|
||||
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
|
||||
$response->assertRedirect(route('login'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\IsAdmin::handle
|
||||
*/
|
||||
public function testMiddlewareAjax()
|
||||
{
|
||||
$server = ['HTTP_X-Requested-With' => 'XMLHttpRequest'];
|
||||
$this->withoutExceptionHandling();
|
||||
$response = $this->get('/_test/is-admin', $server);
|
||||
$this->assertEquals(Response::HTTP_UNAUTHORIZED, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\IsAdmin::handle
|
||||
*/
|
||||
public function testMiddlewareOwner()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$this->withoutExceptionHandling();
|
||||
$response = $this->get('/_test/is-admin');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\IsAdmin::handle
|
||||
*/
|
||||
public function testMiddlewareNotOwner()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$this->be($this->emptyUser());
|
||||
$response = $this->get('/_test/is-admin');
|
||||
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
|
||||
$response->assertRedirect(route('home'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up test
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Route::middleware(IsAdmin::class)->any(
|
||||
'/_test/is-admin', function () {
|
||||
return 'OK';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
84
tests/Unit/Middleware/IsDemoUserTest.php
Normal file
84
tests/Unit/Middleware/IsDemoUserTest.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* IsDemoUserTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Helpers;
|
||||
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IsDemoUserTest
|
||||
*/
|
||||
class IsDemoUserTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\IsDemoUser::handle
|
||||
*/
|
||||
public function testMiddlewareNotAuthenticated()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$response = $this->get('/_test/is-demo');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\IsDemoUser::handle
|
||||
*/
|
||||
public function testMiddlewareAuthenticated()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/is-demo');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\IsDemoUser::handle
|
||||
*/
|
||||
public function testMiddlewareDemoUser()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$this->be($this->demoUser());
|
||||
$response = $this->get('/_test/is-demo');
|
||||
|
||||
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
|
||||
$response->assertSessionHas('warning', strval(trans('firefly.not_available_demo_user')));
|
||||
$response->assertRedirect(route('index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up test
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Route::middleware(IsDemoUser::class)->any(
|
||||
'/_test/is-demo', function () {
|
||||
return 'OK';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
87
tests/Unit/Middleware/IsSandstormUserTest.php
Normal file
87
tests/Unit/Middleware/IsSandstormUserTest.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* IsSandstormUserTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Helpers;
|
||||
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Http\Middleware\IsSandStormUser;
|
||||
use Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IsSandstormUserTest
|
||||
*/
|
||||
class IsSandstormUserTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\IsSandStormUser::handle
|
||||
*/
|
||||
public function testMiddlewareNotAuthenticated()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$response = $this->get('/_test/is-sandstorm');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\IsSandStormUser::handle
|
||||
*/
|
||||
public function testMiddlewareNotSandStorm()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/is-sandstorm');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\IsSandStormUser::handle
|
||||
*/
|
||||
public function testMiddlewareSandstorm()
|
||||
{
|
||||
putenv('SANDSTORM=1');
|
||||
$this->withoutExceptionHandling();
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/is-sandstorm');
|
||||
|
||||
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
|
||||
$response->assertSessionHas('warning', strval(trans('firefly.sandstorm_not_available')));
|
||||
$response->assertRedirect(route('index'));
|
||||
putenv('SANDSTORM=0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up test
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Route::middleware(IsSandStormUser::class)->any(
|
||||
'/_test/is-sandstorm', function () {
|
||||
return 'OK';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
80
tests/Unit/Middleware/RangeTest.php
Normal file
80
tests/Unit/Middleware/RangeTest.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* RangeTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Helpers;
|
||||
|
||||
use FireflyIII\Http\Middleware\Range;
|
||||
use Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class RangeTest
|
||||
*/
|
||||
class RangeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Range::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Range::__construct
|
||||
* @covers \FireflyIII\Http\Middleware\Range::configureList
|
||||
* @covers \FireflyIII\Http\Middleware\Range::configureView
|
||||
* @covers \FireflyIII\Http\Middleware\Range::setRange
|
||||
*/
|
||||
public function testMiddlewareAuthenticated()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/range');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
|
||||
// view has list length
|
||||
$response->assertSeeText('list-length: 10');
|
||||
|
||||
// assert some session stuff?
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Range::handle
|
||||
* @covers \FireflyIII\Http\Middleware\Range::__construct
|
||||
*/
|
||||
public function testMiddlewareNotAuthenticated()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$response = $this->get('/_test/range');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up test
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Route::middleware(Range::class)->any(
|
||||
'/_test/range', function () {
|
||||
return view('test.test');
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
94
tests/Unit/Middleware/RedirectIf2FAAuthenticatedTest.php
Normal file
94
tests/Unit/Middleware/RedirectIf2FAAuthenticatedTest.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* RedirectIf2FAAuthenticatedTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Helpers;
|
||||
|
||||
use FireflyIII\Http\Middleware\RedirectIfTwoFactorAuthenticated;
|
||||
use FireflyIII\Models\Preference;
|
||||
use Preferences;
|
||||
use Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class RedirectIf2FAAuthenticatedTest
|
||||
*/
|
||||
class RedirectIf2FAAuthenticatedTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\RedirectIfTwoFactorAuthenticated::handle
|
||||
*/
|
||||
public function testMiddleware()
|
||||
{
|
||||
$response = $this->get('/_test/authenticate');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\RedirectIfTwoFactorAuthenticated::handle
|
||||
*/
|
||||
public function testMiddlewareAuthenticated()
|
||||
{
|
||||
// pref for has 2fa is true
|
||||
$preference = new Preference;
|
||||
$preference->data = true;
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->once()->andReturn($preference);
|
||||
|
||||
// pref for twoFactorAuthSecret
|
||||
$secret = new Preference;
|
||||
$secret->data = 'SomeSecret';
|
||||
Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->once()->andReturn($secret);
|
||||
|
||||
// no cookie
|
||||
$cookie = ['twoFactorAuthenticated' => 'true'];
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->call('GET', '/_test/authenticate', [], $cookie);
|
||||
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
|
||||
$response->assertRedirect(route('index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\RedirectIfTwoFactorAuthenticated::handle
|
||||
*/
|
||||
public function testMiddlewareLightAuth()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/authenticate');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up test
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Route::middleware(RedirectIfTwoFactorAuthenticated::class)->any(
|
||||
'/_test/authenticate', function () {
|
||||
return 'OK';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
69
tests/Unit/Middleware/RedirectIfAuthenticatedTest.php
Normal file
69
tests/Unit/Middleware/RedirectIfAuthenticatedTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* RedirectIfAuthenticatedTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Helpers;
|
||||
|
||||
use FireflyIII\Http\Middleware\RedirectIfAuthenticated;
|
||||
use Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class RedirectIfAuthenticatedTest
|
||||
*/
|
||||
class RedirectIfAuthenticatedTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\RedirectIfAuthenticated::handle
|
||||
*/
|
||||
public function testMiddleware()
|
||||
{
|
||||
$response = $this->get('/_test/authenticate');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\RedirectIfAuthenticated::handle
|
||||
*/
|
||||
public function testMiddlewareAuthenticated()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/authenticate');
|
||||
$this->assertEquals(Response::HTTP_FOUND, $response->getStatusCode());
|
||||
$response->assertRedirect(route('index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up test
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Route::middleware(RedirectIfAuthenticated::class)->any(
|
||||
'/_test/authenticate', function () {
|
||||
return 'OK';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
178
tests/Unit/Middleware/SandstormTest.php
Normal file
178
tests/Unit/Middleware/SandstormTest.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/**
|
||||
* SandstormTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Helpers;
|
||||
|
||||
use FireflyIII\Http\Middleware\Sandstorm;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class RangeTest
|
||||
*/
|
||||
class SandstormTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
||||
*/
|
||||
public function testMiddlewareAnonEmpty()
|
||||
{
|
||||
putenv('SANDSTORM=1');
|
||||
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('count')->once()->andReturn(0);
|
||||
|
||||
$response = $this->get('/_test/sandstorm');
|
||||
$this->assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode());
|
||||
$response->assertSee('The first visit to a new Firefly III administration cannot be by a guest user.');
|
||||
|
||||
putenv('SANDSTORM=0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
||||
*/
|
||||
public function testMiddlewareAnonUser()
|
||||
{
|
||||
putenv('SANDSTORM=1');
|
||||
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('count')->once()->andReturn(1);
|
||||
|
||||
$response = $this->get('/_test/sandstorm');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
$response->assertSee('sandstorm-anon: true');
|
||||
|
||||
putenv('SANDSTORM=0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
||||
*/
|
||||
public function testMiddlewareLoggedIn()
|
||||
{
|
||||
putenv('SANDSTORM=1');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/sandstorm', ['X-Sandstorm-User-Id' => 'abcd']);
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
$response->assertSee('sandstorm-anon: false');
|
||||
|
||||
putenv('SANDSTORM=0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
||||
*/
|
||||
public function testMiddlewareAnonLoggedIn()
|
||||
{
|
||||
putenv('SANDSTORM=1');
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get('/_test/sandstorm');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
$response->assertSee('sandstorm-anon: true');
|
||||
|
||||
putenv('SANDSTORM=0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
||||
*/
|
||||
public function testMiddlewareMultiUser()
|
||||
{
|
||||
putenv('SANDSTORM=1');
|
||||
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('count')->once()->andReturn(2);
|
||||
|
||||
$response = $this->get('/_test/sandstorm');
|
||||
$this->assertEquals(Response::HTTP_INTERNAL_SERVER_ERROR, $response->getStatusCode());
|
||||
$response->assertSee('Your Firefly III installation has more than one user, which is weird.');
|
||||
|
||||
putenv('SANDSTORM=0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
||||
*/
|
||||
public function testMiddlewareNoUser()
|
||||
{
|
||||
putenv('SANDSTORM=1');
|
||||
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('count')->once()->andReturn(0);
|
||||
$repository->shouldReceive('store')->once()->andReturn($this->user());
|
||||
$repository->shouldReceive('attachRole')->once()->andReturn(true);
|
||||
|
||||
$response = $this->get('/_test/sandstorm', ['X-Sandstorm-User-Id' => 'abcd']);
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
$response->assertSee('sandstorm-anon: false');
|
||||
|
||||
putenv('SANDSTORM=0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
||||
*/
|
||||
public function testMiddlewareNotSandstorm()
|
||||
{
|
||||
$this->withoutExceptionHandling();
|
||||
$response = $this->get('/_test/sandstorm');
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
||||
*/
|
||||
public function testMiddlewareOneUser()
|
||||
{
|
||||
putenv('SANDSTORM=1');
|
||||
|
||||
$repository = $this->mock(UserRepositoryInterface::class);
|
||||
$repository->shouldReceive('count')->once()->andReturn(1);
|
||||
$repository->shouldReceive('first')->once()->andReturn($this->user());
|
||||
|
||||
$response = $this->get('/_test/sandstorm', ['X-Sandstorm-User-Id' => 'abcd']);
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
$response->assertSee('sandstorm-anon: false');
|
||||
|
||||
putenv('SANDSTORM=0');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up test
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Route::middleware(Sandstorm::class)->any(
|
||||
'/_test/sandstorm', function () {
|
||||
return view('test.test');
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user