Drop Sandstorm related code.

This commit is contained in:
James Cole
2020-06-27 15:19:00 +02:00
parent 7945220825
commit b83d06294d
18 changed files with 9 additions and 412 deletions

View File

@@ -1,90 +0,0 @@
<?php
/**
* IsSandstormUserTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Middleware;
use FireflyIII\Http\Middleware\IsSandStormUser;
use Log;
use Route;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
/**
* Class IsSandstormUserTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class IsSandstormUserTest extends TestCase
{
/**
* Set up test
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
Route::middleware(IsSandStormUser::class)->any(
'/_test/is-sandstorm',static function () {
return 'OK';
}
);
}
/**
* @covers \FireflyIII\Http\Middleware\IsSandStormUser
*/
public function testMiddlewareNotAuthenticated(): void
{
$this->withoutExceptionHandling();
$response = $this->get('/_test/is-sandstorm');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\IsSandStormUser
*/
public function testMiddlewareNotSandStorm(): void
{
$this->withoutExceptionHandling();
$this->be($this->user());
$response = $this->get('/_test/is-sandstorm');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\IsSandStormUser
*/
public function testMiddlewareSandstorm(): void
{
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', (string)trans('firefly.sandstorm_not_available'));
$response->assertRedirect(route('index'));
putenv('SANDSTORM=0');
}
}

View File

@@ -1,91 +0,0 @@
<?php
/**
* SandstormTest.php
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Middleware;
use FireflyIII\Http\Middleware\Sandstorm;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
use Route;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
/**
* Class RangeTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class SandstormTest extends TestCase
{
/**
* Set up test
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
Route::middleware(Sandstorm::class)->any(
'/_test/sandstorm', function () {
return view('test.test');
}
);
}
/**
* @covers \FireflyIII\Http\Middleware\Sandstorm
*/
public function testMiddlewareBasic(): void
{
putenv('SANDSTORM=1');
$repository = $this->mock(UserRepositoryInterface::class);
$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');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('sandstorm-anon: false');
putenv('SANDSTORM=0');
}
/**
* @covers \FireflyIII\Http\Middleware\Sandstorm
*/
public function testMiddlewareNotSandstorm(): void
{
putenv('SANDSTORM=0');
$response = $this->get('/_test/sandstorm');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('sandstorm-anon: false');
}
}