Merge pull request #28 from vitodeploy/test-coverage

code quality
This commit is contained in:
Saeed Vaziry 2023-09-02 20:32:49 +02:00 committed by GitHub
commit df96b860c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
134 changed files with 1835 additions and 115 deletions

View File

@ -1,4 +1,4 @@
name: tests name: checks
on: on:
push: push:
@ -54,3 +54,34 @@ jobs:
DB_DATABASE: test_db DB_DATABASE: test_db
DB_USERNAME: user DB_USERNAME: user
DB_PASSWORD: password DB_PASSWORD: password
code-style:
runs-on: ubuntu-20.04
strategy:
fail-fast: true
matrix:
php: [ 8.1 ]
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run pint
run: ./vendor/bin/pint --test

View File

@ -59,7 +59,7 @@ private function validate($type, Server $server, array $input): void
'0 0 * * *', '0 0 * * *',
'0 0 * * 0', '0 0 * * 0',
'0 0 1 * *', '0 0 1 * *',
'custom' 'custom',
]), ]),
], ],
]; ];

View File

@ -6,7 +6,6 @@
use App\Models\FirewallRule; use App\Models\FirewallRule;
use App\Models\Server; use App\Models\Server;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
class CreateRule class CreateRule

View File

@ -15,7 +15,7 @@ public function connect(array $input): void
$sourceControl = new SourceControl([ $sourceControl = new SourceControl([
'provider' => $input['provider'], 'provider' => $input['provider'],
'profile' => $input['name'], 'profile' => $input['name'],
'access_token' => $input['token'] 'access_token' => $input['token'],
]); ]);
if (! $sourceControl->provider()->connect()) { if (! $sourceControl->provider()->connect()) {
@ -36,14 +36,14 @@ private function validate(array $input): void
$rules = [ $rules = [
'provider' => [ 'provider' => [
'required', 'required',
Rule::in(\App\Enums\SourceControl::getValues()) Rule::in(\App\Enums\SourceControl::getValues()),
], ],
'name' => [ 'name' => [
'required', 'required',
], ],
'token' => [ 'token' => [
'required' 'required',
] ],
]; ];
Validator::make($input, $rules)->validate(); Validator::make($input, $rules)->validate();
} }

View File

@ -22,15 +22,15 @@ public function create(User $user, array $input): void
'provider' => $input['provider'], 'provider' => $input['provider'],
'profile' => $input['name'], 'profile' => $input['name'],
'credentials' => [ 'credentials' => [
'token' => $input['token'] 'token' => $input['token'],
] ],
]); ]);
if (! $storageProvider->provider()->connect()) { if (! $storageProvider->provider()->connect()) {
throw ValidationException::withMessages([ throw ValidationException::withMessages([
'token' => __("Couldn't connect to the provider") 'token' => __("Couldn't connect to the provider"),
]); ]);
} }
$storageProvider->save();; $storageProvider->save();
} }
private function validate(User $user, array $input): void private function validate(User $user, array $input): void
@ -45,8 +45,8 @@ private function validate(User $user, array $input): void
Rule::unique('storage_providers', 'profile')->where('user_id', $user->id), Rule::unique('storage_providers', 'profile')->where('user_id', $user->id),
], ],
'token' => [ 'token' => [
'required' 'required',
] ],
])->validate(); ])->validate();
} }
} }

View File

@ -4,7 +4,6 @@
use App\Models\User; use App\Models\User;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Support\Str;
class CreateUserCommand extends Command class CreateUserCommand extends Command
{ {
@ -20,6 +19,6 @@ public function handle(): void
'password' => bcrypt($this->argument('password')), 'password' => bcrypt($this->argument('password')),
]); ]);
$this->info("User created with password"); $this->info('User created with password');
} }
} }

View File

@ -3,7 +3,6 @@
namespace App\Contracts; namespace App\Contracts;
use App\Models\Server; use App\Models\Server;
use Symfony\Component\HttpFoundation\RedirectResponse;
interface StorageProvider interface StorageProvider
{ {

View File

@ -7,5 +7,6 @@
final class ServerType extends Enum final class ServerType extends Enum
{ {
const REGULAR = 'regular'; const REGULAR = 'regular';
const DATABASE = 'database'; const DATABASE = 'database';
} }

View File

@ -74,11 +74,11 @@ public function connect(bool $sftp = false): void
$login = $this->connection->login($this->user, $this->privateKey); $login = $this->connection->login($this->user, $this->privateKey);
if (! $login) { if (! $login) {
throw new SSHAuthenticationError("Error authenticating"); throw new SSHAuthenticationError('Error authenticating');
} }
} catch (Throwable $e) { } catch (Throwable $e) {
Log::error("Error connecting", [ Log::error('Error connecting', [
"msg" => $e->getMessage() 'msg' => $e->getMessage(),
]); ]);
throw $e; throw $e;
} }

View File

@ -64,6 +64,6 @@ class Kernel extends HttpKernel
'signed' => \App\Http\Middleware\ValidateSignature::class, 'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'server-is-ready' => ServerIsReadyMiddleware::class 'server-is-ready' => ServerIsReadyMiddleware::class,
]; ];
} }

View File

@ -20,9 +20,9 @@ class DatabaseBackupFiles extends Component
public Backup $backup; public Backup $backup;
public string $restoreId = ""; public string $restoreId = '';
public string $restoreDatabaseId = ""; public string $restoreDatabaseId = '';
public int $deleteId; public int $deleteId;
@ -61,7 +61,7 @@ public function delete(): void
public function render(): View public function render(): View
{ {
return view('livewire.databases.database-backup-files', [ return view('livewire.databases.database-backup-files', [
'files' => $this->backup->files()->orderByDesc('id')->simplePaginate(10) 'files' => $this->backup->files()->orderByDesc('id')->simplePaginate(10),
]); ]);
} }
} }

View File

@ -75,7 +75,7 @@ public function render(): View
return view('livewire.databases.database-backups', [ return view('livewire.databases.database-backups', [
'backups' => $this->server->backups, 'backups' => $this->server->backups,
'databases' => $this->server->databases, 'databases' => $this->server->databases,
'files' => $this->files 'files' => $this->files,
]); ]);
} }
} }

