HTTP-Promise

 view release on metacpan or  search on metacpan

t/17.serialisation.t  view on Meta::CPAN


        # try-catch
        local $@;
        eval
        {
            my $dispo = HTTP::Promise::Headers::ContentDisposition->new( q{attachment; filename="filename.jpg"} );
            $serial = $cbor->encode( $dispo );
            my $dispo2  = $cbor->decode( $serial );
            isa_ok( $dispo2 => ['HTTP::Promise::Headers::ContentDisposition'], 'deserialised element is a HTTP::Promise::Headers::ContentDisposition object' );
            is( "$dispo2" => "$dispo", 'HTTP::Promise::Headers::ContentDisposition string matches' );
            is( $dispo2->disposition => $dispo->disposition, 'HTTP::Promise::Headers::ContentDisposition disposition matches' );
            is( $dispo2->filename => $dispo->filename, 'HTTP::Promise::Headers::ContentDisposition filename matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentDisposition test for CBOR: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $range = HTTP::Promise::Headers::ContentRange->new( 'bytes 200-1000/67589' );
            $serial = $cbor->encode( $range );
            my $range2  = $cbor->decode( $serial );
            isa_ok( $range2 => ['HTTP::Promise::Headers::ContentRange'], 'deserialised element is a HTTP::Promise::Headers::ContentRange object' );
            is( "$range2" => "$range", 'HTTP::Promise::Headers::ContentRange string matches' );
            is( $range2->range_start => $range->range_start, 'HTTP::Promise::Headers::ContentRange range_start matches' );
            is( $range2->range_end => $range->range_end, 'HTTP::Promise::Headers::ContentRange range_end matches' );
            is( $range2->size => $range->size, 'HTTP::Promise::Headers::ContentRange size matches' );
            is( $range2->unit => $range->unit, 'HTTP::Promise::Headers::ContentRange unit matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentRange test for CBOR: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $policy = HTTP::Promise::Headers::ContentSecurityPolicy->new( q{default-src 'self'; img-src *; media-src media1.com media2.com; script-src userscripts.example.com} );
            $serial = $cbor->encode( $policy );
            my $policy2  = $cbor->decode( $serial );
            isa_ok( $policy2 => ['HTTP::Promise::Headers::ContentSecurityPolicy'], 'deserialised element is a HTTP::Promise::Headers::ContentSecurityPolicy object' );
            is( "$policy2" => "$policy", 'HTTP::Promise::Headers::ContentSecurityPolicy string matches' );
            is( $policy2->default_src => $policy->default_src, 'HTTP::Promise::Headers::ContentSecurityPolicy default_src matches' );
            is( $policy2->img_src => $policy->img_src, 'HTTP::Promise::Headers::ContentSecurityPolicy img_src matches' );
            is( $policy2->media_src => $policy->media_src, 'HTTP::Promise::Headers::ContentSecurityPolicy media_src matches' );
            is( $policy2->script_src => $policy->script_src, 'HTTP::Promise::Headers::ContentSecurityPolicy script_src matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentSecurityPolicy test for CBOR: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $policy = HTTP::Promise::Headers::ContentSecurityPolicyReportOnly->new( q{default-src https:; report-uri /csp-violation-report-endpoint/} );
            $serial = $cbor->encode( $policy );
            my $policy2  = $cbor->decode( $serial );
            isa_ok( $policy2 => ['HTTP::Promise::Headers::ContentSecurityPolicyReportOnly'], 'deserialised element is a HTTP::Promise::Headers::ContentSecurityPolicyReportOnly object' );
            is( "$policy2" => "$policy", 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly string matches' );
            is( $policy2->default_src => $policy->default_src, 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly default_src matches' );
            is( $policy2->report_uri => $policy->report_uri, 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly report_uri matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentSecurityPolicyReportOnly test for CBOR: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $ct = HTTP::Promise::Headers::ContentType->new( q{text/html; charset=UTF-8} );
            $serial = $cbor->encode( $ct );
            my $ct2  = $cbor->decode( $serial );
            isa_ok( $ct2 => ['HTTP::Promise::Headers::ContentType'], 'deserialised element is a HTTP::Promise::Headers::ContentType object' );
            is( "$ct2" => "$ct", 'HTTP::Promise::Headers::ContentType string matches' );
            is( $ct2->type => $ct->type, 'HTTP::Promise::Headers::ContentType type matches' );
            is( $ct2->charset => $ct->charset, 'HTTP::Promise::Headers::ContentType charset matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentType test for CBOR: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $c = HTTP::Promise::Headers::Cookie->new( q{name=value; name2=value2; name3=value3} );
            $serial = $cbor->encode( $c );
            my $c2  = $cbor->decode( $serial );
            isa_ok( $c2 => ['HTTP::Promise::Headers::Cookie'], 'deserialised element is a HTTP::Promise::Headers::Cookie object' );
            is( "$c2" => "$c", 'HTTP::Promise::Headers::Cookie string matches' );
            my $cookies = $c->cookies;
            my $cookies2 = $c2->cookies;
            is( "@$cookies2" => "@$cookies", 'HTTP::Promise::Headers::Cookie cookies matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::Cookie test for CBOR: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $o = HTTP::Promise::Headers::ExpectCT->new( q{max-age=86400, enforce, report-uri="https://foo.example.com/report"} );
            $serial = $cbor->encode( $o );
            my $o2  = $cbor->decode( $serial );
            isa_ok( $o2 => ['HTTP::Promise::Headers::ExpectCT'], 'deserialised element is a HTTP::Promise::Headers::ExpectCT object' );
            is( "$o2" => "$o", 'HTTP::Promise::Headers::ExpectCT string matches' );
            is( $o2->max_age => $o->max_age, 'HTTP::Promise::Headers::ExpectCT max_age matches' );
            is( $o2->enforce => $o->enforce, 'HTTP::Promise::Headers::ExpectCT enforce matches' );
            is( $o2->report_uri => $o->report_uri, 'HTTP::Promise::Headers::ExpectCT report_uri matches' );
        };

t/17.serialisation.t  view on Meta::CPAN


        # try-catch
        local $@;
        eval
        {
            my $dispo = HTTP::Promise::Headers::ContentDisposition->new( q{attachment; filename="filename.jpg"} );
            $serial = $enc->encode( $dispo );
            my $dispo2  = $dec->decode( $serial );
            isa_ok( $dispo2 => ['HTTP::Promise::Headers::ContentDisposition'], 'deserialised element is a HTTP::Promise::Headers::ContentDisposition object' );
            is( "$dispo2" => "$dispo", 'HTTP::Promise::Headers::ContentDisposition string matches' );
            is( $dispo2->disposition => $dispo->disposition, 'HTTP::Promise::Headers::ContentDisposition disposition matches' );
            is( $dispo2->filename => $dispo->filename, 'HTTP::Promise::Headers::ContentDisposition filename matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentDisposition test for Sereal: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $range = HTTP::Promise::Headers::ContentRange->new( 'bytes 200-1000/67589' );
            $serial = $enc->encode( $range );
            my $range2  = $dec->decode( $serial );
            isa_ok( $range2 => ['HTTP::Promise::Headers::ContentRange'], 'deserialised element is a HTTP::Promise::Headers::ContentRange object' );
            is( "$range2" => "$range", 'HTTP::Promise::Headers::ContentRange string matches' );
            is( $range2->range_start => $range->range_start, 'HTTP::Promise::Headers::ContentRange range_start matches' );
            is( $range2->range_end => $range->range_end, 'HTTP::Promise::Headers::ContentRange range_end matches' );
            is( $range2->size => $range->size, 'HTTP::Promise::Headers::ContentRange size matches' );
            is( $range2->unit => $range->unit, 'HTTP::Promise::Headers::ContentRange unit matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentRange test for Sereal: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $policy = HTTP::Promise::Headers::ContentSecurityPolicy->new( q{default-src 'self'; img-src *; media-src media1.com media2.com; script-src userscripts.example.com} );
            $serial = $enc->encode( $policy );
            my $policy2  = $dec->decode( $serial );
            isa_ok( $policy2 => ['HTTP::Promise::Headers::ContentSecurityPolicy'], 'deserialised element is a HTTP::Promise::Headers::ContentSecurityPolicy object' );
            is( "$policy2" => "$policy", 'HTTP::Promise::Headers::ContentSecurityPolicy string matches' );
            is( $policy2->default_src => $policy->default_src, 'HTTP::Promise::Headers::ContentSecurityPolicy default_src matches' );
            is( $policy2->img_src => $policy->img_src, 'HTTP::Promise::Headers::ContentSecurityPolicy img_src matches' );
            is( $policy2->media_src => $policy->media_src, 'HTTP::Promise::Headers::ContentSecurityPolicy media_src matches' );
            is( $policy2->script_src => $policy->script_src, 'HTTP::Promise::Headers::ContentSecurityPolicy script_src matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentSecurityPolicy test for Sereal: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $policy = HTTP::Promise::Headers::ContentSecurityPolicyReportOnly->new( q{default-src https:; report-uri /csp-violation-report-endpoint/} );
            $serial = $enc->encode( $policy );
            my $policy2  = $dec->decode( $serial );
            isa_ok( $policy2 => ['HTTP::Promise::Headers::ContentSecurityPolicyReportOnly'], 'deserialised element is a HTTP::Promise::Headers::ContentSecurityPolicyReportOnly object' );
            is( "$policy2" => "$policy", 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly string matches' );
            is( $policy2->default_src => $policy->default_src, 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly default_src matches' );
            is( $policy2->report_uri => $policy->report_uri, 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly report_uri matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentSecurityPolicyReportOnly test for Sereal: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $ct = HTTP::Promise::Headers::ContentType->new( q{text/html; charset=UTF-8} );
            $serial = $enc->encode( $ct );
            my $ct2  = $dec->decode( $serial );
            isa_ok( $ct2 => ['HTTP::Promise::Headers::ContentType'], 'deserialised element is a HTTP::Promise::Headers::ContentType object' );
            is( "$ct2" => "$ct", 'HTTP::Promise::Headers::ContentType string matches' );
            is( $ct2->type => $ct->type, 'HTTP::Promise::Headers::ContentType type matches' );
            is( $ct2->charset => $ct->charset, 'HTTP::Promise::Headers::ContentType charset matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentType test for Sereal: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $c = HTTP::Promise::Headers::Cookie->new( q{name=value; name2=value2; name3=value3} );
            $serial = $enc->encode( $c );
            my $c2  = $dec->decode( $serial );
            isa_ok( $c2 => ['HTTP::Promise::Headers::Cookie'], 'deserialised element is a HTTP::Promise::Headers::Cookie object' );
            is( "$c2" => "$c", 'HTTP::Promise::Headers::Cookie string matches' );
            my $cookies = $c->cookies;
            my $cookies2 = $c2->cookies;
            is( "@$cookies2" => "@$cookies", 'HTTP::Promise::Headers::Cookie cookies matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::Cookie test for Sereal: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $o = HTTP::Promise::Headers::ExpectCT->new( q{max-age=86400, enforce, report-uri="https://foo.example.com/report"} );
            $serial = $enc->encode( $o );
            my $o2  = $dec->decode( $serial );
            isa_ok( $o2 => ['HTTP::Promise::Headers::ExpectCT'], 'deserialised element is a HTTP::Promise::Headers::ExpectCT object' );
            is( "$o2" => "$o", 'HTTP::Promise::Headers::ExpectCT string matches' );
            is( $o2->max_age => $o->max_age, 'HTTP::Promise::Headers::ExpectCT max_age matches' );
            is( $o2->enforce => $o->enforce, 'HTTP::Promise::Headers::ExpectCT enforce matches' );
            is( $o2->report_uri => $o->report_uri, 'HTTP::Promise::Headers::ExpectCT report_uri matches' );
        };

t/17.serialisation.t  view on Meta::CPAN

        # try-catch
        local $@;
        eval
        {
            my $dispo = HTTP::Promise::Headers::ContentDisposition->new( q{attachment; filename="filename.jpg"} );
            $serial = Storable::Improved::freeze( $dispo );
            my $dispo2  = Storable::Improved::thaw( $serial );
            isa_ok( $dispo2 => ['HTTP::Promise::Headers::ContentDisposition'], 'deserialised element is a HTTP::Promise::Headers::ContentDisposition object' );
            is( "$dispo2" => "$dispo", 'HTTP::Promise::Headers::ContentDisposition string matches' );
            is( $dispo2->disposition => $dispo->disposition, 'HTTP::Promise::Headers::ContentDisposition disposition matches' );
            is( $dispo2->filename => $dispo->filename, 'HTTP::Promise::Headers::ContentDisposition filename matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentDisposition test for Storable: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $range = HTTP::Promise::Headers::ContentRange->new( 'bytes 200-1000/67589' );
            $serial = Storable::Improved::freeze( $range );
            my $range2  = Storable::Improved::thaw( $serial );
            isa_ok( $range2 => ['HTTP::Promise::Headers::ContentRange'], 'deserialised element is a HTTP::Promise::Headers::ContentRange object' );
            is( "$range2" => "$range", 'HTTP::Promise::Headers::ContentRange string matches' );

            is( $range2->range_start => $range->range_start, 'HTTP::Promise::Headers::ContentRange range_start matches' );
            is( $range2->range_end => $range->range_end, 'HTTP::Promise::Headers::ContentRange range_end matches' );
            is( $range2->size => $range->size, 'HTTP::Promise::Headers::ContentRange size matches' );
            is( $range2->unit => $range->unit, 'HTTP::Promise::Headers::ContentRange unit matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentRange test for Storable: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $policy = HTTP::Promise::Headers::ContentSecurityPolicy->new( q{default-src 'self'; img-src *; media-src media1.com media2.com; script-src userscripts.example.com} );
            $serial = Storable::Improved::freeze( $policy );
            my $policy2  = Storable::Improved::thaw( $serial );
            isa_ok( $policy2 => ['HTTP::Promise::Headers::ContentSecurityPolicy'], 'deserialised element is a HTTP::Promise::Headers::ContentSecurityPolicy object' );
            is( "$policy2" => "$policy", 'HTTP::Promise::Headers::ContentSecurityPolicy string matches' );
            is( $policy2->default_src => $policy->default_src, 'HTTP::Promise::Headers::ContentSecurityPolicy default_src matches' );
            is( $policy2->img_src => $policy->img_src, 'HTTP::Promise::Headers::ContentSecurityPolicy img_src matches' );
            is( $policy2->media_src => $policy->media_src, 'HTTP::Promise::Headers::ContentSecurityPolicy media_src matches' );
            is( $policy2->script_src => $policy->script_src, 'HTTP::Promise::Headers::ContentSecurityPolicy script_src matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentSecurityPolicy test for Storable: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $policy = HTTP::Promise::Headers::ContentSecurityPolicyReportOnly->new( q{default-src https:; report-uri /csp-violation-report-endpoint/} );
            $serial = Storable::Improved::freeze( $policy );
            my $policy2  = Storable::Improved::thaw( $serial );
            isa_ok( $policy2 => ['HTTP::Promise::Headers::ContentSecurityPolicyReportOnly'], 'deserialised element is a HTTP::Promise::Headers::ContentSecurityPolicyReportOnly object' );
            is( "$policy2" => "$policy", 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly string matches' );
            is( $policy2->default_src => $policy->default_src, 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly default_src matches' );
            is( $policy2->report_uri => $policy->report_uri, 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly report_uri matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentSecurityPolicyReportOnly test for Storable: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $ct = HTTP::Promise::Headers::ContentType->new( q{text/html; charset=UTF-8} );
            $serial = Storable::Improved::freeze( $ct );
            my $ct2  = Storable::Improved::thaw( $serial );
            isa_ok( $ct2 => ['HTTP::Promise::Headers::ContentType'], 'deserialised element is a HTTP::Promise::Headers::ContentType object' );
            is( "$ct2" => "$ct", 'HTTP::Promise::Headers::ContentType string matches' );
            is( $ct2->type => $ct->type, 'HTTP::Promise::Headers::ContentType type matches' );
            is( $ct2->charset => $ct->charset, 'HTTP::Promise::Headers::ContentType charset matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::ContentType test for Storable: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $c = HTTP::Promise::Headers::Cookie->new( q{name=value; name2=value2; name3=value3} );
            $serial = Storable::Improved::freeze( $c );
            my $c2  = Storable::Improved::thaw( $serial );
            isa_ok( $c2 => ['HTTP::Promise::Headers::Cookie'], 'deserialised element is a HTTP::Promise::Headers::Cookie object' );
            is( "$c2" => "$c", 'HTTP::Promise::Headers::Cookie string matches' );
            my $cookies = $c->cookies;
            my $cookies2 = $c2->cookies;
            is( "@$cookies2" => "@$cookies", 'HTTP::Promise::Headers::Cookie cookies matches' );
        };
        if( $@ )
        {
            fail( "Failed HTTP::Promise::Headers::Cookie test for Storable: $@" );
        }

        # try-catch
        local $@;
        eval
        {
            my $o = HTTP::Promise::Headers::ExpectCT->new( q{max-age=86400, enforce, report-uri="https://foo.example.com/report"} );
            $serial = Storable::Improved::freeze( $o );
            my $o2  = Storable::Improved::thaw( $serial );
            isa_ok( $o2 => ['HTTP::Promise::Headers::ExpectCT'], 'deserialised element is a HTTP::Promise::Headers::ExpectCT object' );
            is( "$o2" => "$o", 'HTTP::Promise::Headers::ExpectCT string matches' );
            is( $o2->max_age => $o->max_age, 'HTTP::Promise::Headers::ExpectCT max_age matches' );
            is( $o2->enforce => $o->enforce, 'HTTP::Promise::Headers::ExpectCT enforce matches' );
            is( $o2->report_uri => $o->report_uri, 'HTTP::Promise::Headers::ExpectCT report_uri matches' );
        };



( run in 1.247 second using v1.01-cache-2.11-cpan-437f7b0c052 )