2012-01-24 14:02:24 +01:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2012-01-24 14:02:24 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2013-07-12 17:19:03 +02:00
|
|
|
#include "nghttp2_frame_test.h"
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2013-03-23 11:31:22 +01:00
|
|
|
#include <assert.h>
|
2013-07-15 14:45:59 +02:00
|
|
|
#include <stdio.h>
|
2013-03-23 11:31:22 +01:00
|
|
|
|
2012-01-24 14:02:24 +01:00
|
|
|
#include <CUnit/CUnit.h>
|
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
#include "nghttp2_frame.h"
|
|
|
|
#include "nghttp2_helper.h"
|
|
|
|
#include "nghttp2_test_helper.h"
|
2014-03-25 18:04:24 +01:00
|
|
|
#include "nghttp2_priority_spec.h"
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2013-12-08 13:19:33 +01:00
|
|
|
static nghttp2_nv make_nv(const char *name, const char *value)
|
2012-02-26 08:26:38 +01:00
|
|
|
{
|
2013-12-08 13:19:33 +01:00
|
|
|
nghttp2_nv nv;
|
|
|
|
nv.name = (uint8_t*)name;
|
|
|
|
nv.value = (uint8_t*)value;
|
|
|
|
nv.namelen = strlen(name);
|
|
|
|
nv.valuelen = strlen(value);
|
2014-04-01 18:25:44 +02:00
|
|
|
nv.flags = NGHTTP2_NV_FLAG_NONE;
|
|
|
|
|
2013-12-08 13:19:33 +01:00
|
|
|
return nv;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define HEADERS_LENGTH 7
|
|
|
|
|
|
|
|
static nghttp2_nv* headers(void)
|
|
|
|
{
|
|
|
|
nghttp2_nv *nva = malloc(sizeof(nghttp2_nv) * HEADERS_LENGTH);
|
|
|
|
nva[0] = make_nv("method", "GET");
|
|
|
|
nva[1] = make_nv("scheme", "https");
|
|
|
|
nva[2] = make_nv("url", "/");
|
|
|
|
nva[3] = make_nv("x-head", "foo");
|
|
|
|
nva[4] = make_nv("x-head", "bar");
|
|
|
|
nva[5] = make_nv("version", "HTTP/1.1");
|
|
|
|
nva[6] = make_nv("x-empty", "");
|
|
|
|
return nva;
|
2012-02-26 08:26:38 +01:00
|
|
|
}
|
|
|
|
|
2014-07-09 15:40:31 +02:00
|
|
|
static void check_frame_header(size_t length, uint8_t type, uint8_t flags,
|
2013-07-15 14:45:59 +02:00
|
|
|
int32_t stream_id, nghttp2_frame_hd *hd)
|
2012-02-26 08:26:38 +01:00
|
|
|
{
|
2013-07-15 14:45:59 +02:00
|
|
|
CU_ASSERT(length == hd->length);
|
|
|
|
CU_ASSERT(type == hd->type);
|
|
|
|
CU_ASSERT(flags == hd->flags);
|
|
|
|
CU_ASSERT(stream_id == hd->stream_id);
|
2012-02-26 08:26:38 +01:00
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
void test_nghttp2_frame_pack_headers()
|
2012-02-24 17:17:03 +01:00
|
|
|
{
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_deflater deflater;
|
|
|
|
nghttp2_hd_inflater inflater;
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_headers frame, oframe;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2013-07-19 17:08:14 +02:00
|
|
|
nghttp2_nv *nva;
|
2014-03-25 18:04:24 +01:00
|
|
|
nghttp2_priority_spec pri_spec;
|
2013-07-19 17:08:14 +02:00
|
|
|
ssize_t nvlen;
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-03-10 17:47:38 +01:00
|
|
|
ssize_t hdblocklen;
|
2014-03-13 14:11:02 +01:00
|
|
|
int rv;
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2013-07-19 17:08:14 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-02-13 15:22:52 +01:00
|
|
|
nghttp2_hd_deflate_init(&deflater);
|
|
|
|
nghttp2_hd_inflate_init(&inflater);
|
2013-07-19 17:08:14 +02:00
|
|
|
|
2013-12-08 13:19:33 +01:00
|
|
|
nva = headers();
|
|
|
|
nvlen = HEADERS_LENGTH;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-04-14 16:53:54 +02:00
|
|
|
nghttp2_priority_spec_default_init(&pri_spec);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2013-08-28 16:38:56 +02:00
|
|
|
nghttp2_frame_headers_init(&frame,
|
2014-03-25 18:04:24 +01:00
|
|
|
NGHTTP2_FLAG_END_STREAM |
|
|
|
|
NGHTTP2_FLAG_END_HEADERS,
|
2014-05-07 16:24:07 +02:00
|
|
|
1000000007, NGHTTP2_HCAT_REQUEST,
|
|
|
|
&pri_spec, nva, nvlen);
|
2014-03-13 14:11:02 +01:00
|
|
|
rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_rewind(&bufs);
|
2013-07-15 14:45:59 +02:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(nghttp2_bufs_len(&bufs) > 0);
|
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
|
|
|
|
|
|
|
check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN,
|
2014-02-08 16:35:21 +01:00
|
|
|
NGHTTP2_HEADERS,
|
2013-08-28 16:38:56 +02:00
|
|
|
NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS,
|
|
|
|
1000000007, &oframe.hd);
|
2014-04-14 16:53:54 +02:00
|
|
|
/* We did not include PRIORITY flag */
|
|
|
|
CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == oframe.pri_spec.weight);
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN;
|
2014-03-10 17:47:38 +01:00
|
|
|
CU_ASSERT(hdblocklen ==
|
2014-03-13 14:11:02 +01:00
|
|
|
inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
CU_ASSERT(7 == out.nvlen);
|
|
|
|
CU_ASSERT(nvnameeq("method", &out.nva[0]));
|
|
|
|
CU_ASSERT(nvvalueeq("GET", &out.nva[0]));
|
2013-07-15 14:45:59 +02:00
|
|
|
|
|
|
|
nghttp2_frame_headers_free(&oframe);
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_reset(&out);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-07-26 17:58:38 +02:00
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
memset(&oframe, 0, sizeof(oframe));
|
2014-04-14 16:53:54 +02:00
|
|
|
/* Next, include NGHTTP2_FLAG_PRIORITY */
|
|
|
|
nghttp2_priority_spec_init(&frame.pri_spec, 1000000009, 12, 1);
|
|
|
|
frame.hd.flags |= NGHTTP2_FLAG_PRIORITY;
|
2014-03-25 18:04:24 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater);
|
2013-07-15 14:45:59 +02:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(nghttp2_bufs_len(&bufs) > 0);
|
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN,
|
2014-02-08 16:35:21 +01:00
|
|
|
NGHTTP2_HEADERS,
|
2013-08-28 16:38:56 +02:00
|
|
|
NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS |
|
2014-04-14 16:53:54 +02:00
|
|
|
NGHTTP2_FLAG_PRIORITY,
|
2013-07-15 14:45:59 +02:00
|
|
|
1000000007, &oframe.hd);
|
|
|
|
|
2014-04-14 16:53:54 +02:00
|
|
|
CU_ASSERT(1000000009 == oframe.pri_spec.stream_id);
|
|
|
|
CU_ASSERT(12 == oframe.pri_spec.weight);
|
|
|
|
CU_ASSERT(1 == oframe.pri_spec.exclusive);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
|
|
|
hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN
|
|
|
|
- nghttp2_frame_priority_len(oframe.hd.flags);
|
2014-03-10 17:47:38 +01:00
|
|
|
CU_ASSERT(hdblocklen ==
|
2014-03-25 18:04:24 +01:00
|
|
|
inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN
|
|
|
|
+ nghttp2_frame_priority_len(oframe.hd.flags)));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
nghttp2_nv_array_sort(out.nva, out.nvlen);
|
|
|
|
CU_ASSERT(nvnameeq("method", &out.nva[0]));
|
|
|
|
|
2014-03-25 18:04:24 +01:00
|
|
|
nghttp2_frame_headers_free(&oframe);
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_reset(&out);
|
2014-03-25 18:04:24 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_headers_free(&frame);
|
2013-07-19 17:08:14 +02:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
2012-02-24 17:17:03 +01:00
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
void test_nghttp2_frame_pack_headers_frame_too_large(void)
|
2012-09-14 15:41:55 +02:00
|
|
|
{
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_deflater deflater;
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_headers frame;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2013-07-19 17:08:14 +02:00
|
|
|
nghttp2_nv *nva;
|
2014-05-28 16:02:23 +02:00
|
|
|
size_t big_vallen = NGHTTP2_HD_MAX_NV;
|
2014-01-26 14:01:27 +01:00
|
|
|
nghttp2_nv big_hds[16];
|
2013-12-08 13:19:33 +01:00
|
|
|
size_t big_hdslen = ARRLEN(big_hds);
|
2013-08-06 14:57:26 +02:00
|
|
|
size_t i;
|
2014-03-13 14:11:02 +01:00
|
|
|
int rv;
|
2013-08-06 14:57:26 +02:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2013-12-08 13:19:33 +01:00
|
|
|
for(i = 0; i < big_hdslen; ++i) {
|
|
|
|
big_hds[i].name = (uint8_t*)"header";
|
|
|
|
big_hds[i].value = malloc(big_vallen+1);
|
2014-06-11 16:37:16 +02:00
|
|
|
memset(big_hds[i].value, '0' + (int)i, big_vallen);
|
2013-12-08 13:19:33 +01:00
|
|
|
big_hds[i].value[big_vallen] = '\0';
|
|
|
|
big_hds[i].namelen = strlen((char*)big_hds[i].name);
|
|
|
|
big_hds[i].valuelen = big_vallen;
|
2014-04-01 18:25:44 +02:00
|
|
|
big_hds[i].flags = NGHTTP2_NV_FLAG_NONE;
|
2013-08-06 14:57:26 +02:00
|
|
|
}
|
|
|
|
|
2014-06-11 16:37:16 +02:00
|
|
|
nghttp2_nv_array_copy(&nva, big_hds, big_hdslen);
|
2014-02-13 15:22:52 +01:00
|
|
|
nghttp2_hd_deflate_init(&deflater);
|
2013-08-28 16:38:56 +02:00
|
|
|
nghttp2_frame_headers_init(&frame,
|
|
|
|
NGHTTP2_FLAG_END_STREAM|NGHTTP2_FLAG_END_HEADERS,
|
2014-05-07 16:24:07 +02:00
|
|
|
1000000007, NGHTTP2_HCAT_REQUEST,
|
2014-06-11 16:37:16 +02:00
|
|
|
NULL, nva, big_hdslen);
|
2014-03-13 14:11:02 +01:00
|
|
|
rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater);
|
|
|
|
CU_ASSERT(NGHTTP2_ERR_HEADER_COMP == rv);
|
2012-09-14 15:41:55 +02:00
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_headers_free(&frame);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-12-08 13:19:33 +01:00
|
|
|
for(i = 0; i < big_hdslen; ++i) {
|
|
|
|
free(big_hds[i].value);
|
2013-08-06 14:57:26 +02:00
|
|
|
}
|
2013-07-19 17:08:14 +02:00
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
2012-09-14 15:41:55 +02:00
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
void test_nghttp2_frame_pack_priority(void)
|
2012-02-24 17:17:03 +01:00
|
|
|
{
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_priority frame, oframe;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2014-03-25 18:04:24 +01:00
|
|
|
nghttp2_priority_spec pri_spec;
|
2014-03-13 14:11:02 +01:00
|
|
|
int rv;
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-25 18:04:24 +01:00
|
|
|
/* First, pack priority with priority group and weight */
|
2014-04-14 16:53:54 +02:00
|
|
|
nghttp2_priority_spec_init(&pri_spec, 1000000009, 12, 1);
|
2014-03-25 18:04:24 +01:00
|
|
|
|
|
|
|
nghttp2_frame_priority_init(&frame, 1000000007, &pri_spec);
|
|
|
|
rv = nghttp2_frame_pack_priority(&bufs, &frame);
|
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
2014-07-09 15:40:31 +02:00
|
|
|
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 5 == nghttp2_bufs_len(&bufs));
|
2014-03-25 18:04:24 +01:00
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
2014-04-14 16:53:54 +02:00
|
|
|
check_frame_header(5, NGHTTP2_PRIORITY, NGHTTP2_FLAG_NONE,
|
2014-03-25 18:04:24 +01:00
|
|
|
1000000007, &oframe.hd);
|
|
|
|
|
2014-04-14 16:53:54 +02:00
|
|
|
CU_ASSERT(1000000009 == oframe.pri_spec.stream_id);
|
|
|
|
CU_ASSERT(12 == oframe.pri_spec.weight);
|
|
|
|
CU_ASSERT(1 == oframe.pri_spec.exclusive);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_priority_free(&oframe);
|
2014-03-25 18:04:24 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_priority_free(&frame);
|
2012-02-26 08:33:53 +01:00
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
void test_nghttp2_frame_pack_rst_stream(void)
|
2012-02-24 17:17:03 +01:00
|
|
|
{
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_rst_stream frame, oframe;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
|
|
|
int rv;
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_rst_stream_init(&frame, 1000000007, NGHTTP2_PROTOCOL_ERROR);
|
2014-03-13 14:11:02 +01:00
|
|
|
rv = nghttp2_frame_pack_rst_stream(&bufs, &frame);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2014-07-09 15:40:31 +02:00
|
|
|
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4 == nghttp2_bufs_len(&bufs));
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
2013-07-15 14:45:59 +02:00
|
|
|
check_frame_header(4, NGHTTP2_RST_STREAM, NGHTTP2_FLAG_NONE, 1000000007,
|
|
|
|
&oframe.hd);
|
|
|
|
CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_rst_stream_free(&oframe);
|
2014-06-18 04:53:32 +02:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
|
2014-08-23 10:34:56 +02:00
|
|
|
/* Unknown error code is passed to callback as is */
|
2014-06-18 04:53:32 +02:00
|
|
|
frame.error_code = 1000000009;
|
|
|
|
rv = nghttp2_frame_pack_rst_stream(&bufs, &frame);
|
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
|
|
|
|
|
|
|
check_frame_header(4, NGHTTP2_RST_STREAM, NGHTTP2_FLAG_NONE, 1000000007,
|
|
|
|
&oframe.hd);
|
|
|
|
|
2014-08-23 10:34:56 +02:00
|
|
|
CU_ASSERT(1000000009 == oframe.error_code);
|
2014-06-18 04:53:32 +02:00
|
|
|
|
|
|
|
nghttp2_frame_rst_stream_free(&oframe);
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_rst_stream_free(&frame);
|
2014-06-18 04:53:32 +02:00
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
2012-02-24 17:47:37 +01:00
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
void test_nghttp2_frame_pack_settings()
|
2012-01-31 16:26:26 +01:00
|
|
|
{
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_settings frame, oframe;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2012-01-31 16:26:26 +01:00
|
|
|
int i;
|
2014-03-13 14:11:02 +01:00
|
|
|
int rv;
|
2014-03-10 17:47:38 +01:00
|
|
|
nghttp2_settings_entry iv[] =
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 256
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, 16384
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NGHTTP2_SETTINGS_HEADER_TABLE_SIZE, 4096
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2013-07-15 14:45:59 +02:00
|
|
|
|
2013-10-27 11:22:51 +01:00
|
|
|
nghttp2_frame_settings_init(&frame, NGHTTP2_FLAG_NONE,
|
|
|
|
nghttp2_frame_iv_copy(iv, 3), 3);
|
2014-03-13 14:11:02 +01:00
|
|
|
rv = nghttp2_frame_pack_settings(&bufs, &frame);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH ==
|
|
|
|
nghttp2_bufs_len(&bufs));
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
2014-02-06 14:06:42 +01:00
|
|
|
check_frame_header(3 * NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH,
|
|
|
|
NGHTTP2_SETTINGS, NGHTTP2_FLAG_NONE, 0, &oframe.hd);
|
2013-07-15 14:45:59 +02:00
|
|
|
CU_ASSERT(3 == oframe.niv);
|
2012-01-31 16:26:26 +01:00
|
|
|
for(i = 0; i < 3; ++i) {
|
2013-07-15 14:45:59 +02:00
|
|
|
CU_ASSERT(iv[i].settings_id == oframe.iv[i].settings_id);
|
|
|
|
CU_ASSERT(iv[i].value == oframe.iv[i].value);
|
2012-01-31 16:26:26 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_settings_free(&frame);
|
|
|
|
nghttp2_frame_settings_free(&oframe);
|
2012-01-31 16:26:26 +01:00
|
|
|
}
|
|
|
|
|
2013-07-24 18:49:05 +02:00
|
|
|
void test_nghttp2_frame_pack_push_promise()
|
|
|
|
{
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_deflater deflater;
|
|
|
|
nghttp2_hd_inflater inflater;
|
2013-07-24 18:49:05 +02:00
|
|
|
nghttp2_push_promise frame, oframe;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2013-07-24 18:49:05 +02:00
|
|
|
nghttp2_nv *nva;
|
|
|
|
ssize_t nvlen;
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-03-10 17:47:38 +01:00
|
|
|
ssize_t hdblocklen;
|
2014-03-13 14:11:02 +01:00
|
|
|
int rv;
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2013-07-24 18:49:05 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-02-13 15:22:52 +01:00
|
|
|
nghttp2_hd_deflate_init(&deflater);
|
|
|
|
nghttp2_hd_inflate_init(&inflater);
|
2013-07-24 18:49:05 +02:00
|
|
|
|
2013-12-08 13:19:33 +01:00
|
|
|
nva = headers();
|
|
|
|
nvlen = HEADERS_LENGTH;
|
2014-02-21 13:23:51 +01:00
|
|
|
nghttp2_frame_push_promise_init(&frame, NGHTTP2_FLAG_END_HEADERS,
|
2013-07-24 18:49:05 +02:00
|
|
|
1000000007, (1U << 31) - 1, nva, nvlen);
|
2014-03-13 14:11:02 +01:00
|
|
|
rv = nghttp2_frame_pack_push_promise(&bufs, &frame, &deflater);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(nghttp2_bufs_len(&bufs) > 0);
|
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
2013-07-24 18:49:05 +02:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN,
|
2013-07-24 18:49:05 +02:00
|
|
|
NGHTTP2_PUSH_PROMISE,
|
2014-02-21 13:23:51 +01:00
|
|
|
NGHTTP2_FLAG_END_HEADERS, 1000000007, &oframe.hd);
|
2013-07-24 18:49:05 +02:00
|
|
|
CU_ASSERT((1U << 31) - 1 == oframe.promised_stream_id);
|
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN - 4;
|
2014-03-10 17:47:38 +01:00
|
|
|
CU_ASSERT(hdblocklen ==
|
2014-03-13 14:11:02 +01:00
|
|
|
inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN + 4));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
CU_ASSERT(7 == out.nvlen);
|
|
|
|
CU_ASSERT(nvnameeq("method", &out.nva[0]));
|
|
|
|
CU_ASSERT(nvvalueeq("GET", &out.nva[0]));
|
|
|
|
|
|
|
|
nva_out_reset(&out);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-24 18:49:05 +02:00
|
|
|
nghttp2_frame_push_promise_free(&oframe);
|
|
|
|
nghttp2_frame_push_promise_free(&frame);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
void test_nghttp2_frame_pack_ping(void)
|
2012-04-05 18:45:39 +02:00
|
|
|
{
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_ping frame, oframe;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2013-07-15 14:45:59 +02:00
|
|
|
const uint8_t opaque_data[] = "01234567";
|
2014-03-13 14:11:02 +01:00
|
|
|
int rv;
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2013-10-27 11:22:51 +01:00
|
|
|
nghttp2_frame_ping_init(&frame, NGHTTP2_FLAG_ACK, opaque_data);
|
2014-03-13 14:11:02 +01:00
|
|
|
rv = nghttp2_frame_pack_ping(&bufs, &frame);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2014-07-09 15:40:31 +02:00
|
|
|
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 8 == nghttp2_bufs_len(&bufs));
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
2013-10-27 11:22:51 +01:00
|
|
|
check_frame_header(8, NGHTTP2_PING, NGHTTP2_FLAG_ACK, 0, &oframe.hd);
|
2013-07-15 14:45:59 +02:00
|
|
|
CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, sizeof(opaque_data) - 1)
|
|
|
|
== 0);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_ping_free(&oframe);
|
|
|
|
nghttp2_frame_ping_free(&frame);
|
2012-04-05 18:45:39 +02:00
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
void test_nghttp2_frame_pack_goaway()
|
2012-04-05 18:45:39 +02:00
|
|
|
{
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_goaway frame, oframe;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2013-07-15 14:45:59 +02:00
|
|
|
size_t opaque_data_len = 16;
|
|
|
|
uint8_t *opaque_data = malloc(opaque_data_len);
|
2014-03-13 14:11:02 +01:00
|
|
|
int rv;
|
2014-01-26 08:46:18 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
memcpy(opaque_data, "0123456789abcdef", opaque_data_len);
|
|
|
|
nghttp2_frame_goaway_init(&frame, 1000000007, NGHTTP2_PROTOCOL_ERROR,
|
|
|
|
opaque_data, opaque_data_len);
|
2014-03-13 14:11:02 +01:00
|
|
|
rv = nghttp2_frame_pack_goaway(&bufs, &frame);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2014-07-09 15:40:31 +02:00
|
|
|
CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + 8 + opaque_data_len) ==
|
|
|
|
nghttp2_bufs_len(&bufs));
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
2013-07-15 14:45:59 +02:00
|
|
|
check_frame_header(24, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, &oframe.hd);
|
|
|
|
CU_ASSERT(1000000007 == oframe.last_stream_id);
|
|
|
|
CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code);
|
2014-03-22 10:59:59 +01:00
|
|
|
|
|
|
|
CU_ASSERT(opaque_data_len == oframe.opaque_data_len);
|
|
|
|
CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, opaque_data_len) == 0);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_goaway_free(&oframe);
|
2014-06-18 04:53:32 +02:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
|
2014-08-23 10:34:56 +02:00
|
|
|
/* Unknown error code is passed to callback as is */
|
2014-06-18 04:53:32 +02:00
|
|
|
frame.error_code = 1000000009;
|
|
|
|
|
|
|
|
rv = nghttp2_frame_pack_goaway(&bufs, &frame);
|
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
|
|
|
check_frame_header(24, NGHTTP2_GOAWAY, NGHTTP2_FLAG_NONE, 0, &oframe.hd);
|
2014-08-23 10:34:56 +02:00
|
|
|
CU_ASSERT(1000000009 == oframe.error_code);
|
2014-06-18 04:53:32 +02:00
|
|
|
|
|
|
|
nghttp2_frame_goaway_free(&oframe);
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_goaway_free(&frame);
|
2014-06-18 04:53:32 +02:00
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
2012-03-26 16:19:58 +02:00
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
void test_nghttp2_frame_pack_window_update(void)
|
2013-03-23 13:23:13 +01:00
|
|
|
{
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_window_update frame, oframe;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
|
|
|
int rv;
|
2014-01-26 08:46:18 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2013-08-18 15:04:09 +02:00
|
|
|
nghttp2_frame_window_update_init(&frame, NGHTTP2_FLAG_NONE,
|
2013-07-15 14:45:59 +02:00
|
|
|
1000000007, 4096);
|
2014-03-13 14:11:02 +01:00
|
|
|
rv = nghttp2_frame_pack_window_update(&bufs, &frame);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2014-07-09 15:40:31 +02:00
|
|
|
CU_ASSERT(NGHTTP2_FRAME_HDLEN + 4 == nghttp2_bufs_len(&bufs));
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
2013-08-18 15:04:09 +02:00
|
|
|
check_frame_header(4, NGHTTP2_WINDOW_UPDATE, NGHTTP2_FLAG_NONE,
|
2013-07-15 14:45:59 +02:00
|
|
|
1000000007, &oframe.hd);
|
|
|
|
CU_ASSERT(4096 == oframe.window_size_increment);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_window_update_free(&oframe);
|
|
|
|
nghttp2_frame_window_update_free(&frame);
|
2013-03-23 13:23:13 +01:00
|
|
|
}
|
2013-07-23 16:03:18 +02:00
|
|
|
|
2014-04-01 14:47:51 +02:00
|
|
|
void test_nghttp2_frame_pack_altsvc(void)
|
|
|
|
{
|
2014-06-09 16:16:54 +02:00
|
|
|
nghttp2_extension frame, oframe;
|
|
|
|
nghttp2_ext_altsvc altsvc, oaltsvc;
|
2014-04-01 14:47:51 +02:00
|
|
|
nghttp2_bufs bufs;
|
|
|
|
nghttp2_buf *buf;
|
|
|
|
size_t protocol_id_len, host_len, origin_len;
|
|
|
|
uint8_t *protocol_id, *host, *origin;
|
|
|
|
uint8_t *data;
|
|
|
|
size_t datalen;
|
|
|
|
int rv;
|
|
|
|
size_t payloadlen;
|
|
|
|
|
|
|
|
protocol_id_len = strlen("h2");
|
|
|
|
host_len = strlen("h2.example.org");
|
|
|
|
origin_len = strlen("www.example.org");
|
|
|
|
|
|
|
|
datalen = protocol_id_len + host_len + origin_len;
|
|
|
|
data = malloc(datalen);
|
|
|
|
|
|
|
|
memcpy(data, "h2", protocol_id_len);
|
|
|
|
protocol_id = data;
|
|
|
|
|
|
|
|
memcpy(data + protocol_id_len, "h2.example.org", host_len);
|
|
|
|
host = data + protocol_id_len;
|
|
|
|
|
|
|
|
memcpy(data + protocol_id_len + host_len,
|
|
|
|
"http://www.example.org", origin_len);
|
|
|
|
origin = data + protocol_id_len + host_len;
|
|
|
|
|
|
|
|
frame_pack_bufs_init(&bufs);
|
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
frame.payload = &altsvc;
|
|
|
|
|
2014-04-01 14:47:51 +02:00
|
|
|
nghttp2_frame_altsvc_init(&frame, 1000000007, 1u << 31, 4000,
|
|
|
|
protocol_id, protocol_id_len,
|
|
|
|
host, host_len, origin, origin_len);
|
|
|
|
|
|
|
|
rv = nghttp2_frame_pack_altsvc(&bufs, &frame);
|
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
|
2014-06-07 12:10:09 +02:00
|
|
|
CU_ASSERT((ssize_t)(NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_MINLEN + datalen) ==
|
2014-04-01 14:47:51 +02:00
|
|
|
nghttp2_bufs_len(&bufs));
|
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
oframe.payload = &oaltsvc;
|
|
|
|
|
2014-04-01 14:47:51 +02:00
|
|
|
CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));
|
|
|
|
|
2014-06-07 12:10:09 +02:00
|
|
|
check_frame_header(NGHTTP2_ALTSVC_MINLEN + datalen,
|
2014-06-09 16:16:54 +02:00
|
|
|
NGHTTP2_EXT_ALTSVC, NGHTTP2_FLAG_NONE,
|
2014-04-01 14:47:51 +02:00
|
|
|
1000000007, &oframe.hd);
|
2014-06-09 16:16:54 +02:00
|
|
|
CU_ASSERT(1u << 31 == oaltsvc.max_age);
|
|
|
|
CU_ASSERT(4000 == oaltsvc.port);
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
CU_ASSERT(protocol_id_len == oaltsvc.protocol_id_len);
|
|
|
|
CU_ASSERT(memcmp(protocol_id, oaltsvc.protocol_id, protocol_id_len) == 0);
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
CU_ASSERT(host_len == oaltsvc.host_len);
|
|
|
|
CU_ASSERT(memcmp(host, oaltsvc.host, host_len) == 0);
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
CU_ASSERT(origin_len == oaltsvc.origin_len);
|
|
|
|
CU_ASSERT(memcmp(origin, oaltsvc.origin, origin_len) == 0);
|
2014-04-01 14:47:51 +02:00
|
|
|
|
|
|
|
nghttp2_frame_altsvc_free(&oframe);
|
|
|
|
nghttp2_frame_altsvc_free(&frame);
|
|
|
|
|
|
|
|
memset(&oframe, 0, sizeof(oframe));
|
2014-06-09 16:16:54 +02:00
|
|
|
memset(&oaltsvc, 0, sizeof(oaltsvc));
|
2014-04-01 14:47:51 +02:00
|
|
|
|
|
|
|
buf = &bufs.head->buf;
|
|
|
|
|
2014-06-07 11:15:36 +02:00
|
|
|
CU_ASSERT(buf->pos - buf->begin == 1);
|
2014-04-01 14:47:51 +02:00
|
|
|
|
|
|
|
/* Check no origin case */
|
|
|
|
|
2014-06-07 12:10:09 +02:00
|
|
|
payloadlen = NGHTTP2_ALTSVC_MINLEN + protocol_id_len + host_len;
|
2014-07-09 15:40:31 +02:00
|
|
|
nghttp2_put_uint32be(buf->pos, (uint32_t)((payloadlen << 8) + buf->pos[3]));
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
oframe.payload = &oaltsvc;
|
|
|
|
|
2014-04-01 14:47:51 +02:00
|
|
|
CU_ASSERT(0 ==
|
|
|
|
nghttp2_frame_unpack_altsvc_payload
|
|
|
|
(&oframe,
|
|
|
|
buf->pos + NGHTTP2_FRAME_HDLEN,
|
2014-06-07 12:10:09 +02:00
|
|
|
NGHTTP2_ALTSVC_FIXED_PARTLEN,
|
|
|
|
buf->pos + NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_FIXED_PARTLEN,
|
|
|
|
payloadlen - NGHTTP2_ALTSVC_FIXED_PARTLEN));
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
CU_ASSERT(protocol_id_len == oaltsvc.protocol_id_len);
|
|
|
|
CU_ASSERT(host_len == oaltsvc.host_len);
|
|
|
|
CU_ASSERT(0 == oaltsvc.origin_len);
|
|
|
|
|
|
|
|
memset(&oframe, 0, sizeof(oframe));
|
|
|
|
memset(&oaltsvc, 0, sizeof(oaltsvc));
|
2014-04-01 14:47:51 +02:00
|
|
|
|
|
|
|
/* Check insufficient payload length for host */
|
2014-06-07 12:10:09 +02:00
|
|
|
payloadlen = NGHTTP2_ALTSVC_MINLEN + protocol_id_len + host_len - 1;
|
2014-07-09 15:40:31 +02:00
|
|
|
nghttp2_put_uint32be(buf->pos, (uint32_t)((payloadlen << 8) + buf->pos[3]));
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
oframe.payload = &oaltsvc;
|
|
|
|
|
2014-04-01 14:47:51 +02:00
|
|
|
CU_ASSERT(NGHTTP2_ERR_FRAME_SIZE_ERROR ==
|
|
|
|
nghttp2_frame_unpack_altsvc_payload
|
|
|
|
(&oframe,
|
|
|
|
buf->pos + NGHTTP2_FRAME_HDLEN,
|
2014-06-07 12:10:09 +02:00
|
|
|
NGHTTP2_ALTSVC_FIXED_PARTLEN,
|
|
|
|
buf->pos + NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_FIXED_PARTLEN,
|
|
|
|
payloadlen - NGHTTP2_ALTSVC_FIXED_PARTLEN));
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
memset(&oframe, 0, sizeof(oframe));
|
|
|
|
memset(&oaltsvc, 0, sizeof(oaltsvc));
|
|
|
|
|
2014-04-01 14:47:51 +02:00
|
|
|
/* Check no host case */
|
2014-06-07 12:10:09 +02:00
|
|
|
payloadlen = NGHTTP2_ALTSVC_MINLEN + protocol_id_len;
|
2014-07-09 15:40:31 +02:00
|
|
|
nghttp2_put_uint32be(buf->pos, (uint32_t)((payloadlen << 8) + buf->pos[3]));
|
2014-06-07 12:10:09 +02:00
|
|
|
buf->pos[NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_FIXED_PARTLEN
|
|
|
|
+ protocol_id_len] = 0;
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
oframe.payload = &oaltsvc;
|
|
|
|
|
2014-04-01 14:47:51 +02:00
|
|
|
CU_ASSERT(0 ==
|
|
|
|
nghttp2_frame_unpack_altsvc_payload
|
|
|
|
(&oframe,
|
|
|
|
buf->pos + NGHTTP2_FRAME_HDLEN,
|
2014-06-07 12:10:09 +02:00
|
|
|
NGHTTP2_ALTSVC_FIXED_PARTLEN,
|
|
|
|
buf->pos + NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_FIXED_PARTLEN,
|
|
|
|
payloadlen - NGHTTP2_ALTSVC_FIXED_PARTLEN));
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
CU_ASSERT(protocol_id_len == oaltsvc.protocol_id_len);
|
|
|
|
CU_ASSERT(0 == oaltsvc.host_len);
|
|
|
|
CU_ASSERT(0 == oaltsvc.origin_len);
|
|
|
|
|
|
|
|
memset(&oframe, 0, sizeof(oframe));
|
|
|
|
memset(&oaltsvc, 0, sizeof(oaltsvc));
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-07 12:10:09 +02:00
|
|
|
/* Check missing Host-Len */
|
|
|
|
payloadlen = NGHTTP2_ALTSVC_FIXED_PARTLEN + protocol_id_len;
|
2014-07-09 15:40:31 +02:00
|
|
|
nghttp2_put_uint32be(buf->pos, (uint32_t)((payloadlen << 8) + buf->pos[3]));
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
oframe.payload = &oaltsvc;
|
|
|
|
|
2014-04-01 14:47:51 +02:00
|
|
|
CU_ASSERT(NGHTTP2_ERR_FRAME_SIZE_ERROR ==
|
|
|
|
nghttp2_frame_unpack_altsvc_payload
|
|
|
|
(&oframe,
|
|
|
|
buf->pos + NGHTTP2_FRAME_HDLEN,
|
2014-06-07 12:10:09 +02:00
|
|
|
NGHTTP2_ALTSVC_FIXED_PARTLEN,
|
|
|
|
buf->pos + NGHTTP2_FRAME_HDLEN + NGHTTP2_ALTSVC_FIXED_PARTLEN,
|
|
|
|
payloadlen - NGHTTP2_ALTSVC_FIXED_PARTLEN));
|
2014-04-01 14:47:51 +02:00
|
|
|
|
2014-06-09 16:16:54 +02:00
|
|
|
memset(&oframe, 0, sizeof(oframe));
|
|
|
|
memset(&oaltsvc, 0, sizeof(oaltsvc));
|
|
|
|
|
2014-04-01 14:47:51 +02:00
|
|
|
nghttp2_bufs_free(&bufs);
|
|
|
|
}
|
|
|
|
|
2013-09-10 17:55:35 +02:00
|
|
|
void test_nghttp2_nv_array_copy(void)
|
|
|
|
{
|
|
|
|
nghttp2_nv *nva;
|
|
|
|
ssize_t rv;
|
|
|
|
nghttp2_nv emptynv[] = {MAKE_NV("", ""),
|
|
|
|
MAKE_NV("", "")};
|
|
|
|
nghttp2_nv nv[] = {MAKE_NV("alpha", "bravo"),
|
|
|
|
MAKE_NV("charlie", "delta")};
|
|
|
|
nghttp2_nv bignv;
|
|
|
|
|
|
|
|
bignv.name = (uint8_t*)"echo";
|
2014-04-30 16:08:34 +02:00
|
|
|
bignv.namelen = strlen("echo");
|
2013-09-10 17:55:35 +02:00
|
|
|
bignv.valuelen = (1 << 14) - 1;
|
|
|
|
bignv.value = malloc(bignv.valuelen);
|
|
|
|
memset(bignv.value, '0', bignv.valuelen);
|
|
|
|
|
|
|
|
rv = nghttp2_nv_array_copy(&nva, NULL, 0);
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(NULL == nva);
|
|
|
|
|
|
|
|
rv = nghttp2_nv_array_copy(&nva, emptynv, ARRLEN(emptynv));
|
|
|
|
CU_ASSERT(0 == rv);
|
2014-06-11 16:37:16 +02:00
|
|
|
CU_ASSERT(nva[0].namelen == 0);
|
|
|
|
CU_ASSERT(nva[0].valuelen == 0);
|
|
|
|
CU_ASSERT(nva[1].namelen == 0);
|
|
|
|
CU_ASSERT(nva[1].valuelen == 0);
|
|
|
|
|
|
|
|
nghttp2_nv_array_del(nva);
|
2013-09-10 17:55:35 +02:00
|
|
|
|
|
|
|
rv = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv));
|
2014-06-11 16:37:16 +02:00
|
|
|
CU_ASSERT(0 == rv);
|
2013-09-10 17:55:35 +02:00
|
|
|
CU_ASSERT(nva[0].namelen == 5);
|
|
|
|
CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5));
|
|
|
|
CU_ASSERT(nva[0].valuelen = 5);
|
|
|
|
CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5));
|
|
|
|
CU_ASSERT(nva[1].namelen == 7);
|
|
|
|
CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7));
|
|
|
|
CU_ASSERT(nva[1].valuelen == 5);
|
|
|
|
CU_ASSERT(0 == memcmp("delta", nva[1].value, 5));
|
|
|
|
|
|
|
|
nghttp2_nv_array_del(nva);
|
|
|
|
|
2014-02-24 16:26:12 +01:00
|
|
|
/* Large header field is acceptable */
|
2013-09-10 17:55:35 +02:00
|
|
|
rv = nghttp2_nv_array_copy(&nva, &bignv, 1);
|
2014-06-11 16:37:16 +02:00
|
|
|
CU_ASSERT(0 == rv);
|
2013-09-10 17:55:35 +02:00
|
|
|
|
2014-02-27 19:07:19 +01:00
|
|
|
nghttp2_nv_array_del(nva);
|
|
|
|
|
2013-09-10 17:55:35 +02:00
|
|
|
free(bignv.value);
|
|
|
|
}
|
|
|
|
|
2013-08-17 16:41:04 +02:00
|
|
|
void test_nghttp2_iv_check(void)
|
2013-08-03 11:05:14 +02:00
|
|
|
{
|
2013-08-17 16:41:04 +02:00
|
|
|
nghttp2_settings_entry iv[5];
|
2013-08-03 11:05:14 +02:00
|
|
|
|
2013-08-17 16:41:04 +02:00
|
|
|
iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
|
|
|
|
iv[0].value = 100;
|
2014-02-05 16:23:20 +01:00
|
|
|
iv[1].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
|
|
|
|
iv[1].value = 1024;
|
2013-08-03 11:05:14 +02:00
|
|
|
|
2014-02-05 16:23:20 +01:00
|
|
|
CU_ASSERT(nghttp2_iv_check(iv, 2));
|
2013-08-03 11:05:14 +02:00
|
|
|
|
2013-08-17 16:41:04 +02:00
|
|
|
iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
|
|
|
|
iv[1].value = NGHTTP2_MAX_WINDOW_SIZE;
|
2014-02-05 16:23:20 +01:00
|
|
|
CU_ASSERT(nghttp2_iv_check(iv, 2));
|
2013-08-03 11:05:14 +02:00
|
|
|
|
2013-08-17 16:41:04 +02:00
|
|
|
/* Too large window size */
|
|
|
|
iv[1].value = (uint32_t)NGHTTP2_MAX_WINDOW_SIZE + 1;
|
2014-02-05 16:23:20 +01:00
|
|
|
CU_ASSERT(0 == nghttp2_iv_check(iv, 2));
|
2014-02-06 13:38:16 +01:00
|
|
|
|
|
|
|
/* ENABLE_PUSH only allows 0 or 1 */
|
|
|
|
iv[1].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH;
|
|
|
|
iv[1].value = 0;
|
|
|
|
CU_ASSERT(nghttp2_iv_check(iv, 2));
|
|
|
|
iv[1].value = 1;
|
|
|
|
CU_ASSERT(nghttp2_iv_check(iv, 2));
|
|
|
|
iv[1].value = 3;
|
|
|
|
CU_ASSERT(!nghttp2_iv_check(iv, 2));
|
2014-02-11 08:53:08 +01:00
|
|
|
|
2014-07-27 10:05:24 +02:00
|
|
|
/* Undefined SETTINGS ID is allowed */
|
2014-02-11 08:53:08 +01:00
|
|
|
iv[1].settings_id = 1000000009;
|
|
|
|
iv[1].value = 0;
|
2014-07-27 10:05:24 +02:00
|
|
|
CU_ASSERT(nghttp2_iv_check(iv, 2));
|
2014-05-12 14:28:49 +02:00
|
|
|
|
|
|
|
/* Too large SETTINGS_HEADER_TABLE_SIZE */
|
|
|
|
iv[1].settings_id = NGHTTP2_SETTINGS_HEADER_TABLE_SIZE;
|
|
|
|
iv[1].value = UINT32_MAX;
|
|
|
|
CU_ASSERT(!nghttp2_iv_check(iv, 2));
|
2014-07-27 09:58:04 +02:00
|
|
|
|
|
|
|
/* Too small SETTINGS_MAX_FRAME_SIZE */
|
|
|
|
iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
|
|
|
|
iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MIN - 1;
|
|
|
|
CU_ASSERT(!nghttp2_iv_check(iv, 1));
|
|
|
|
|
|
|
|
/* Too large SETTINGS_MAX_FRAME_SIZE */
|
|
|
|
iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
|
|
|
|
iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MAX + 1;
|
|
|
|
CU_ASSERT(!nghttp2_iv_check(iv, 1));
|
|
|
|
|
|
|
|
/* Max and min SETTINGS_MAX_FRAME_SIZE */
|
|
|
|
iv[0].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
|
|
|
|
iv[0].value = NGHTTP2_MAX_FRAME_SIZE_MIN;
|
|
|
|
iv[1].settings_id = NGHTTP2_SETTINGS_MAX_FRAME_SIZE;
|
|
|
|
iv[1].value = NGHTTP2_MAX_FRAME_SIZE_MAX;
|
|
|
|
CU_ASSERT(nghttp2_iv_check(iv, 2));
|
2013-08-03 11:05:14 +02:00
|
|
|
}
|