View File

@ -21,6 +21,7 @@ public function handle(): void
{ {
if ($this->server->provider()->isRunning()) { if ($this->server->provider()->isRunning()) {
$this->server->install(); $this->server->install();
return; return;
} }
@ -33,6 +34,7 @@ public function handle(): void
'server' => $this->server, 'server' => $this->server,
]) ])
); );
return; return;
} }

View File

@ -5,7 +5,7 @@
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\FirewallRule; use App\Models\FirewallRule;
use App\Models\Service; use App\Models\Service;
use App\SSHCommands\PHPMyAdmin\DeleteNginxPHPMyAdminVHost; use App\SSHCommands\PHPMyAdmin\DeleteNginxPHPMyAdminVHostCommand;
use Exception; use Exception;
use Throwable; use Throwable;
@ -48,7 +48,7 @@ private function removeFirewallRule(): void
private function deleteVHost(): void private function deleteVHost(): void
{ {
$this->service->server->ssh()->exec( $this->service->server->ssh()->exec(
new DeleteNginxPHPMyAdminVHost('/home/vito/phpmyadmin'), new DeleteNginxPHPMyAdminVHostCommand('/home/vito/phpmyadmin'),
'delete-phpmyadmin-vhost' 'delete-phpmyadmin-vhost'
); );
} }

View File

@ -7,7 +7,7 @@
use App\Helpers\SSH; use App\Helpers\SSH;
use App\Jobs\Job; use App\Jobs\Job;
use App\Models\Deployment; use App\Models\Deployment;
use App\SSHCommands\System\RunScript; use App\SSHCommands\System\RunScriptCommand;
use Throwable; use Throwable;
class Deploy extends Job class Deploy extends Job
@ -34,7 +34,7 @@ public function handle(): void
{ {
$this->ssh = $this->deployment->site->server->ssh(); $this->ssh = $this->deployment->site->server->ssh();
$this->ssh->exec( $this->ssh->exec(
new RunScript($this->path, $this->script), new RunScriptCommand($this->path, $this->script),
'deploy', 'deploy',
$this->deployment->site_id $this->deployment->site_id
); );

View File

@ -34,7 +34,7 @@ public function handle(): void
); );
$this->site->save(); $this->site->save();
$this->site->sourceControl()->provider()->deployKey( $this->site->sourceControl()->provider()->deployKey(
$this->site->domain.'-key-' . $this->site->id, $this->site->domain.'-key-'.$this->site->id,
$this->site->repository, $this->site->repository,
$this->site->ssh_key $this->site->ssh_key
); );

View File

@ -15,7 +15,7 @@ public function handle(Broadcast $event): void
{ {
Cache::set('broadcast', [ Cache::set('broadcast', [
'type' => $event->type, 'type' => $event->type,
'data' => $event->data 'data' => $event->data,
], now()->addMinutes(5)); ], now()->addMinutes(5));
} }
} }

View File

@ -110,7 +110,7 @@ public static function boot(): void
static::created(function (Site $site) { static::created(function (Site $site) {
$site->deploymentScript()->create([ $site->deploymentScript()->create([
'name' => 'default', 'name' => 'default',
'content' => '' 'content' => '',
]); ]);
}); });
} }

View File

