From dc24f443291054d55b2b00942102ea9c1bee110d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 24 Feb 2023 12:29:08 -0300 Subject: [PATCH] Regression tests to highlight #242 To reproduce: 1. Apply this patch 2. Run: $ PERL5LIB=../json-validator/lib/:../mojo/lib:./lib prove t/v2-headers.t => FAIL: Tests fail! Weird header handling! # Failed test 'exact match for JSON Pointer "/first"' # at t/v2-headers.t line 50. # got: '42, 24, 44' # expected: '42,24, 44' # Failed test 'exact match for JSON Pointer "/second"' # at t/v2-headers.t line 50. # got: '42' # expected: '42,24, 44' # Looks like you failed 2 tests of 32. The 'first' use case, might be correct, meaning some sanitization of the collection format takes place. But the fact that the space is added even on the case that already had one, is suspicious. The second failure confirms that repeated headers are mangled in a way they get lost. --- t/v2-headers.t | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/t/v2-headers.t b/t/v2-headers.t index ec5f1ed..7d82077 100644 --- a/t/v2-headers.t +++ b/t/v2-headers.t @@ -14,6 +14,23 @@ get '/headers' => sub { }, 'dummy'; +get '/validate_twice' => sub { + + my $c = shift; + + my $res = {before => $c->req->headers->header('x-array')}; + + $c->openapi->valid_input or return; + + $res->{first} = $c->req->headers->header('x-array'); + + $c->openapi->valid_input; + $res->{second} = $c->req->headers->header('x-array'); + + $c->render(openapi => $res); + }, + 'twice'; + plugin OpenAPI => {url => 'data://main/headers.json'}; my $t = Test::Mojo->new; @@ -28,6 +45,13 @@ $what_ever = [qw(1 2 3)]; $t->get_ok('/api/headers' => {'x-array' => '42,24'})->status_is(200)->json_is('/x-array', [42, 24]) ->header_is('what-ever', '1, 2, 3'); +my $header_value = '42,24, 44'; + +$t->get_ok('/api/validate_twice' => {'x-array' => $header_value })->status_is(200) + ->json_is( '/before' => $header_value ) + ->json_is( '/first' => $header_value ) + ->json_is( '/second' => $header_value ); + for my $bool (qw(true false 1 0)) { my $s = $bool =~ /true|1/ ? 'true' : 'false'; $what_ever = '123'; @@ -71,6 +95,20 @@ __DATA__ } } } + }, + "/twice" : { + "get" : { + "x-mojo-name": "twice", + "parameters" : [ + { "in": "header", "name": "x-array", "items": { "type": "string" }, "type": "array", "description": "desc..." } + ], + "responses" : { + "200" : { + "description": "this is required", + "schema": { "type" : "object" } + } + } + } } } }