diff --git a/src/SslCertificationExpiredCheck.php b/src/SslCertificationExpiredCheck.php index 3dddd63..b807049 100644 --- a/src/SslCertificationExpiredCheck.php +++ b/src/SslCertificationExpiredCheck.php @@ -4,6 +4,7 @@ namespace VictoRD11\SslCertificationHealthCheck; +use Carbon\Carbon; use Spatie\Health\Checks\Check; use Spatie\Health\Checks\Result; use Spatie\SslCertificate\SslCertificate; @@ -60,8 +61,8 @@ public function run(): Result throw InvalidUrl::make(); } - $certificate = SslCertificate::createForHostName($this->url); - $daysUntilExpired = $certificate->expirationDate()->diffInDays(); + $certificate = SslCertificate::createForHostName($this->url, 30, false); + $daysUntilExpired = Carbon::now()->diffInDays($certificate->expirationDate(), false); $result = Result::make() ->meta(['days_until_expired' => $daysUntilExpired]) diff --git a/tests/SslCertificationExpiredCheckTest.php b/tests/SslCertificationExpiredCheckTest.php index 89bd293..d7a3585 100644 --- a/tests/SslCertificationExpiredCheckTest.php +++ b/tests/SslCertificationExpiredCheckTest.php @@ -16,7 +16,7 @@ expect($result->status)->toBe(Status::ok()); }); -it('certification is expired with warning', function () { +it('certification will expire with warning', function () { $result = SslCertificationExpiredCheck::new() ->url('google.com') ->warnWhenSslCertificationExpiringDay(9999) @@ -25,7 +25,7 @@ expect($result->status)->toBe(Status::warning()); }); -it('certification is expired with fail', function () { +it('certification will expire with fail', function () { $result = SslCertificationExpiredCheck::new() ->url('google.com') ->failWhenSslCertificationExpiringDay(9999) @@ -33,3 +33,11 @@ expect($result->status)->toBe(Status::failed()); }); + +it('certification is expired with fail', function () { + $result = SslCertificationExpiredCheck::new() + ->url('expired.badssl.com') + ->run(); + + expect($result->status)->toBe(Status::failed()); +});