@ -7,7 +7,6 @@
use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification; use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider class EventServiceProvider extends ServiceProvider
{ {

View File

@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $databa
public function file(): string public function file(): string
{ {
return File::get(resource_path(sprintf("commands/database/%s/backup.sh", $this->provider))); return File::get(resource_path(sprintf('commands/database/%s/backup.sh', $this->provider)));
} }
public function content(): string public function content(): string

View File

@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $name)
public function file(): string public function file(): string
{ {
return File::get(resource_path(sprintf("commands/database/%s/create.sh", $this->provider))); return File::get(resource_path(sprintf('commands/database/%s/create.sh', $this->provider)));
} }
public function content(): string public function content(): string

View File

@ -17,7 +17,7 @@ public function __construct(
public function file(): string public function file(): string
{ {
return File::get(resource_path(sprintf("commands/database/%s/create-user.sh", $this->provider))); return File::get(resource_path(sprintf('commands/database/%s/create-user.sh', $this->provider)));
} }
public function content(): string public function content(): string

View File

@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $name)
public function file(): string public function file(): string
{ {
return File::get(resource_path(sprintf("commands/database/%s/delete.sh", $this->provider))); return File::get(resource_path(sprintf('commands/database/%s/delete.sh', $this->provider)));
} }
public function content(): string public function content(): string

View File

@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $userna
public function file(): string public function file(): string
{ {
return File::get(resource_path(sprintf("commands/database/%s/delete-user.sh", $this->provider))); return File::get(resource_path(sprintf('commands/database/%s/delete-user.sh', $this->provider)));
} }
public function content(): string public function content(): string

View File

@ -17,7 +17,7 @@ public function __construct(
public function file(): string public function file(): string
{ {
return File::get(resource_path(sprintf("commands/database/%s/link.sh", $this->provider))); return File::get(resource_path(sprintf('commands/database/%s/link.sh', $this->provider)));
} }
public function content(): string public function content(): string

View File

@ -13,7 +13,7 @@ public function __construct(protected string $provider, protected string $databa
public function file(): string public function file(): string
{ {
return File::get(resource_path(sprintf("commands/database/%s/restore.sh", $this->provider))); return File::get(resource_path(sprintf('commands/database/%s/restore.sh', $this->provider)));
} }
public function content(): string public function content(): string

View File

@ -16,7 +16,7 @@ public function __construct(
public function file(): string public function file(): string
{ {
return File::get(resource_path(sprintf("commands/database/%s/unlink.sh", $this->provider))); return File::get(resource_path(sprintf('commands/database/%s/unlink.sh', $this->provider)));
} }
public function content(): string public function content(): string

View File

@ -21,6 +21,6 @@ public function __construct(
public function file(): string public function file(): string
{ {
return File::get(resource_path(sprintf("commands/firewall/%s/add-rule.sh", $this->provider))); return File::get(resource_path(sprintf('commands/firewall/%s/add-rule.sh', $this->provider)));
} }
} }

View File

@ -21,6 +21,6 @@ public function __construct(
public function file(): string public function file(): string
{ {
return File::get(resource_path(sprintf("commands/firewall/%s/remove-rule.sh", $this->provider))); return File::get(resource_path(sprintf('commands/firewall/%s/remove-rule.sh', $this->provider)));
} }
} }

View File

@ -4,7 +4,6 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class InstallNginxCommand extends Command class InstallNginxCommand extends Command
{ {

View File

@ -4,7 +4,6 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class InstallPHPCommand extends Command class InstallPHPCommand extends Command
{ {

View File

@ -4,7 +4,6 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class UninstallPHPCommand extends Command class UninstallPHPCommand extends Command
{ {

View File

@ -5,7 +5,7 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
class DeleteNginxPHPMyAdminVHost extends Command class DeleteNginxPHPMyAdminVHostCommand extends Command
{ {
public function __construct(protected string $path) public function __construct(protected string $path)
{ {

View File

@ -17,6 +17,6 @@ public function file(): string
public function content(): string public function content(): string
{ {
return 'sudo rm -rf '.$this->path.'*'."\n"; return 'sudo rm -rf '.$this->path.'*';
} }
} }

View File

@ -5,7 +5,7 @@
use App\SSHCommands\Command; use App\SSHCommands\Command;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
class RunScript extends Command class RunScriptCommand extends Command
{ {
public function __construct(protected string $path, protected string $script) public function __construct(protected string $path, protected string $script)
{ {
@ -20,7 +20,7 @@ public function content(): string
{ {
return str($this->file()) return str($this->file())
->replace('__path__', $this->path) ->replace('__path__', $this->path)
->replace('__script__', make_bash_script($this->script)) ->replace('__script__', $this->script)
->toString(); ->toString();
} }
} }

View File

@ -4,7 +4,6 @@
use App\Enums\OperatingSystem; use App\Enums\OperatingSystem;
use App\Exceptions\CouldNotConnectToProvider; use App\Exceptions\CouldNotConnectToProvider;
use App\Notifications\FailedToDeleteServerFromProvider;
use Aws\Ec2\Ec2Client; use Aws\Ec2\Ec2Client;
use Aws\EC2InstanceConnect\EC2InstanceConnectClient; use Aws\EC2InstanceConnect\EC2InstanceConnectClient;
use Exception; use Exception;

View File

@ -4,7 +4,6 @@
use App\Exceptions\CouldNotConnectToProvider; use App\Exceptions\CouldNotConnectToProvider;
use App\Exceptions\ServerProviderError; use App\Exceptions\ServerProviderError;
use App\Notifications\FailedToDeleteServerFromProvider;
use Exception; use Exception;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;

View File

@ -4,7 +4,6 @@
use App\Exceptions\CouldNotConnectToProvider; use App\Exceptions\CouldNotConnectToProvider;
use App\Exceptions\ServerProviderError; use App\Exceptions\ServerProviderError;
use App\Notifications\FailedToDeleteServerFromProvider;
use Illuminate\Http\Client\Response; use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;

View File

@ -4,7 +4,6 @@
use App\Exceptions\CouldNotConnectToProvider; use App\Exceptions\CouldNotConnectToProvider;
use App\Exceptions\ServerProviderError; use App\Exceptions\ServerProviderError;
use App\Notifications\FailedToDeleteServerFromProvider;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@ -104,7 +103,7 @@ public function create(): void
if (count($errors) > 0) { if (count($errors) > 0) {
$msg = $errors[0]['reason']; $msg = $errors[0]['reason'];
} }
Log::error("Linode error", $errors); Log::error('Linode error', $errors);
throw new ServerProviderError($msg); throw new ServerProviderError($msg);
} }
$this->server->ip = $create->json()['ipv4'][0]; $this->server->ip = $create->json()['ipv4'][0];

View File

@ -4,7 +4,6 @@
use App\Exceptions\CouldNotConnectToProvider; use App\Exceptions\CouldNotConnectToProvider;
use App\Exceptions\ServerProviderError; use App\Exceptions\ServerProviderError;
use App\Notifications\FailedToDeleteServerFromProvider;
use Exception; use Exception;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;

View File

@ -4,9 +4,6 @@
use App\Events\Broadcast; use App\Events\Broadcast;
use App\Jobs\Installation\Initialize; use App\Jobs\Installation\Initialize;
use App\Jobs\Installation\InstallCertbot;
use App\Jobs\Installation\InstallComposer;
use App\Jobs\Installation\InstallNodejs;
use App\Jobs\Installation\InstallRequirements; use App\Jobs\Installation\InstallRequirements;
use App\Jobs\Installation\Upgrade; use App\Jobs\Installation\Upgrade;
use Illuminate\Support\Facades\Bus; use Illuminate\Support\Facades\Bus;

View File

@ -5,9 +5,6 @@
use App\Exceptions\FailedToDeployGitHook; use App\Exceptions\FailedToDeployGitHook;
use App\Exceptions\FailedToDeployGitKey; use App\Exceptions\FailedToDeployGitKey;
use App\Exceptions\FailedToDestroyGitHook; use App\Exceptions\FailedToDestroyGitHook;
use App\Exceptions\RepositoryNotFound;
use App\Exceptions\RepositoryPermissionDenied;
use App\Exceptions\SourceControlIsNotConnected;
use Exception; use Exception;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@ -39,7 +36,7 @@ public function getRepo(string $repo = null): mixed
public function fullRepoUrl(string $repo, string $key): string public function fullRepoUrl(string $repo, string $key): string
{ {
return sprintf("git@bitbucket.org-%s:%s.git", $key, $repo); return sprintf('git@bitbucket.org-%s:%s.git', $key, $repo);
} }
/** /**

View File

@ -2,8 +2,8 @@
namespace App\SourceControlProviders; namespace App\SourceControlProviders;
use App\Exceptions\FailedToDeployGitKey;
use App\Exceptions\FailedToDeployGitHook; use App\Exceptions\FailedToDeployGitHook;
use App\Exceptions\FailedToDeployGitKey;
use App\Exceptions\FailedToDestroyGitHook; use App\Exceptions\FailedToDestroyGitHook;
use Exception; use Exception;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
@ -44,7 +44,7 @@ public function getRepo(string $repo = null): mixed
public function fullRepoUrl(string $repo, string $key): string public function fullRepoUrl(string $repo, string $key): string
{ {
return sprintf("git@github.com-%s:%s.git", $key, $repo); return sprintf('git@github.com-%s:%s.git', $key, $repo);
} }
/** /**

View File

@ -2,8 +2,8 @@
namespace App\SourceControlProviders; namespace App\SourceControlProviders;
use App\Exceptions\FailedToDeployGitKey;
use App\Exceptions\FailedToDeployGitHook; use App\Exceptions\FailedToDeployGitHook;
use App\Exceptions\FailedToDeployGitKey;
use App\Exceptions\FailedToDestroyGitHook; use App\Exceptions\FailedToDestroyGitHook;
use Exception; use Exception;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
@ -36,7 +36,7 @@ public function getRepo(string $repo = null): mixed
public function fullRepoUrl(string $repo, string $key): string public function fullRepoUrl(string $repo, string $key): string
{ {
return sprintf("git@gitlab.com-%s:%s.git", $key, $repo); return sprintf('git@gitlab.com-%s:%s.git', $key, $repo);
} }
/** /**

View File

@ -17,7 +17,7 @@ public function connect(): bool
{ {
$res = Http::withToken($this->storageProvider->credentials['token']) $res = Http::withToken($this->storageProvider->credentials['token'])
->post($this->apiUrl.'/check/user', [ ->post($this->apiUrl.'/check/user', [
'query' => '' 'query' => '',
]); ]);
return $res->successful(); return $res->successful();
@ -40,7 +40,7 @@ public function upload(Server $server, string $src, string $dest): array
$data = json_decode($upload, true); $data = json_decode($upload, true);
if (isset($data['error'])) { if (isset($data['error'])) {
throw new BackupFileException("Failed to upload to Dropbox ".$data['error_summary'] ?? ''); throw new BackupFileException('Failed to upload to Dropbox '.$data['error_summary'] ?? '');
} }
return [ return [

View File

@ -193,7 +193,7 @@
App\Providers\AuthServiceProvider::class, App\Providers\AuthServiceProvider::class,
App\Providers\BroadcastServiceProvider::class, App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class, App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class App\Providers\RouteServiceProvider::class,
], ],
/* /*

View File

@ -25,7 +25,6 @@
use App\ServiceHandlers\Webserver\Nginx; use App\ServiceHandlers\Webserver\Nginx;
use App\SiteTypes\Laravel; use App\SiteTypes\Laravel;
use App\SiteTypes\PHPSite; use App\SiteTypes\PHPSite;
use App\SiteTypes\Wordpress;
use App\SourceControlProviders\Bitbucket; use App\SourceControlProviders\Bitbucket;
use App\SourceControlProviders\Custom; use App\SourceControlProviders\Custom;
use App\SourceControlProviders\Github; use App\SourceControlProviders\Github;
@ -48,7 +47,7 @@
'operating_systems' => [ 'operating_systems' => [
// 'ubuntu_18', // 'ubuntu_18',
'ubuntu_20', 'ubuntu_20',
'ubuntu_22' 'ubuntu_22',
], ],
'webservers' => ['none', 'nginx'], 'webservers' => ['none', 'nginx'],
'php_versions' => [ 'php_versions' => [

View File

@ -13,7 +13,7 @@ public function definition(): array
'type' => 'database', 'type' => 'database',
'interval' => '0 * * * *', 'interval' => '0 * * * *',
'keep_backups' => 10, 'keep_backups' => 10,
'status' => BackupStatus::RUNNING 'status' => BackupStatus::RUNNING,
]; ];
} }
} }

View File

@ -2,7 +2,6 @@
namespace Database\Factories; namespace Database\Factories;
use App\Enums\LogType;
use App\Models\ServerLog; use App\Models\ServerLog;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;

View File

@ -2,10 +2,8 @@
namespace Database\Factories; namespace Database\Factories;
use App\Models\Server;
use App\Models\Service; use App\Models\Service;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
class ServiceFactory extends Factory class ServiceFactory extends Factory
{ {

View File

@ -20,7 +20,7 @@ public function definition(): array
'status' => 'ready', 'status' => 'ready',
'progress' => '100', 'progress' => '100',
'php_version' => '8.2', 'php_version' => '8.2',
'branch' => 'main' 'branch' => 'main',
]; ];
} }
} }

View File

@ -4,7 +4,6 @@
use App\Models\SshKey; use App\Models\SshKey;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Carbon;
class SshKeyFactory extends Factory class SshKeyFactory extends Factory
{ {

View File

@ -3,7 +3,8 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
return new class extends Migration { return new class extends Migration
{
public function up(): void public function up(): void
{ {
DB::statement('ALTER TABLE firewall_rules MODIFY mask varchar(10) null'); DB::statement('ALTER TABLE firewall_rules MODIFY mask varchar(10) null');

View File

@ -4,7 +4,8 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration
{
public function up(): void public function up(): void
{ {
Schema::table('sites', function (Blueprint $table) { Schema::table('sites', function (Blueprint $table) {

View File

@ -4,7 +4,8 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration
{
public function up(): void public function up(): void
{ {
Schema::table('source_controls', function (Blueprint $table) { Schema::table('source_controls', function (Blueprint $table) {

View File

@ -4,7 +4,8 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration
{
public function up(): void public function up(): void
{ {
Schema::table('source_controls', function (Blueprint $table) { Schema::table('source_controls', function (Blueprint $table) {

View File

@ -4,7 +4,8 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration
{
public function up(): void public function up(): void
{ {
Schema::table('sites', function (Blueprint $table) { Schema::table('sites', function (Blueprint $table) {

View File

@ -4,7 +4,8 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration
{
public function up(): void public function up(): void
{ {
Schema::table('storage_providers', function (Blueprint $table) { Schema::table('storage_providers', function (Blueprint $table) {

View File

@ -4,7 +4,8 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration
{
public function up(): void public function up(): void
{ {
Schema::table('backups', function (Blueprint $table) { Schema::table('backups', function (Blueprint $table) {

View File

@ -4,7 +4,8 @@
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
return new class extends Migration { return new class extends Migration
{
public function up(): void public function up(): void
{ {
Schema::table('backup_files', function (Blueprint $table) { Schema::table('backup_files', function (Blueprint $table) {

View File

@ -21,13 +21,13 @@ public function run(): void
'email' => 'user@example.com', 'email' => 'user@example.com',
]); ]);
$server = Server::factory()->create([ $server = Server::factory()->create([
'user_id' => $user->id 'user_id' => $user->id,
]); ]);
$server->services()->create([ $server->services()->create([
'type' => 'database', 'type' => 'database',
'name' => config('core.databases_name.mysql80'), 'name' => config('core.databases_name.mysql80'),
'version' => config('core.databases_version.mysql80'), 'version' => config('core.databases_version.mysql80'),
'status' => ServiceStatus::READY 'status' => ServiceStatus::READY,
]); ]);
$server->services()->create([ $server->services()->create([
'type' => 'php', 'type' => 'php',
@ -36,17 +36,17 @@ public function run(): void
], ],
'name' => 'php', 'name' => 'php',
'version' => '8.1', 'version' => '8.1',
'status' => ServiceStatus::READY 'status' => ServiceStatus::READY,
]); ]);
$server->services()->create([ $server->services()->create([
'type' => 'webserver', 'type' => 'webserver',
'name' => 'nginx', 'name' => 'nginx',
'version' => 'latest', 'version' => 'latest',
'status' => ServiceStatus::READY 'status' => ServiceStatus::READY,
]); ]);
Site::factory()->create([ Site::factory()->create([
'server_id' => $server->id, 'server_id' => $server->id,
'type' => SiteType::LARAVEL 'type' => SiteType::LARAVEL,
]); ]);
} }
} }

View File

@ -6,6 +6,6 @@ if ! sudo ln -s /usr/bin/php__version__ /usr/bin/php; then
echo 'VITO_SSH_ERROR' && exit 1 echo 'VITO_SSH_ERROR' && exit 1
fi fi
echo "Default php is: \n" echo "Default php is: "
php -v php -v

View File

@ -2,4 +2,6 @@ if ! cd __path__; then
echo 'VITO_SSH_ERROR' && exit 1 echo 'VITO_SSH_ERROR' && exit 1
fi fi
__script__ if ! __script__; then
echo 'VITO_SSH_ERROR' && exit 1
fi

View File

@ -23,7 +23,7 @@ public function test_visit_application()
$this->get( $this->get(
route('servers.sites.show', [ route('servers.sites.show', [
'server' => $this->server, 'server' => $this->server,
'site' => $this->site 'site' => $this->site,
]) ])
) )
->assertOk() ->assertOk()
@ -44,7 +44,7 @@ public function test_update_deployment_script()
$this->assertDatabaseHas('deployment_scripts', [ $this->assertDatabaseHas('deployment_scripts', [
'site_id' => $this->site->id, 'site_id' => $this->site->id,
'content' => 'some script' 'content' => 'some script',
]); ]);
$this->site->refresh(); $this->site->refresh();

View File

@ -58,7 +58,7 @@ public function test_create_cronjob()
'command' => 'ls -la', 'command' => 'ls -la',
'user' => 'vito', 'user' => 'vito',
'frequency' => '* * * * *', 'frequency' => '* * * * *',
'status' => CronjobStatus::CREATING 'status' => CronjobStatus::CREATING,
]); ]);
} }
} }

View File

@ -32,7 +32,7 @@ public function test_create_backup(): void
$storage = StorageProvider::factory()->create([ $storage = StorageProvider::factory()->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'provider' => \App\Enums\StorageProvider::DROPBOX 'provider' => \App\Enums\StorageProvider::DROPBOX,
]); ]);
Livewire::test(DatabaseBackups::class, ['server' => $this->server]) Livewire::test(DatabaseBackups::class, ['server' => $this->server])
@ -60,7 +60,7 @@ public function test_see_backups_list(): void
$storage = StorageProvider::factory()->create([ $storage = StorageProvider::factory()->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'provider' => \App\Enums\StorageProvider::DROPBOX 'provider' => \App\Enums\StorageProvider::DROPBOX,
]); ]);
$backup = Backup::factory()->create([ $backup = Backup::factory()->create([
@ -85,7 +85,7 @@ public function test_delete_database(): void
$storage = StorageProvider::factory()->create([ $storage = StorageProvider::factory()->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'provider' => \App\Enums\StorageProvider::DROPBOX 'provider' => \App\Enums\StorageProvider::DROPBOX,
]); ]);
$backup = Backup::factory()->create([ $backup = Backup::factory()->create([

View File

@ -35,7 +35,7 @@ public function test_create_firewall_rule(): void
Bus::assertDispatched(AddToServer::class); Bus::assertDispatched(AddToServer::class);
$this->assertDatabaseHas('firewall_rules', [ $this->assertDatabaseHas('firewall_rules', [
'port' => '1234' 'port' => '1234',
]); ]);
} }
@ -44,7 +44,7 @@ public function test_see_firewall_rules(): void
$this->actingAs($this->user); $this->actingAs($this->user);
$rule = FirewallRule::factory()->create([ $rule = FirewallRule::factory()->create([
'server_id' => $this->server->id 'server_id' => $this->server->id,
]); ]);
Livewire::test(FirewallRulesList::class, ['server' => $this->server]) Livewire::test(FirewallRulesList::class, ['server' => $this->server])
@ -61,7 +61,7 @@ public function test_delete_firewall_rule(): void
$this->actingAs($this->user); $this->actingAs($this->user);
$rule = FirewallRule::factory()->create([ $rule = FirewallRule::factory()->create([
'server_id' => $this->server->id 'server_id' => $this->server->id,
]); ]);
Livewire::test(FirewallRulesList::class, ['server' => $this->server]) Livewire::test(FirewallRulesList::class, ['server' => $this->server])
@ -73,7 +73,7 @@ public function test_delete_firewall_rule(): void
$this->assertDatabaseHas('firewall_rules', [ $this->assertDatabaseHas('firewall_rules', [
'id' => $rule->id, 'id' => $rule->id,
'status' => FirewallRuleStatus::DELETING 'status' => FirewallRuleStatus::DELETING,
]); ]);
} }
} }

View File

@ -59,7 +59,7 @@ public function test_change_default_php_cli(): void
], ],
'name' => 'php', 'name' => 'php',
'version' => '8.1', 'version' => '8.1',
'status' => ServiceStatus::READY 'status' => ServiceStatus::READY,
]); ]);
Livewire::test(DefaultCli::class, ['server' => $this->server]) Livewire::test(DefaultCli::class, ['server' => $this->server])

View File

@ -63,7 +63,7 @@ public function test_create_queue()
'auto_start' => 1, 'auto_start' => 1,
'auto_restart' => 1, 'auto_restart' => 1,
'numprocs' => 1, 'numprocs' => 1,
'status' => QueueStatus::CREATING 'status' => QueueStatus::CREATING,
]); ]);
} }
} }

View File

@ -56,7 +56,7 @@ public function test_delete_ssh_key()
$this->assertDatabaseHas('server_ssh_keys', [ $this->assertDatabaseHas('server_ssh_keys', [
'server_id' => $this->server->id, 'server_id' => $this->server->id,
'ssh_key_id' => $sshKey->id, 'ssh_key_id' => $sshKey->id,
'status' => SshKeyStatus::DELETING 'status' => SshKeyStatus::DELETING,
]); ]);
Bus::assertDispatched(DeleteSshKeyFromServer::class); Bus::assertDispatched(DeleteSshKeyFromServer::class);
@ -77,7 +77,7 @@ public function test_add_new_ssh_key()
$this->assertDatabaseHas('server_ssh_keys', [ $this->assertDatabaseHas('server_ssh_keys', [
'server_id' => $this->server->id, 'server_id' => $this->server->id,
'status' => SshKeyStatus::ADDING 'status' => SshKeyStatus::ADDING,
]); ]);
Bus::assertDispatched(DeploySshKeyToServer::class); Bus::assertDispatched(DeploySshKeyToServer::class);
@ -103,7 +103,7 @@ public function test_add_existing_key()
$this->assertDatabaseHas('server_ssh_keys', [ $this->assertDatabaseHas('server_ssh_keys', [
'server_id' => $this->server->id, 'server_id' => $this->server->id,
'status' => SshKeyStatus::ADDING 'status' => SshKeyStatus::ADDING,
]); ]);
Bus::assertDispatched(DeploySshKeyToServer::class); Bus::assertDispatched(DeploySshKeyToServer::class);

View File

@ -25,7 +25,7 @@ public function test_see_services_list(): void
'supervisor', 'supervisor',
'redis', 'redis',
'ufw', 'ufw',
'php' 'php',
]); ]);
} }

View File

@ -2,10 +2,7 @@
namespace Tests\Feature\Http; namespace Tests\Feature\Http;
use App\Http\Livewire\SourceControls\Bitbucket;
use App\Http\Livewire\SourceControls\Connect; use App\Http\Livewire\SourceControls\Connect;
use App\Http\Livewire\SourceControls\Github;
use App\Http\Livewire\SourceControls\Gitlab;
use App\Http\Livewire\SourceControls\SourceControlsList; use App\Http\Livewire\SourceControls\SourceControlsList;
use App\Models\SourceControl; use App\Models\SourceControl;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
@ -48,7 +45,7 @@ public function test_delete_provider(string $provider): void
/** @var SourceControl $sourceControl */ /** @var SourceControl $sourceControl */
$sourceControl = SourceControl::factory()->create([ $sourceControl = SourceControl::factory()->create([
'provider' => $provider, 'provider' => $provider,
'profile' => 'test' 'profile' => 'test',
]); ]);
Livewire::test(SourceControlsList::class) Livewire::test(SourceControlsList::class)

View File

@ -3,8 +3,8 @@
namespace Tests\Feature\Http; namespace Tests\Feature\Http;
use App\Enums\StorageProvider; use App\Enums\StorageProvider;
use App\Http\Livewire\StorageProviders\ProvidersList;
use App\Http\Livewire\StorageProviders\ConnectProvider; use App\Http\Livewire\StorageProviders\ConnectProvider;
use App\Http\Livewire\StorageProviders\ProvidersList;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Livewire\Livewire; use Livewire\Livewire;
@ -39,7 +39,7 @@ public function test_see_providers_list(): void
$provider = \App\Models\StorageProvider::factory()->create([ $provider = \App\Models\StorageProvider::factory()->create([
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'provider' => StorageProvider::DROPBOX 'provider' => StorageProvider::DROPBOX,
]); ]);
Livewire::test(ProvidersList::class) Livewire::test(ProvidersList::class)

View File

@ -0,0 +1,18 @@
<?php
namespace Tests\Feature\SSHCommands\CronJob;
use App\SSHCommands\CronJob\UpdateCronJobsCommand;
use Tests\TestCase;
class UpdateCronJobsCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new UpdateCronJobsCommand('vito', 'ls -la');
$this->assertStringContainsString("echo 'ls -la' | sudo -u vito crontab -;", $command->content());
$this->assertStringContainsString('sudo -u vito crontab -l;', $command->content());
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Tests\Feature\SSHCommands\Database;
use App\SSHCommands\Database\BackupDatabaseCommand;
use Tests\TestCase;
class BackupDatabaseCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new BackupDatabaseCommand('mysql', 'test', 'test');
$this->assertStringContainsString('sudo DEBIAN_FRONTEND=noninteractive mysqldump -u root test > test.sql;', $command->content());
$this->assertStringContainsString('DEBIAN_FRONTEND=noninteractive zip test.zip test.sql;', $command->content());
$this->assertStringContainsString('rm test.sql;', $command->content());
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Tests\Feature\SSHCommands\Database;
use App\SSHCommands\Database\CreateCommand;
use Tests\TestCase;
class CreateCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new CreateCommand('mysql', 'test');
$this->assertStringContainsString('sudo mysql -e "CREATE DATABASE IF NOT EXISTS test CHARACTER SET utf8 COLLATE utf8_general_ci";', $command->content());
$this->assertStringContainsString('echo "Command executed"', $command->content());
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Tests\Feature\SSHCommands\Database;
use App\SSHCommands\Database\CreateUserCommand;
use Tests\TestCase;
class CreateUserCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new CreateUserCommand('mysql', 'user', 'password', '%');
$this->assertStringContainsString('sudo mysql -e "CREATE USER IF NOT EXISTS \'user\'@\'%\' IDENTIFIED BY \'password\'";', $command->content());
$this->assertStringContainsString('sudo mysql -e "FLUSH PRIVILEGES";', $command->content());
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace Tests\Feature\SSHCommands\Database;
use App\SSHCommands\Database\DeleteCommand;
use Tests\TestCase;
class DeleteCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new DeleteCommand('mysql', 'test');
$this->assertStringContainsString('sudo mysql -e "DROP DATABASE IF EXISTS test";', $command->content());
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Tests\Feature\SSHCommands\Database;
use App\SSHCommands\Database\DeleteUserCommand;
use Tests\TestCase;
class DeleteUserCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new DeleteUserCommand('mysql', 'user', '%');
$this->assertStringContainsString('sudo mysql -e "DROP USER IF EXISTS \'user\'@\'%\'";', $command->content());
$this->assertStringContainsString('sudo mysql -e "FLUSH PRIVILEGES";', $command->content());
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Tests\Feature\SSHCommands\Database;
use App\SSHCommands\Database\InstallMariadbCommand;
use Tests\TestCase;
class InstallMariadbCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new InstallMariadbCommand();
$expected = <<<EOD
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
sudo DEBIAN_FRONTEND=noninteractive ./mariadb_repo_setup \
--mariadb-server-version="mariadb-10.3"
sudo DEBIAN_FRONTEND=noninteractive apt update
sudo DEBIAN_FRONTEND=noninteractive apt install mariadb-server mariadb-backup -y
sudo service mysql start
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace Tests\Feature\SSHCommands\Database;
use App\SSHCommands\Database\InstallMysqlCommand;
use Tests\TestCase;
class InstallMysqlCommandTest extends TestCase
{
public function test_generate_command_mysql8()
{
$command = new InstallMysqlCommand('8.0');
$expected = <<<'EOD'
wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb
sudo DEBIAN_FRONTEND=noninteractive dpkg -i mysql-apt-config_0.8.22-1_all.deb
sudo DEBIAN_FRONTEND=noninteractive apt update
sudo DEBIAN_FRONTEND=noninteractive apt install mysql-server -y
sudo service mysql enable
sudo service mysql start
if ! sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
EOD;
$this->assertStringContainsString($expected, $command->content());
}
public function test_generate_command_mysql5()
{
$command = new InstallMysqlCommand('5.7');
$expected = <<<'EOD'
sudo DEBIAN_FRONTEND=noninteractive apt install mysql-server -y
sudo service mysql enable
sudo service mysql start
if ! sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace Tests\Feature\SSHCommands\Database;
use App\SSHCommands\Database\LinkCommand;
use Tests\TestCase;
class LinkCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new LinkCommand('mysql', 'user', '%', 'test');
$expected = <<<'EOD'
if ! sudo mysql -e "GRANT ALL PRIVILEGES ON test.* TO 'user'@'%'"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo mysql -e "FLUSH PRIVILEGES"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Linking to test finished"
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Tests\Feature\SSHCommands\Database;
use App\SSHCommands\Database\UnlinkCommand;
use Tests\TestCase;
class UnlinkCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new UnlinkCommand('mysql', 'user', '%');
$expected = <<<'EOD'
if ! sudo mysql -e "REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'user'@'%'"; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Command executed"
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Tests\Feature\SSHCommands\Firewall;
use App\SSHCommands\Firewall\AddRuleCommand;
use Tests\TestCase;
class AddRuleCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new AddRuleCommand('ufw', 'allow', 'tcp', '1080', '0.0.0.0', '0');
$expected = <<<'EOD'
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 1080; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw reload; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service ufw restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace Tests\Feature\SSHCommands\Firewall;
use App\SSHCommands\Firewall\InstallUfwCommand;
use Tests\TestCase;
class InstallUfwCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new InstallUfwCommand();
$expected = <<<'EOD'
if ! sudo ufw default deny incoming; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw default allow outgoing; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 22; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 80; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw allow from 0.0.0.0/0 to any proto tcp port 443; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw --force enable; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw reload; then
echo 'VITO_SSH_ERROR' && exit 1
fi
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Tests\Feature\SSHCommands\Firewall;
use App\SSHCommands\Firewall\RemoveRuleCommand;
use Tests\TestCase;
class RemoveRuleCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new RemoveRuleCommand('ufw', 'allow', 'tcp', '1080', '0.0.0.0', '0');
$expected = <<<'EOD'
if ! sudo ufw delete allow from 0.0.0.0/0 to any proto tcp port 1080; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ufw reload; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service ufw restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Tests\Feature\SSHCommands\Installation;
use App\SSHCommands\Installation\InstallNodejsCommand;
use Tests\TestCase;
class InstallNodejsCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new InstallNodejsCommand();
$expected = <<<'EOD'
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -;
sudo DEBIAN_FRONTEND=noninteractive apt update
sudo DEBIAN_FRONTEND=noninteractive apt install nodejs -y
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Tests\Feature\SSHCommands\Installation;
use App\SSHCommands\Installation\InstallRedisCommand;
use Tests\TestCase;
class InstallRedisCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new InstallRedisCommand();
$expected = <<<'EOD'
sudo DEBIAN_FRONTEND=noninteractive apt install redis-server -y
sudo sed -i 's/bind 127.0.0.1 ::1/bind 0.0.0.0/g' /etc/redis/redis.conf
sudo service redis enable
sudo service redis start
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace Tests\Feature\SSHCommands\Installation;
use App\SSHCommands\Installation\InstallRequirementsCommand;
use Tests\TestCase;
class InstallRequirementsCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new InstallRequirementsCommand('user@example.com', 'user');
$expected = <<<'EOD'
sudo DEBIAN_FRONTEND=noninteractive apt install -y software-properties-common curl zip unzip git gcc
git config --global user.email "user@example.com"
git config --global user.name "user"
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace Tests\Feature\SSHCommands\Nginx;
use App\SSHCommands\Nginx\ChangeNginxPHPVersionCommand;
use Tests\TestCase;
class ChangeNginxPHPVersionCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new ChangeNginxPHPVersionCommand('example.com', '7.1', '8.2');
$expected = <<<'EOD'
if ! sudo sed -i 's/php7.1/php8.2/g' /etc/nginx/sites-available/example.com; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service nginx restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "PHP Version Changed to 8.2"
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace Tests\Feature\SSHCommands\Nginx;
use App\SSHCommands\Nginx\CreateNginxVHostCommand;
use Tests\TestCase;
class CreateNginxVHostCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new CreateNginxVHostCommand('example.com', '/home/vito/example.com', '__the__vhost__');
$expected = <<<'EOD'
if ! rm -rf /home/vito/example.com; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! mkdir /home/vito/example.com; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo chown -R 755 /home/vito/example.com; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! echo '' | sudo tee /etc/nginx/conf.d/example.com_redirects; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! echo '__the__vhost__' | sudo tee /etc/nginx/sites-available/example.com; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service nginx restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Tests\Feature\SSHCommands\Nginx;
use App\SSHCommands\Nginx\DeleteNginxSiteCommand;
use Tests\TestCase;
class DeleteNginxSiteCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new DeleteNginxSiteCommand('example.com', '/home/vito/example.com');
$expected = <<<'EOD'
rm -rf /home/vito/example.com
sudo rm /etc/nginx/sites-available/example.com
sudo rm /etc/nginx/sites-enabled/example.com
echo "Site deleted"
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,115 @@
<?php
namespace Tests\Feature\SSHCommands\Nginx;
use App\SSHCommands\Nginx\InstallNginxCommand;
use Tests\TestCase;
class InstallNginxCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new InstallNginxCommand();
$nginxConfig = <<<'EOD'
user vito;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
EOD;
$expected = <<<EOD
sudo DEBIAN_FRONTEND=noninteractive apt install nginx -y
if ! echo '$nginxConfig' | sudo tee /etc/nginx/nginx.conf; then
echo 'VITO_SSH_ERROR' && exit 1
fi
sudo service nginx start
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Tests\Feature\SSHCommands\Nginx;
use App\SSHCommands\Nginx\UpdateNginxRedirectsCommand;
use Tests\TestCase;
class UpdateNginxRedirectsCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new UpdateNginxRedirectsCommand('example.com', '__redirects__');
$expected = <<<'EOD'
if ! echo '__redirects__' | sudo tee /etc/nginx/conf.d/example.com_redirects; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service nginx restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Tests\Feature\SSHCommands\Nginx;
use App\SSHCommands\Nginx\UpdateNginxVHostCommand;
use Tests\TestCase;
class UpdateNginxVHostCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new UpdateNginxVHostCommand('example.com', '/home/vito/example.com', '__vhost__');
$expected = <<<'EOD'
if ! echo '__vhost__' | sudo tee /etc/nginx/sites-available/example.com; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo service nginx restart; then
echo 'VITO_SSH_ERROR' && exit 1
fi
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Tests\Feature\SSHCommands\PHP;
use App\SSHCommands\PHP\ChangeDefaultPHPCommand;
use Tests\TestCase;
class ChangeDefaultPHPCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new ChangeDefaultPHPCommand('8.2');
$expected = <<<'EOD'
if ! sudo rm /usr/bin/php; then
echo 'VITO_SSH_ERROR' && exit 1
fi
if ! sudo ln -s /usr/bin/php8.2 /usr/bin/php; then
echo 'VITO_SSH_ERROR' && exit 1
fi
echo "Default php is: "
php -v
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Tests\Feature\SSHCommands\PHP;
use App\SSHCommands\PHP\GetPHPIniCommand;
use Tests\TestCase;
class GetPHPIniCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new GetPHPIniCommand('8.2');
$expected = <<<'EOD'
cat /etc/php/8.2/cli/php.ini
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Tests\Feature\SSHCommands\PHP;
use App\SSHCommands\PHP\InstallComposerCommand;
use Tests\TestCase;
class InstallComposerCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new InstallComposerCommand();
$expected = <<<'EOD'
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Tests\Feature\SSHCommands\PHP;
use App\SSHCommands\PHP\InstallPHPCommand;
use Tests\TestCase;
class InstallPHPCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new InstallPHPCommand('8.1');
$expected = <<<'EOD'
sudo add-apt-repository ppa:ondrej/php -y
sudo DEBIAN_FRONTEND=noninteractive apt update
sudo DEBIAN_FRONTEND=noninteractive apt install -y php8.1 php8.1-fpm php8.1-mbstring php8.1-mysql php8.1-mcrypt php8.1-gd php8.1-xml php8.1-curl php8.1-gettext php8.1-zip php8.1-bcmath php8.1-soap php8.1-redis
if ! sudo sed -i 's/www-data/vito/g' /etc/php/8.1/fpm/pool.d/www.conf; then
echo 'VITO_SSH_ERROR' && exit 1
fi
sudo service php8.1-fpm enable
sudo service php8.1-fpm start
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Tests\Feature\SSHCommands\PHP;
use App\SSHCommands\PHP\InstallPHPExtensionCommand;
use Tests\TestCase;
class InstallPHPExtensionCommandTest extends TestCase
{
public function test_generate_command()
{
$command = new InstallPHPExtensionCommand('8.1', 'imagick');
$expected = <<<'EOD'
sudo apt install -y php8.1-imagick
sudo service php8.1-fpm restart
php8.1 -m
EOD;
$this->assertStringContainsString($expected, $command->content());
}
}

Some files were not shown because too many files have changed in this diff Show More