Compare commits
3 Commits
c398ff843d
...
285d25223e
| Author | SHA1 | Date | |
|---|---|---|---|
| 285d25223e | |||
| d88e35b965 | |||
| b0aa64053b |
@@ -439,15 +439,14 @@ sub check_url_reachable_async {
|
|||||||
|
|
||||||
sub check_ssl_certificate {
|
sub check_ssl_certificate {
|
||||||
my ( $self, $url ) = @_;
|
my ( $self, $url ) = @_;
|
||||||
|
return Mojo::Promise->resolve(1) unless defined $url && length $url;
|
||||||
return Mojo::Promise->reject('URL is required')
|
|
||||||
unless defined $url && length($url) > 0;
|
|
||||||
|
|
||||||
my $parsed = $self->_parse_url($url);
|
my $parsed = $self->_parse_url($url);
|
||||||
return Mojo::Promise->resolve(1)
|
return Mojo::Promise->resolve(1)
|
||||||
unless $parsed && $parsed->scheme && $parsed->scheme eq 'https';
|
unless $parsed && $parsed->scheme && $parsed->scheme eq 'https';
|
||||||
|
|
||||||
return $self->ua->head_p($url)->then( sub { return 1; } )->catch(
|
$self->_fire_and_forget(
|
||||||
|
$self->ua->head_p($url)->then( sub { return 1; } )->catch(
|
||||||
sub {
|
sub {
|
||||||
my $err = shift;
|
my $err = shift;
|
||||||
my $err_str = "$err";
|
my $err_str = "$err";
|
||||||
@@ -461,13 +460,9 @@ sub check_ssl_certificate {
|
|||||||
return Mojo::Promise->reject(
|
return Mojo::Promise->reject(
|
||||||
$self->_format_error_message( $error_type, $err_str ) );
|
$self->_format_error_message( $error_type, $err_str ) );
|
||||||
}
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
sub check_ssl_certificate_async {
|
|
||||||
my ( $self, $url ) = @_;
|
|
||||||
return Mojo::Promise->resolve(1) unless defined $url && length $url;
|
|
||||||
$self->_fire_and_forget( $self->check_ssl_certificate($url) );
|
|
||||||
return Mojo::Promise->resolve(1);
|
return Mojo::Promise->resolve(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -507,7 +502,7 @@ sub validate_url_with_checks {
|
|||||||
|
|
||||||
my $ssl_check =
|
my $ssl_check =
|
||||||
$parsed->scheme eq 'https'
|
$parsed->scheme eq 'https'
|
||||||
? $self->check_ssl_certificate_async($normalized)
|
? $self->check_ssl_certificate($normalized)
|
||||||
: Mojo::Promise->resolve(1);
|
: Mojo::Promise->resolve(1);
|
||||||
|
|
||||||
return $ssl_check->then(
|
return $ssl_check->then(
|
||||||
|
|||||||
@@ -542,8 +542,8 @@ subtest 'check_ssl_certificate - SSL error' => sub {
|
|||||||
my ( $result, $error ) =
|
my ( $result, $error ) =
|
||||||
wait_promise( $validator->check_ssl_certificate('https://example.com') );
|
wait_promise( $validator->check_ssl_certificate('https://example.com') );
|
||||||
|
|
||||||
is( $result, undef, 'SSL error has no result' );
|
is( $result, 1, 'SSL error is async' );
|
||||||
like( $error, qr/Invalid SSL certificate/, 'SSL error is detected' );
|
is( $error, undef, 'SSL error has no error' );
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'check_ssl_certificate - non-SSL error' => sub {
|
subtest 'check_ssl_certificate - non-SSL error' => sub {
|
||||||
@@ -551,8 +551,8 @@ subtest 'check_ssl_certificate - non-SSL error' => sub {
|
|||||||
my ( $result, $error ) =
|
my ( $result, $error ) =
|
||||||
wait_promise( $validator->check_ssl_certificate('https://example.com') );
|
wait_promise( $validator->check_ssl_certificate('https://example.com') );
|
||||||
|
|
||||||
is( $result, undef, 'non-SSL error has no result' );
|
is( $result, 1, 'non-SSL error is async' );
|
||||||
like( $error, qr/Cannot reach URL/, 'non-SSL error is classified' );
|
is( $error, undef, 'non-SSL error has no error' );
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'check_ssl_certificate - DNS error' => sub {
|
subtest 'check_ssl_certificate - DNS error' => sub {
|
||||||
@@ -560,8 +560,8 @@ subtest 'check_ssl_certificate - DNS error' => sub {
|
|||||||
my ( $result, $error ) =
|
my ( $result, $error ) =
|
||||||
wait_promise( $validator->check_ssl_certificate('https://example.com') );
|
wait_promise( $validator->check_ssl_certificate('https://example.com') );
|
||||||
|
|
||||||
is( $result, undef, 'DNS error has no result' );
|
is( $result, 1, 'DNS error is async' );
|
||||||
like( $error, qr/DNS resolution failed/, 'DNS error is classified' );
|
is( $error, undef, 'DNS error has no error' );
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'check_ssl_certificate - unknown error' => sub {
|
subtest 'check_ssl_certificate - unknown error' => sub {
|
||||||
@@ -569,24 +569,24 @@ subtest 'check_ssl_certificate - unknown error' => sub {
|
|||||||
my ( $result, $error ) =
|
my ( $result, $error ) =
|
||||||
wait_promise( $validator->check_ssl_certificate('https://example.com') );
|
wait_promise( $validator->check_ssl_certificate('https://example.com') );
|
||||||
|
|
||||||
is( $result, undef, 'unknown error has no result' );
|
is( $result, 1, 'unknown error is async' );
|
||||||
like( $error, qr/URL validation failed/, 'unknown error is classified' );
|
is( $error, undef, 'unknown error has no error' );
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'check_ssl_certificate - missing URL' => sub {
|
subtest 'check_ssl_certificate - missing URL' => sub {
|
||||||
my ( $result, $error ) =
|
my ( $result, $error ) =
|
||||||
wait_promise( $validator->check_ssl_certificate(undef) );
|
wait_promise( $validator->check_ssl_certificate(undef) );
|
||||||
|
|
||||||
is( $result, undef, 'missing URL has no result' );
|
is( $result, 1, 'missing URL passes' );
|
||||||
is( $error, 'URL is required', 'missing URL returns error' );
|
is( $error, undef, 'missing URL has no error' );
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'check_ssl_certificate - empty URL' => sub {
|
subtest 'check_ssl_certificate - empty URL' => sub {
|
||||||
my ( $result, $error ) =
|
my ( $result, $error ) =
|
||||||
wait_promise( $validator->check_ssl_certificate('') );
|
wait_promise( $validator->check_ssl_certificate('') );
|
||||||
|
|
||||||
is( $result, undef, 'empty URL has no result' );
|
is( $result, 1, 'empty URL passes' );
|
||||||
is( $error, 'URL is required', 'empty URL returns error' );
|
is( $error, undef, 'empty URL has no error' );
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'validate_url_with_checks - missing URL' => sub {
|
subtest 'validate_url_with_checks - missing URL' => sub {
|
||||||
|
|||||||
@@ -148,15 +148,10 @@ subtest 'POST /api/v1/urls - Real validator network errors (async)' => sub {
|
|||||||
|
|
||||||
subtest 'POST /api/v1/urls - Real validator SSL certificate validation' => sub {
|
subtest 'POST /api/v1/urls - Real validator SSL certificate validation' => sub {
|
||||||
my $res = post_shorten('https://www.example.com');
|
my $res = post_shorten('https://www.example.com');
|
||||||
if ( $res->{code} == 200 ) {
|
ok(
|
||||||
pass('HTTPS URL with valid SSL certificate accepted');
|
$res->{code} == 200 || $res->{code} == 400,
|
||||||
}
|
'SSL validation runs async for HTTPS URL'
|
||||||
elsif ( $res->{code} == 422 && $res->{error} =~ /SSL certificate/i ) {
|
);
|
||||||
diag( "SSL validation: " . $res->{error} );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
diag( "SSL test skipped: " . $res->{error} );
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'POST /api/v1/urls - Real validator invalid URL format' => sub {
|
subtest 'POST /api/v1/urls - Real validator invalid URL format' => sub {
|
||||||
|
|||||||
Reference in New Issue
Block a user