File: es_sync_auth.pl

package info (click to toggle)
libsearch-elasticsearch-client-1-0-perl 6.81-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 444 kB
  • sloc: perl: 2,788; makefile: 2
file content (78 lines) | stat: -rw-r--r-- 2,097 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! perl
use Test::More;
use Test::Deep;
use Test::Exception;

use strict;
use warnings;
use lib 't/lib';

our $Throws_SSL;

unless ( $ENV{ES_SSL} ) {
    plan skip_all => "$ENV{ES_CXN} - No https server specified in ES_SSL";
    exit;
}

unless ( $ENV{ES_USERINFO} ) {
    plan skip_all => "$ENV{ES_CXN} - No user/pass specified in ES_USERINFO";
    exit;
}

unless ( $ENV{ES_CA_PATH} ) {
    plan skip_all => "$ENV{ES_CXN} - No cacert specified in ES_CA_PATH";
    exit;
}

$ENV{ES}           = $ENV{ES_SSL};
$ENV{ES_SKIP_PING} = 1;

our %Auth = ( use_https => 1, userinfo => $ENV{ES_USERINFO} );

# Test https connection with correct auth, without cacert
$ENV{ES_CXN_POOL} = 'Static';
my $es = do "es_sync.pl" or die( $@ || $! );

ok $es->cluster->health,
    "$ENV{ES_CXN} - Non-cert HTTPS with auth, cxn static";

$ENV{ES_CXN_POOL} = 'Sniff';
$es = do "es_sync.pl" or die( $@ || $! );
ok $es->cluster->health, "$ENV{ES_CXN} - Non-cert HTTPS with auth, cxn sniff";

$ENV{ES_CXN_POOL} = 'Static::NoPing';
$es = do "es_sync.pl" or die( $@ || $! );
ok $es->cluster->health,
    "$ENV{ES_CXN} - Non-cert HTTPS with auth, cxn noping";

# Test forbidden action
throws_ok { $es->nodes->shutdown }
"Search::Elasticsearch::Error::Forbidden",
    "$ENV{ES_CXN} - Forbidden action";

# Test https connection with correct auth, with valid cacert
$Auth{ssl_options} = ssl_options( $ENV{ES_CA_PATH} );

$es = do "es_sync.pl" or die( $@ || $! );

ok $es->cluster->health, "$ENV{ES_CXN} - Valid cert HTTPS with auth";

# Test invalid user credentials
%Auth = ( userinfo => 'foobar:baz' );
$es = do "es_sync.pl" or die( $@ || $! );
throws_ok { $es->cluster->health }
"Search::Elasticsearch::Error::Unauthorized",
    "$ENV{ES_CXN} - Bad userinfo";

# Test https connection with correct auth, with invalid cacert
$Auth{ssl_options} = ssl_options('t/lib/bad_cacert.pem');
$ENV{ES}           = "https://www.google.com";

$es = do "es_sync.pl" or die( $@ || $! );

throws_ok { $es->cluster->health }
"Search::Elasticsearch::Error::$Throws_SSL",
    "$ENV{ES_CXN} - Invalid cert throws $Throws_SSL";

done_testing;