From 7949165648c86602fb3fa608cd32a72de6fb8450 Mon Sep 17 00:00:00 2001 From: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com> Date: Mon, 18 Mar 2024 17:17:45 +0100 Subject: [PATCH] fix custom ssl creation (#122) --- app/Actions/SSL/CreateSSL.php | 3 ++- .../scripts/nginx/create-custom-ssl.sh | 6 ++--- .../views/ssls/partials/create-ssl.blade.php | 22 ++++++++++++++-- tests/Feature/SslTest.php | 25 ++++++++++++++++++- 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/app/Actions/SSL/CreateSSL.php b/app/Actions/SSL/CreateSSL.php index 15f771b..3835659 100644 --- a/app/Actions/SSL/CreateSSL.php +++ b/app/Actions/SSL/CreateSSL.php @@ -24,7 +24,7 @@ public function create(Site $site, array $input): void 'type' => $input['type'], 'certificate' => $input['certificate'] ?? null, 'pk' => $input['private'] ?? null, - 'expires_at' => $input['type'] === SslType::LETSENCRYPT ? now()->addMonths(3) : null, + 'expires_at' => $input['type'] === SslType::LETSENCRYPT ? now()->addMonths(3) : $input['expires_at'], 'status' => SslStatus::CREATING, ]); $ssl->save(); @@ -53,6 +53,7 @@ protected function validate(array $input): void if (isset($input['type']) && $input['type'] == SslType::CUSTOM) { $rules['certificate'] = 'required'; $rules['private'] = 'required'; + $rules['expires_at'] = 'required|date_format:Y-m-d|after_or_equal:'.now(); } Validator::make($input, $rules)->validate(); diff --git a/app/SSH/Services/Webserver/scripts/nginx/create-custom-ssl.sh b/app/SSH/Services/Webserver/scripts/nginx/create-custom-ssl.sh index aaa44fa..fb2a156 100644 --- a/app/SSH/Services/Webserver/scripts/nginx/create-custom-ssl.sh +++ b/app/SSH/Services/Webserver/scripts/nginx/create-custom-ssl.sh @@ -1,12 +1,12 @@ -if ! sudo mkdir __path__; then +if ! sudo mkdir -p __path__; then echo 'VITO_SSH_ERROR' && exit 1 fi -if ! echo __certificate__ | sudo tee __certificate_path__; then +if ! echo "__certificate__" | sudo tee __certificate_path__; then echo 'VITO_SSH_ERROR' && exit 1 fi -if ! echo __pk__ | sudo tee __pk_path__; then +if ! echo "__pk__" | sudo tee __pk_path__; then echo 'VITO_SSH_ERROR' && exit 1 fi diff --git a/resources/views/ssls/partials/create-ssl.blade.php b/resources/views/ssls/partials/create-ssl.blade.php index 4c57f87..82e5585 100644 --- a/resources/views/ssls/partials/create-ssl.blade.php +++ b/resources/views/ssls/partials/create-ssl.blade.php @@ -42,7 +42,9 @@ class="p-6" type="text" class="mt-1 w-full" rows="5" - /> + > + {{ old("certificate") }} + @error("certificate") @enderror @@ -57,11 +59,27 @@ class="mt-1 w-full" type="text" class="mt-1 w-full" rows="5" - /> + > + {{ old("private") }} + @error("private") @enderror + +
+ + + @error("expires_at") + + @enderror +
diff --git a/tests/Feature/SslTest.php b/tests/Feature/SslTest.php index 5113304..0358ef3 100644 --- a/tests/Feature/SslTest.php +++ b/tests/Feature/SslTest.php @@ -41,7 +41,7 @@ public function test_see_ssls_list_with_no_ssls() ->assertSeeText(__("You don't have any SSL certificates yet!")); } - public function test_create_ssl() + public function test_letsencrypt_ssl() { SSH::fake('Successfully received certificate'); @@ -61,6 +61,29 @@ public function test_create_ssl() ]); } + public function test_custom_ssl() + { + SSH::fake('Successfully received certificate'); + + $this->actingAs($this->user); + + $this->post(route('servers.sites.ssl.store', [ + 'server' => $this->server, + 'site' => $this->site, + ]), [ + 'type' => SslType::CUSTOM, + 'certificate' => 'certificate', + 'private' => 'private', + 'expires_at' => now()->addYear()->format('Y-m-d'), + ])->assertSessionDoesntHaveErrors(); + + $this->assertDatabaseHas('ssls', [ + 'site_id' => $this->site->id, + 'type' => SslType::CUSTOM, + 'status' => SslStatus::CREATED, + ]); + } + public function test_delete_ssl() { SSH::fake();