File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,11 +7,11 @@ package Nipe::Component::Utils::Status {
77
88 Readonly my $SUCCESS_CODE => 200;
99
10- our $VERSION = ' 0.0.4 ' ;
10+ our $VERSION = ' 0.0.5 ' ;
1111
1212 sub new {
1313 my $api_check = ' https://check.torproject.org/api/ip' ;
14- my $request = HTTP::Tiny -> new -> get($api_check );
14+ my $request = HTTP::Tiny -> new( verify_SSL => 1) -> get($api_check );
1515
1616 if ($request -> {status } == $SUCCESS_CODE ) {
1717 my $data = decode_json($request -> {content });
@@ -26,4 +26,4 @@ package Nipe::Component::Utils::Status {
2626 }
2727}
2828
29- 1;
29+ 1;
Original file line number Diff line number Diff line change 1+ # !/usr/bin/env perl
2+
3+ use strict;
4+ use warnings;
5+ use Test::More;
6+ use Test::MockModule;
7+
8+ use lib ' ./lib' ;
9+
10+ BEGIN {
11+ use_ok(' Nipe::Component::Utils::Status' );
12+ }
13+
14+ my $http_mock = Test::MockModule -> new(' HTTP::Tiny' );
15+
16+ subtest ' reports tor when IsTor is true' => sub {
17+ plan tests => 2;
18+
19+ $http_mock -> mock(' get' , sub {
20+ return { status => 200, content => ' {"IsTor":true,"IP":"185.220.101.1"}' };
21+ });
22+
23+ my $output = Nipe::Component::Utils::Status -> new();
24+ ok(index ($output , ' Status: true' ) >= 0, ' status is true' );
25+ ok(index ($output , ' 185.220.101.1' ) >= 0, ' ip is shown' );
26+ };
27+
28+ subtest ' reports not tor when IsTor is false' => sub {
29+ plan tests => 1;
30+
31+ $http_mock -> mock(' get' , sub {
32+ return { status => 200, content => ' {"IsTor":false,"IP":"8.8.8.8"}' };
33+ });
34+
35+ my $output = Nipe::Component::Utils::Status -> new();
36+ ok(index ($output , ' Status: false' ) >= 0, ' status is false' );
37+ };
38+
39+ subtest ' reports an error when the request fails' => sub {
40+ plan tests => 1;
41+
42+ $http_mock -> mock(' get' , sub {
43+ return { status => 599, content => q{ } };
44+ });
45+
46+ my $output = Nipe::Component::Utils::Status -> new();
47+ ok(index ($output , ' not possible to establish a connection' ) >= 0, ' error branch' );
48+ };
49+
50+ done_testing();
You can’t perform that action at this time.
0 commit comments