Test :: Mojo post_ok does not read POST data correctly

I am creating a simple Mojolicious application that should have a REST API for some objects in my database. I am trying to verify the creation of a new object, but POSTing the data in a collection of objects. Here is the basic structure of my test :: Mojo script:

use Mojo::Base -strict;
use Test::More;
use Test::Mojo;

use strict;
use warnings;

my $ip_node = {ipname => 'ip_alias.subdomain.company.com', ipservice => 'reserved', ipaddress => '192.168.0.1'};

my $t = Test::Mojo->new('Tools');
$t->post_ok('/tools/ipadmin/nodes' => {Accept => 'application/json'} => form => $ip_node)->status_is(201);

done_testing();

But for some reason, the Mojo controller cannot read the POST data when sent in the above manner. To debug this, in my controller I have the following lines to respond to the request:

my $c = shift;

print "All params: " . $c->req->params . "\n";
print "IP Name: " . $c->req->param("ipname") . "\n";
print "IP Service: " . $c->req->param("ipservice") . "\n";
print "IP Address: " . $c->req->param("ipaddress") . "\n";

When I run the test script through confirmation:

$ prove -v -I /path/to/workspace/Tools/lib t/basic.t

. 4 , CRLF + POST ( , , CRLF, _), , HTTP- .

All params: %0D%0Aipaddress=192.168.0.1&ipname=ip_alias.subdomain.company.com&ipservice=reserv
IP Name: ip_alias.subdomain.company.com
IP Service: reserv
IP Address: 

All params: User-Agent%3A+Mojolicious+%28Perl%29%0D%0AHost%3A+127.0.0.1%3A35611%0D%0AAccept-Encoding%3A+gzip%0D%0A=
IP Name: 
IP Service: 
IP Address: 

All params: 
IP Name: 
IP Service: 
IP Address:

- ? - post_ok ? Mojo Test:: Mojo, (), , . ?

!

+4
1

, cookie, . Cookie Jar authn/authz mojo :

my $jar = Mojo::UserAgent::CookieJar->new;

$jar->add(
    Mojo::Cookie::Response->new(
        name   => "$mojo_cookie_name",
        value  => "$cookie_data",
        domain => "127.0.0.1",
        path   => "$mojo_cookie_path"
    )
);

$t->{ua}->{cookie_jar} =  $jar;

$cookie_data . chomp() $cookie_data, Cookie Jar, , . , Mojo , cookie , , , - . - , / .

0

Source: https://habr.com/ru/post/1664724/


All Articles