mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Drop Sandstorm related code.
This commit is contained in:
parent
7945220825
commit
b83d06294d
@ -304,7 +304,6 @@ PUSHER_ID=
|
||||
DEMO_USERNAME=
|
||||
DEMO_PASSWORD=
|
||||
USE_ENCRYPTION=false
|
||||
IS_SANDSTORM=false
|
||||
IS_HEROKU=false
|
||||
FIREFLY_III_LAYOUT=v1
|
||||
|
||||
|
@ -25,7 +25,6 @@ namespace FireflyIII\Http\Controllers\Admin;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Http\Middleware\IsSandStormUser;
|
||||
use FireflyIII\Http\Requests\ConfigurationRequest;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@ -55,7 +54,6 @@ class ConfigurationController extends Controller
|
||||
}
|
||||
);
|
||||
$this->middleware(IsDemoUser::class)->except(['index']);
|
||||
$this->middleware(IsSandStormUser::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +25,6 @@ namespace FireflyIII\Http\Controllers\Admin;
|
||||
use FireflyIII\Events\AdminRequestedTestMessage;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Http\Middleware\IsSandStormUser;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@ -48,7 +47,6 @@ class HomeController extends Controller
|
||||
{
|
||||
parent::__construct();
|
||||
$this->middleware(IsDemoUser::class)->except(['index']);
|
||||
$this->middleware(IsSandStormUser::class)->except(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,9 +59,8 @@ class HomeController extends Controller
|
||||
Log::channel('audit')->info('User visits admin index.');
|
||||
$title = (string) trans('firefly.administration');
|
||||
$mainTitleIcon = 'fa-hand-spock-o';
|
||||
$sandstorm = 1 === (int) getenv('SANDSTORM');
|
||||
|
||||
return view('admin.index', compact('title', 'mainTitleIcon', 'sandstorm'));
|
||||
return view('admin.index', compact('title', 'mainTitleIcon'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +26,6 @@ namespace FireflyIII\Http\Controllers\Admin;
|
||||
use FireflyIII\Helpers\Update\UpdateTrait;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Http\Middleware\IsSandStormUser;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@ -57,7 +56,6 @@ class UpdateController extends Controller
|
||||
}
|
||||
);
|
||||
$this->middleware(IsDemoUser::class)->except(['index']);
|
||||
$this->middleware(IsSandStormUser::class)->except(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,6 @@ namespace FireflyIII\Http\Controllers\Admin;
|
||||
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Http\Middleware\IsSandStormUser;
|
||||
use FireflyIII\Http\Requests\UserFormRequest;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
@ -57,7 +56,6 @@ class UserController extends Controller
|
||||
}
|
||||
);
|
||||
$this->middleware(IsDemoUser::class)->except(['index', 'show']);
|
||||
$this->middleware(IsSandStormUser::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,6 @@ use FireflyIII\Events\UserChangedEmail;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Exceptions\ValidationException;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Http\Middleware\IsSandStormUser;
|
||||
use FireflyIII\Http\Requests\DeleteAccountFormRequest;
|
||||
use FireflyIII\Http\Requests\EmailFormRequest;
|
||||
use FireflyIII\Http\Requests\ProfileFormRequest;
|
||||
@ -85,7 +84,6 @@ class ProfileController extends Controller
|
||||
$this->externalIdentity = 'eloquent' === $loginProvider || 'remote_user_guard' === $authGuard;
|
||||
|
||||
$this->middleware(IsDemoUser::class)->except(['index']);
|
||||
$this->middleware(IsSandStormUser::class)->except('index');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,7 +31,6 @@ use FireflyIII\Http\Middleware\InterestingMessage;
|
||||
use FireflyIII\Http\Middleware\IsAdmin;
|
||||
use FireflyIII\Http\Middleware\Range;
|
||||
use FireflyIII\Http\Middleware\RedirectIfAuthenticated;
|
||||
use FireflyIII\Http\Middleware\Sandstorm;
|
||||
use FireflyIII\Http\Middleware\SecureHeaders;
|
||||
use FireflyIII\Http\Middleware\StartFireflySession;
|
||||
use FireflyIII\Http\Middleware\TrimStrings;
|
||||
@ -85,7 +84,6 @@ class Kernel extends HttpKernel
|
||||
// does not check 2fa
|
||||
// does not check activation
|
||||
'web' => [
|
||||
Sandstorm::class,
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartFireflySession::class,
|
||||
@ -105,7 +103,6 @@ class Kernel extends HttpKernel
|
||||
// MUST NOT be logged in. Does not care about 2FA or confirmation.
|
||||
'user-not-logged-in' => [
|
||||
Installer::class,
|
||||
Sandstorm::class,
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartFireflySession::class,
|
||||
@ -119,7 +116,6 @@ class Kernel extends HttpKernel
|
||||
// don't care about confirmation:
|
||||
'user-logged-in-no-2fa' => [
|
||||
Installer::class,
|
||||
Sandstorm::class,
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartFireflySession::class,
|
||||
@ -134,7 +130,6 @@ class Kernel extends HttpKernel
|
||||
// don't care about 2fa
|
||||
// don't care about confirmation.
|
||||
'user-simple-auth' => [
|
||||
Sandstorm::class,
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartFireflySession::class,
|
||||
@ -149,7 +144,6 @@ class Kernel extends HttpKernel
|
||||
// MUST be confirmed.
|
||||
// (this group includes the other Firefly middleware)
|
||||
'user-full-auth' => [
|
||||
Sandstorm::class,
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartFireflySession::class,
|
||||
@ -168,7 +162,6 @@ class Kernel extends HttpKernel
|
||||
// MUST have owner role
|
||||
// (this group includes the other Firefly middleware)
|
||||
'admin' => [
|
||||
Sandstorm::class,
|
||||
EncryptCookies::class,
|
||||
AddQueuedCookiesToResponse::class,
|
||||
StartFireflySession::class,
|
||||
|
@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* IsSandStormUser.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 FireflyIII\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
|
||||
/**
|
||||
* Class IsSandStormUser.
|
||||
*/
|
||||
class IsSandStormUser
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request. May not be a limited user (ie. Sandstorm env. or demo user).
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $guard = null)
|
||||
{
|
||||
if (Auth::guard($guard)->guest()) {
|
||||
// don't care when not logged in, usual stuff applies:
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if (1 === (int) getenv('SANDSTORM')) {
|
||||
app('session')->flash('warning', (string) trans('firefly.sandstorm_not_available'));
|
||||
|
||||
return response()->redirectTo(route('index'));
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Sandstorm.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/>.
|
||||
*/
|
||||
/** @noinspection PhpDynamicAsStaticMethodCallInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Middleware;
|
||||
|
||||
use Auth;
|
||||
use Closure;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class Sandstorm.
|
||||
*/
|
||||
class Sandstorm
|
||||
{
|
||||
/**
|
||||
* Detects if is using Sandstorm, and responds by logging the user
|
||||
* in and/or creating an account.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Closure $next
|
||||
* @param string|null $guard
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $guard = null)
|
||||
{
|
||||
// is in Sandstorm environment?
|
||||
$sandstorm = 1 === (int) getenv('SANDSTORM');
|
||||
app('view')->share('SANDSTORM', $sandstorm);
|
||||
if (!$sandstorm) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
// we're in sandstorm! is user a guest?
|
||||
if (Auth::guard($guard)->guest()) {
|
||||
/** @var UserRepositoryInterface $repository */
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
$userId = (string) $request->header('X-Sandstorm-User-Id');
|
||||
|
||||
// catch anonymous:
|
||||
$userId = '' === $userId ? 'anonymous' : $userId;
|
||||
$email = $userId . '@firefly';
|
||||
|
||||
// always grab the first user in the Sandstorm DB:
|
||||
$user = $repository->findByEmail($email) ?? $repository->first();
|
||||
// or create somebody if necessary.
|
||||
$user = $user ?? $this->createUser($email);
|
||||
|
||||
// then log this user in:
|
||||
Log::info(sprintf('Sandstorm user ID is "%s"', $userId));
|
||||
Log::info(sprintf('Access to database under "%s"', $email));
|
||||
Auth::guard($guard)->login($user);
|
||||
$repository->attachRole($user, 'owner');
|
||||
app('view')->share('SANDSTORM_ANON', false);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a user.
|
||||
*
|
||||
* @param string $email
|
||||
*
|
||||
* @return User
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function createUser(string $email): User
|
||||
{
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
|
||||
return $repository->store(
|
||||
[
|
||||
'blocked' => false,
|
||||
'blocked_code' => null,
|
||||
'email' => $email,
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ return [
|
||||
],
|
||||
|
||||
//'encryption' => null === env('USE_ENCRYPTION') || true === env('USE_ENCRYPTION'),
|
||||
'version' => '5.3.0-alpha.1',
|
||||
'version' => '5.3.0-beta.1',
|
||||
'api_version' => '1.2.0',
|
||||
'db_version' => 14,
|
||||
'maxUploadSize' => 15242880,
|
||||
@ -152,7 +152,6 @@ return [
|
||||
'send_registration_mail' => env('SEND_REGISTRATION_MAIL', true),
|
||||
'demo_username' => env('DEMO_USERNAME', ''),
|
||||
'demo_password' => env('DEMO_PASSWORD', ''),
|
||||
'is_sandstorm' => env('IS_SANDSTORM', 'unknown'),
|
||||
'fixer_api_key' => env('FIXER_API_KEY', ''),
|
||||
'mapbox_api_key' => env('MAPBOX_API_KEY', ''),
|
||||
'trusted_proxies' => env('TRUSTED_PROXIES', ''),
|
||||
@ -185,6 +184,7 @@ return [
|
||||
Tag::class,
|
||||
Transaction::class,
|
||||
TransactionJournal::class,
|
||||
Recurrence::class,
|
||||
],
|
||||
'allowedMimes' => [
|
||||
/* plain files */
|
||||
|
@ -1511,9 +1511,6 @@ return [
|
||||
'reset_after' => 'Reset form after submission',
|
||||
'errors_submission' => 'There was something wrong with your submission. Please check out the errors below.',
|
||||
|
||||
// sandstorm.io errors and messages:
|
||||
'sandstorm_not_available' => 'This function is not available when you are using Firefly III within a Sandstorm.io environment.',
|
||||
|
||||
// object groups
|
||||
'default_group_title_name' => '(ungrouped)',
|
||||
|
||||
|
@ -17,9 +17,7 @@
|
||||
{% if config('firefly.feature_flags.telemetry') %}
|
||||
<li><a href="{{ route('admin.telemetry.index') }}">{{ 'telemetry_admin_index'|_ }}</a></li>
|
||||
{% endif %}
|
||||
{% if not sandstorm %}
|
||||
<li><a href="{{ route('admin.update-check') }}">{{ 'update_check_title'|_ }}</a></li>
|
||||
{% endif %}
|
||||
<li><a href="{{ route('admin.update-check') }}">{{ 'update_check_title'|_ }}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -84,13 +84,11 @@
|
||||
</span>
|
||||
</li>
|
||||
|
||||
{% if not SANDSTORM %}
|
||||
<li class="dropdown user user-menu">
|
||||
<span style="cursor:default;color:#fff;padding: 15px;display: block;line-height: 20px;">
|
||||
<span class="hidden-xs">{{ Auth.user.email }}</span>
|
||||
</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li class="dropdown user user-menu">
|
||||
<span style="cursor:default;color:#fff;padding: 15px;display: block;line-height: 20px;">
|
||||
<span class="hidden-xs">{{ Auth.user.email }}</span>
|
||||
</span>
|
||||
</li>
|
||||
<li id="sidebar-toggle">
|
||||
<a href="#" data-toggle="control-sidebar"><i class="fa fa-plus-circle"></i></a>
|
||||
</li>
|
||||
|
@ -213,12 +213,10 @@
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
{% if not SANDSTORM %}
|
||||
<li>
|
||||
<a href="{{ route('logout') }}">
|
||||
<i class="fa fa-sign-out fa-fw"></i>
|
||||
<span>{{ 'logout'|_ }}</span>
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
@ -17,7 +17,6 @@
|
||||
<p>
|
||||
{{ trans('firefly.user_id_is',{user: userId})|raw }}
|
||||
</p>
|
||||
{% if not SANDSTORM %}
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<ul>
|
||||
@ -37,34 +36,11 @@
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if SANDSTORM %}
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Offer template</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<p>
|
||||
Block for sandstorm thing
|
||||
</p>
|
||||
<div>
|
||||
<iframe style="width: 100%; height: 55px; margin: 0; border: 0;" id="offer-iframe">
|
||||
</iframe>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if not SANDSTORM %}
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12">
|
||||
<div class="box box-primary">
|
||||
@ -89,9 +65,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if not SANDSTORM %}
|
||||
<div class="row">
|
||||
<div class="col-lg-8 col-lg-offset-2 col-md-12 col-sm-12">
|
||||
<div class="box box-primary">
|
||||
@ -128,7 +102,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div id="passport_clients"></div>
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
|
@ -1,3 +1,2 @@
|
||||
list-length: {{ listLength }}
|
||||
sandstorm-anon: {% if SANDSTORM_ANON %}true{% else %}false{% endif %}
|
||||
user-email: {{ Auth.user.email }}
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
@ -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');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user