mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 02:45:58 +00:00
Clean up sandstorm tests.
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
list-length: {{ listLength }}
|
list-length: {{ listLength }}
|
||||||
sandstorm-anon: {% if SANDSTORM_ANON %}true{% else %}false{% endif %}
|
sandstorm-anon: {% if SANDSTORM_ANON %}true{% else %}false{% endif %}
|
||||||
|
user-email: {{ Auth.user.email }}
|
||||||
|
@@ -24,11 +24,11 @@ declare(strict_types=1);
|
|||||||
namespace Tests\Unit\Middleware;
|
namespace Tests\Unit\Middleware;
|
||||||
|
|
||||||
use FireflyIII\Http\Middleware\Sandstorm;
|
use FireflyIII\Http\Middleware\Sandstorm;
|
||||||
use FireflyIII\Models\Role;
|
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
use Route;
|
use Route;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
use Mockery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RangeTest
|
* Class RangeTest
|
||||||
@@ -38,129 +38,19 @@ class SandstormTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
||||||
*/
|
*/
|
||||||
public function testMiddlewareAnonEmpty(): void
|
public function testMiddlewareBasic(): void
|
||||||
{
|
{
|
||||||
putenv('SANDSTORM=1');
|
putenv('SANDSTORM=1');
|
||||||
|
|
||||||
$repository = $this->mock(UserRepositoryInterface::class);
|
$repository = $this->mock(UserRepositoryInterface::class);
|
||||||
$repository->shouldReceive('count')->once()->andReturn(0);
|
$repository->shouldReceive('findByEmail')->withArgs(['anonymous@firefly'])->once()->andReturn($this->user());
|
||||||
|
// single user, checks if user is admin
|
||||||
|
$repository->shouldReceive('count')->andReturn(1);
|
||||||
|
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->once();
|
||||||
|
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->once();
|
||||||
|
$repository->shouldReceive('attachRole')->withArgs([Mockery::any(), 'owner'])->once();
|
||||||
|
|
||||||
$response = $this->get('/_test/sandstorm');
|
$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 testMiddlewareAnonLoggedIn(): void
|
|
||||||
{
|
|
||||||
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 testMiddlewareAnonUser(): void
|
|
||||||
{
|
|
||||||
putenv('SANDSTORM=1');
|
|
||||||
|
|
||||||
$repository = $this->mock(UserRepositoryInterface::class);
|
|
||||||
$repository->shouldReceive('count')->twice()->andReturn(1);
|
|
||||||
$repository->shouldReceive('hasRole')->andReturn(true);
|
|
||||||
|
|
||||||
$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(): void
|
|
||||||
{
|
|
||||||
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 testMiddlewareMultiUser(): void
|
|
||||||
{
|
|
||||||
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(): void
|
|
||||||
{
|
|
||||||
putenv('SANDSTORM=1');
|
|
||||||
|
|
||||||
$repository = $this->mock(UserRepositoryInterface::class);
|
|
||||||
$repository->shouldReceive('count')->twice()->andReturn(0);
|
|
||||||
$repository->shouldReceive('store')->once()->andReturn($this->user());
|
|
||||||
$repository->shouldReceive('attachRole')->once()->andReturn(true);
|
|
||||||
//$repository->shouldReceive('getRole')->once()->andReturn(new Role);
|
|
||||||
$repository->shouldReceive('hasRole')->andReturn(false);
|
|
||||||
|
|
||||||
$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(): void
|
|
||||||
{
|
|
||||||
$this->withoutExceptionHandling();
|
|
||||||
$response = $this->get('/_test/sandstorm');
|
|
||||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \FireflyIII\Http\Middleware\Sandstorm::handle
|
|
||||||
*/
|
|
||||||
public function testMiddlewareOneUser(): void
|
|
||||||
{
|
|
||||||
putenv('SANDSTORM=1');
|
|
||||||
|
|
||||||
$repository = $this->mock(UserRepositoryInterface::class);
|
|
||||||
$repository->shouldReceive('count')->twice()->andReturn(1);
|
|
||||||
$repository->shouldReceive('first')->once()->andReturn($this->user());
|
|
||||||
$repository->shouldReceive('hasRole')->andReturn(true);
|
|
||||||
|
|
||||||
$response = $this->get('/_test/sandstorm', ['X-Sandstorm-User-Id' => 'abcd']);
|
|
||||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||||
$response->assertSee('sandstorm-anon: false');
|
$response->assertSee('sandstorm-anon: false');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user