| 1 | package cPanel::APIClient::Utils::HTTPSession; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | # Copyright 2020 cPanel, L. L. C. | ||||||||||||||||||||
| 4 | # All rights reserved. | ||||||||||||||||||||
| 5 | # http://cpanel.net | ||||||||||||||||||||
| 6 | # | ||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under the | ||||||||||||||||||||
| 8 | # same terms as Perl itself. See L<perlartistic>. | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | ▶ | use cPanel::APIClient::Utils::HTTPRequest (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 1 | ▶ | sub get_login_request_pieces { | ||||||||||||||||||
|
Subroutine
get_login_request_pieces: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 16 | 1 | my ( $username, $password, $tfa_token ) = @_; | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | my %payload = ( | |||||||||||||||||||
| 19 | user => $username, | ||||||||||||||||||||
| 20 | pass => $password, | ||||||||||||||||||||
| 21 | login_only => 1, | ||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | ▶ | $payload{'tfa_token'} = $tfa_token if $tfa_token; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | return ( | ||||||||||||||||||||
| 27 | 1 | 'POST', | |||||||||||||||||||
| 28 | '/login', | ||||||||||||||||||||
| 29 | cPanel::APIClient::Utils::HTTPRequest::encode_form(\%payload), | ||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 1 | ▶ | sub parse_token { | ||||||||||||||||||
|
Subroutine
parse_token: called CC=3 SCAR=13.5
Pod
undocumented
| |||||||||||||||||||||
| 34 | 1 | my ($response_obj) = @_; | |||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 1 | ▶ | my $loc = $response_obj->header('location') || do { | ||||||||||||||||||
|
Condition33%1/3
$response_obj->header('location') || do {
die "No \342\200\234Location\342\200\235 header given: " . $response_obj->as_string
}
MC/DC0%0/2
$response_obj->header('location') || do {
die "No \342\200\234Location\342\200\235 header given: " . $response_obj->as_string
}
$response_obj->header('location')
do {
die "No \342\200\234Location\342\200\235 header given: " . $response_obj->as_string
}
Truth table33%1/3
A || B
A= $response_obj->header('location')B= do {
die "No \342\200\234Location\342\200\235 header given: " . $response_obj->as_string
}
| |||||||||||||||||||||
| 37 | 0 | die "No “Location” header given: " . $response_obj->as_string(); | |||||||||||||||||||
| 38 | }; | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 1 | ▶ | $loc =~ m<\A(/[^/]+)> or do { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 0 | die "Unrecognized “Location” header: $loc"; | |||||||||||||||||||
| 42 | }; | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 1 | return $1; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 1 | 1; | |||||||||||||||||||