2012-01-24 14:02:24 +01:00
|
|
|
/*
|
2013-07-12 17:19:03 +02:00
|
|
|
* nghttp2 - HTTP/2.0 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"
|
2012-01-24 14:02:24 +01:00
|
|
|
|
2012-01-24 15:06:58 +01:00
|
|
|
static const char *headers[] = {
|
|
|
|
"method", "GET",
|
|
|
|
"scheme", "https",
|
|
|
|
"url", "/",
|
|
|
|
"x-head", "foo",
|
|
|
|
"x-head", "bar",
|
|
|
|
"version", "HTTP/1.1",
|
2012-05-25 03:46:40 +02:00
|
|
|
"x-empty", "",
|
2012-01-24 15:06:58 +01:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
void test_nghttp2_frame_nv_check_null(void)
|
2012-02-26 08:26:38 +01:00
|
|
|
{
|
2013-07-15 14:45:59 +02:00
|
|
|
const char *headers1[] = { "path", "/", "host", "a", NULL };
|
|
|
|
const char *headers2[] = { "", "/", "host", "a", NULL };
|
|
|
|
const char *headers3[] = { "path", "/", "host\x01", "a", NULL };
|
2013-08-25 10:39:29 +02:00
|
|
|
const char *headers4[] = { "PATH", "/", "host", NULL, NULL };
|
2013-07-15 14:45:59 +02:00
|
|
|
|
|
|
|
CU_ASSERT(nghttp2_frame_nv_check_null(headers1));
|
|
|
|
CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers2));
|
|
|
|
CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers3));
|
|
|
|
CU_ASSERT(0 == nghttp2_frame_nv_check_null(headers4));
|
2012-02-26 08:26:38 +01:00
|
|
|
}
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
static void check_frame_header(uint16_t length, uint8_t type, uint8_t flags,
|
|
|
|
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
|
|
|
{
|
2013-07-19 17:08:14 +02:00
|
|
|
nghttp2_hd_context deflater, inflater;
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_headers frame, oframe;
|
2013-07-19 17:08:14 +02:00
|
|
|
uint8_t *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
2012-02-24 17:17:03 +01:00
|
|
|
ssize_t framelen;
|
2013-07-19 17:08:14 +02:00
|
|
|
nghttp2_nv *nva;
|
|
|
|
ssize_t nvlen;
|
|
|
|
|
2013-10-20 17:44:39 +02:00
|
|
|
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
|
|
|
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_REQUEST);
|
2013-07-19 17:08:14 +02:00
|
|
|
|
|
|
|
nvlen = nghttp2_nv_array_from_cstr(&nva, headers);
|
2013-08-28 16:38:56 +02:00
|
|
|
nghttp2_frame_headers_init(&frame,
|
|
|
|
NGHTTP2_FLAG_END_STREAM|NGHTTP2_FLAG_END_HEADERS,
|
|
|
|
1000000007,
|
2013-07-19 17:08:14 +02:00
|
|
|
1 << 20, nva, nvlen);
|
|
|
|
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame, &deflater);
|
2013-07-26 17:58:38 +02:00
|
|
|
nghttp2_hd_end_headers(&deflater);
|
2013-07-15 14:45:59 +02:00
|
|
|
|
|
|
|
CU_ASSERT(0 == unpack_frame_with_nv_block((nghttp2_frame*)&oframe,
|
|
|
|
NGHTTP2_HEADERS,
|
|
|
|
&inflater,
|
|
|
|
buf, framelen));
|
|
|
|
check_frame_header(framelen - NGHTTP2_FRAME_HEAD_LENGTH, NGHTTP2_HEADERS,
|
2013-08-28 16:38:56 +02:00
|
|
|
NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS,
|
|
|
|
1000000007, &oframe.hd);
|
2013-07-15 14:45:59 +02:00
|
|
|
/* We didn't include PRIORITY flag so priority is not packed */
|
|
|
|
CU_ASSERT(1 << 30 == oframe.pri);
|
2013-07-19 17:08:14 +02:00
|
|
|
CU_ASSERT(7 == oframe.nvlen);
|
|
|
|
CU_ASSERT(nvnameeq("method", &oframe.nva[0]));
|
|
|
|
CU_ASSERT(nvvalueeq("GET", &oframe.nva[0]));
|
2013-07-15 14:45:59 +02:00
|
|
|
|
|
|
|
nghttp2_frame_headers_free(&oframe);
|
2013-07-26 17:58:38 +02:00
|
|
|
nghttp2_hd_end_headers(&inflater);
|
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
memset(&oframe, 0, sizeof(oframe));
|
|
|
|
/* Next, include PRIORITY flag */
|
|
|
|
frame.hd.flags |= NGHTTP2_FLAG_PRIORITY;
|
2013-07-19 17:08:14 +02:00
|
|
|
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame, &deflater);
|
2013-07-26 17:58:38 +02:00
|
|
|
nghttp2_hd_end_headers(&deflater);
|
2013-07-15 14:45:59 +02:00
|
|
|
|
|
|
|
CU_ASSERT(0 == unpack_frame_with_nv_block((nghttp2_frame*)&oframe,
|
|
|
|
NGHTTP2_HEADERS,
|
2012-05-25 03:46:40 +02:00
|
|
|
&inflater,
|
|
|
|
buf, framelen));
|
2013-07-15 14:45:59 +02:00
|
|
|
check_frame_header(framelen - NGHTTP2_FRAME_HEAD_LENGTH, NGHTTP2_HEADERS,
|
2013-08-28 16:38:56 +02:00
|
|
|
NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS |
|
|
|
|
NGHTTP2_FLAG_PRIORITY,
|
2013-07-15 14:45:59 +02:00
|
|
|
1000000007, &oframe.hd);
|
|
|
|
CU_ASSERT(1 << 20 == oframe.pri);
|
2013-11-13 15:56:02 +01:00
|
|
|
nghttp2_nv_array_sort(oframe.nva, oframe.nvlen);
|
2013-07-19 17:08:14 +02:00
|
|
|
CU_ASSERT(nvnameeq("method", &oframe.nva[0]));
|
2013-07-15 14:45:59 +02:00
|
|
|
|
2012-02-24 17:17:03 +01:00
|
|
|
free(buf);
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_headers_free(&oframe);
|
|
|
|
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
|
|
|
{
|
2013-07-19 17:08:14 +02:00
|
|
|
nghttp2_hd_context deflater;
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_headers frame;
|
2013-07-19 17:08:14 +02:00
|
|
|
uint8_t *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
2012-09-14 15:41:55 +02:00
|
|
|
ssize_t framelen;
|
2013-07-19 17:08:14 +02:00
|
|
|
nghttp2_nv *nva;
|
|
|
|
ssize_t nvlen;
|
2013-08-06 14:57:26 +02:00
|
|
|
size_t big_vallen = NGHTTP2_MAX_HD_VALUE_LENGTH;
|
|
|
|
char *big_hds[17];
|
2013-09-08 08:29:46 +02:00
|
|
|
size_t big_hdslen = sizeof(big_hds)/sizeof(big_hds[0]) - 1;
|
2013-08-06 14:57:26 +02:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for(i = 0; i < big_hdslen; i += 2) {
|
|
|
|
big_hds[i] = (char*)"header";
|
|
|
|
big_hds[i+1] = malloc(big_vallen+1);
|
|
|
|
memset(big_hds[i+1], '0'+i, big_vallen);
|
|
|
|
big_hds[i+1][big_vallen] = '\0';
|
|
|
|
}
|
2013-09-08 08:29:46 +02:00
|
|
|
big_hds[big_hdslen] = NULL;
|
2013-08-06 14:57:26 +02:00
|
|
|
|
|
|
|
nvlen = nghttp2_nv_array_from_cstr(&nva, (const char**)big_hds);
|
2013-10-20 17:44:39 +02:00
|
|
|
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_REQUEST);
|
2013-08-28 16:38:56 +02:00
|
|
|
nghttp2_frame_headers_init(&frame,
|
|
|
|
NGHTTP2_FLAG_END_STREAM|NGHTTP2_FLAG_END_HEADERS,
|
|
|
|
1000000007,
|
2013-07-19 17:08:14 +02:00
|
|
|
0, nva, nvlen);
|
|
|
|
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame, &deflater);
|
|
|
|
CU_ASSERT_EQUAL(NGHTTP2_ERR_HEADER_COMP, framelen);
|
2012-09-14 15:41:55 +02:00
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_headers_free(&frame);
|
2012-09-14 15:41:55 +02:00
|
|
|
free(buf);
|
2013-08-06 14:57:26 +02:00
|
|
|
for(i = 0; i < big_hdslen; i += 2) {
|
|
|
|
free(big_hds[i+1]);
|
|
|
|
}
|
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;
|
|
|
|
uint8_t *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
2012-02-24 17:17:03 +01:00
|
|
|
ssize_t framelen;
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_priority_init(&frame, 1000000007, 1 << 30);
|
|
|
|
framelen = nghttp2_frame_pack_priority(&buf, &buflen, &frame);
|
|
|
|
CU_ASSERT(0 == nghttp2_frame_unpack_priority
|
|
|
|
(&oframe,
|
|
|
|
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
|
|
|
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
|
|
|
framelen - NGHTTP2_FRAME_HEAD_LENGTH));
|
|
|
|
check_frame_header(4, NGHTTP2_PRIORITY, NGHTTP2_FLAG_NONE, 1000000007,
|
|
|
|
&oframe.hd);
|
|
|
|
CU_ASSERT(1 << 30 == oframe.pri);
|
2012-01-27 10:21:14 +01:00
|
|
|
free(buf);
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_priority_free(&oframe);
|
|
|
|
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;
|
2012-02-24 17:47:37 +01:00
|
|
|
uint8_t *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
|
|
|
ssize_t framelen;
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_rst_stream_init(&frame, 1000000007, NGHTTP2_PROTOCOL_ERROR);
|
|
|
|
framelen = nghttp2_frame_pack_rst_stream(&buf, &buflen, &frame);
|
|
|
|
CU_ASSERT(0 == nghttp2_frame_unpack_rst_stream
|
|
|
|
(&oframe,
|
2013-07-12 17:19:03 +02:00
|
|
|
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
|
|
|
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
2013-07-15 14:45:59 +02:00
|
|
|
framelen - NGHTTP2_FRAME_HEAD_LENGTH));
|
|
|
|
check_frame_header(4, NGHTTP2_RST_STREAM, NGHTTP2_FLAG_NONE, 1000000007,
|
|
|
|
&oframe.hd);
|
|
|
|
CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == oframe.error_code);
|
2012-02-24 17:47:37 +01:00
|
|
|
free(buf);
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_rst_stream_free(&oframe);
|
|
|
|
nghttp2_frame_rst_stream_free(&frame);
|
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;
|
2012-02-16 12:54:30 +01:00
|
|
|
uint8_t *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
|
|
|
ssize_t framelen;
|
2012-01-31 16:26:26 +01:00
|
|
|
int i;
|
2013-07-12 17:19:03 +02:00
|
|
|
nghttp2_settings_entry iv[3];
|
2013-07-15 14:45:59 +02:00
|
|
|
iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
|
2012-01-31 16:26:26 +01:00
|
|
|
iv[0].value = 256;
|
2013-07-15 14:45:59 +02:00
|
|
|
iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
|
|
|
|
iv[1].value = 16384;
|
|
|
|
iv[2].settings_id = NGHTTP2_SETTINGS_FLOW_CONTROL_OPTIONS;
|
|
|
|
iv[2].value = 1;
|
|
|
|
|
2013-10-27 11:22:51 +01:00
|
|
|
nghttp2_frame_settings_init(&frame, NGHTTP2_FLAG_NONE,
|
|
|
|
nghttp2_frame_iv_copy(iv, 3), 3);
|
2013-07-15 14:45:59 +02:00
|
|
|
framelen = nghttp2_frame_pack_settings(&buf, &buflen, &frame);
|
|
|
|
CU_ASSERT(NGHTTP2_FRAME_HEAD_LENGTH+3*8 == framelen);
|
2012-01-31 16:26:26 +01:00
|
|
|
|
2013-07-12 17:19:03 +02:00
|
|
|
CU_ASSERT(0 == nghttp2_frame_unpack_settings
|
2013-07-15 14:45:59 +02:00
|
|
|
(&oframe,
|
2013-07-12 17:19:03 +02:00
|
|
|
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
|
|
|
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
2013-07-15 14:45:59 +02:00
|
|
|
framelen - NGHTTP2_FRAME_HEAD_LENGTH));
|
2012-01-31 16:26:26 +01:00
|
|
|
|
2013-07-15 14:45:59 +02:00
|
|
|
check_frame_header(3*8, NGHTTP2_SETTINGS, NGHTTP2_FLAG_NONE, 0, &oframe.hd);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
free(buf);
|
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()
|
|
|
|
{
|
|
|
|
nghttp2_hd_context deflater, inflater;
|
|
|
|
nghttp2_push_promise frame, oframe;
|
|
|
|
uint8_t *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
|
|
|
ssize_t framelen;
|
|
|
|
nghttp2_nv *nva;
|
|
|
|
ssize_t nvlen;
|
|
|
|
|
2013-10-20 17:44:39 +02:00
|
|
|
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_RESPONSE);
|
|
|
|
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_RESPONSE);
|
2013-07-24 18:49:05 +02:00
|
|
|
|
|
|
|
nvlen = nghttp2_nv_array_from_cstr(&nva, headers);
|
|
|
|
nghttp2_frame_push_promise_init(&frame, NGHTTP2_FLAG_END_PUSH_PROMISE,
|
|
|
|
1000000007, (1U << 31) - 1, nva, nvlen);
|
|
|
|
framelen = nghttp2_frame_pack_push_promise(&buf, &buflen, &frame, &deflater);
|
2013-07-26 17:58:38 +02:00
|
|
|
nghttp2_hd_end_headers(&deflater);
|
2013-07-24 18:49:05 +02:00
|
|
|
|
|
|
|
CU_ASSERT(0 == unpack_frame_with_nv_block((nghttp2_frame*)&oframe,
|
|
|
|
NGHTTP2_PUSH_PROMISE,
|
|
|
|
&inflater,
|
|
|
|
buf, framelen));
|
|
|
|
check_frame_header(framelen - NGHTTP2_FRAME_HEAD_LENGTH,
|
|
|
|
NGHTTP2_PUSH_PROMISE,
|
|
|
|
NGHTTP2_FLAG_END_PUSH_PROMISE, 1000000007, &oframe.hd);
|
|
|
|
CU_ASSERT((1U << 31) - 1 == oframe.promised_stream_id);
|
|
|
|
CU_ASSERT(7 == oframe.nvlen);
|
|
|
|
CU_ASSERT(nvnameeq("method", &oframe.nva[0]));
|
|
|
|
CU_ASSERT(nvvalueeq("GET", &oframe.nva[0]));
|
|
|
|
|
|
|
|
free(buf);
|
|
|
|
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;
|
|
|
|
uint8_t *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
|
|
|
ssize_t framelen;
|
|
|
|
const uint8_t opaque_data[] = "01234567";
|
2013-10-27 11:22:51 +01:00
|
|
|
nghttp2_frame_ping_init(&frame, NGHTTP2_FLAG_ACK, opaque_data);
|
2013-07-15 14:45:59 +02:00
|
|
|
framelen = nghttp2_frame_pack_ping(&buf, &buflen, &frame);
|
|
|
|
CU_ASSERT(0 == nghttp2_frame_unpack_ping
|
|
|
|
(&oframe,
|
|
|
|
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
|
|
|
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
|
|
|
framelen - NGHTTP2_FRAME_HEAD_LENGTH));
|
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);
|
|
|
|
free(buf);
|
|
|
|
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;
|
2012-04-05 18:45:39 +02:00
|
|
|
uint8_t *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
|
|
|
ssize_t framelen;
|
2013-07-15 14:45:59 +02:00
|
|
|
size_t opaque_data_len = 16;
|
|
|
|
uint8_t *opaque_data = malloc(opaque_data_len);
|
|
|
|
memcpy(opaque_data, "0123456789abcdef", opaque_data_len);
|
|
|
|
nghttp2_frame_goaway_init(&frame, 1000000007, NGHTTP2_PROTOCOL_ERROR,
|
|
|
|
opaque_data, opaque_data_len);
|
|
|
|
framelen = nghttp2_frame_pack_goaway(&buf, &buflen, &frame);
|
|
|
|
CU_ASSERT(0 == nghttp2_frame_unpack_goaway
|
|
|
|
(&oframe,
|
2013-07-12 17:19:03 +02:00
|
|
|
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
|
|
|
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
|
|
|
framelen-NGHTTP2_FRAME_HEAD_LENGTH));
|
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);
|
|
|
|
CU_ASSERT(opaque_data_len == oframe.opaque_data_len);
|
|
|
|
CU_ASSERT(memcmp(opaque_data, oframe.opaque_data, opaque_data_len) == 0);
|
2012-04-05 18:45:39 +02:00
|
|
|
free(buf);
|
2013-07-15 14:45:59 +02:00
|
|
|
nghttp2_frame_goaway_free(&oframe);
|
|
|
|
nghttp2_frame_goaway_free(&frame);
|
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;
|
|
|
|
uint8_t *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
|
|
|
ssize_t framelen;
|
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);
|
|
|
|
framelen = nghttp2_frame_pack_window_update(&buf, &buflen,
|
|
|
|
&frame);
|
|
|
|
CU_ASSERT(0 == nghttp2_frame_unpack_window_update
|
|
|
|
(&oframe,
|
|
|
|
&buf[0], NGHTTP2_FRAME_HEAD_LENGTH,
|
|
|
|
&buf[NGHTTP2_FRAME_HEAD_LENGTH],
|
|
|
|
framelen - NGHTTP2_FRAME_HEAD_LENGTH));
|
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);
|
|
|
|
free(buf);
|
|
|
|
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
|
|
|
|
2013-09-10 17:55:35 +02:00
|
|
|
void test_nghttp2_nv_array_check_null(void)
|
|
|
|
{
|
|
|
|
nghttp2_nv nva1[] = {MAKE_NV("path", "/"),
|
|
|
|
MAKE_NV("host", "a")};
|
|
|
|
nghttp2_nv nva2[] = {MAKE_NV("", "/"),
|
|
|
|
MAKE_NV("host", "a")};
|
|
|
|
nghttp2_nv nva3[] = {MAKE_NV("path", "/"),
|
|
|
|
MAKE_NV("host\x01", "a")};
|
|
|
|
nghttp2_nv nva4[] = {MAKE_NV("PATH", "/")};
|
|
|
|
|
|
|
|
CU_ASSERT(nghttp2_nv_array_check_null(nva1, ARRLEN(nva1)));
|
|
|
|
CU_ASSERT(0 == nghttp2_nv_array_check_null(nva2, ARRLEN(nva2)));
|
|
|
|
CU_ASSERT(0 == nghttp2_nv_array_check_null(nva3, ARRLEN(nva3)));
|
|
|
|
CU_ASSERT(nghttp2_nv_array_check_null(nva4, ARRLEN(nva4)));
|
|
|
|
}
|
|
|
|
|
2013-07-23 16:03:18 +02:00
|
|
|
void test_nghttp2_nv_array_from_cstr(void)
|
|
|
|
{
|
|
|
|
const char *empty[] = {NULL};
|
|
|
|
const char *emptynv[] = {"", "", "", "", NULL};
|
|
|
|
const char *nv[] = {"alpha", "bravo", "charlie", "delta", NULL};
|
|
|
|
const char *bignv[] = {"echo", NULL, NULL};
|
|
|
|
size_t bigvallen = 64*1024;
|
|
|
|
char *bigval = malloc(bigvallen+1);
|
|
|
|
nghttp2_nv *nva;
|
|
|
|
ssize_t rv;
|
|
|
|
|
|
|
|
memset(bigval, '0', bigvallen);
|
|
|
|
bigval[bigvallen] = '\0';
|
|
|
|
bignv[1] = bigval;
|
|
|
|
|
|
|
|
rv = nghttp2_nv_array_from_cstr(&nva, empty);
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(NULL == nva);
|
|
|
|
|
|
|
|
rv = nghttp2_nv_array_from_cstr(&nva, emptynv);
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(NULL == nva);
|
|
|
|
|
|
|
|
rv = nghttp2_nv_array_from_cstr(&nva, nv);
|
|
|
|
CU_ASSERT(2 == rv);
|
|
|
|
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);
|
|
|
|
|
|
|
|
rv = nghttp2_nv_array_from_cstr(&nva, bignv);
|
|
|
|
CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv);
|
|
|
|
|
|
|
|
free(bigval);
|
|
|
|
}
|
2013-08-03 11:05:14 +02:00
|
|
|
|
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";
|
|
|
|
bignv.namelen = (uint16_t)strlen("echo");
|
|
|
|
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);
|
|
|
|
CU_ASSERT(NULL == nva);
|
|
|
|
|
|
|
|
rv = nghttp2_nv_array_copy(&nva, nv, ARRLEN(nv));
|
|
|
|
CU_ASSERT(2 == rv);
|
|
|
|
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);
|
|
|
|
|
|
|
|
rv = nghttp2_nv_array_copy(&nva, &bignv, 1);
|
|
|
|
CU_ASSERT(NGHTTP2_ERR_INVALID_ARGUMENT == rv);
|
|
|
|
|
|
|
|
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;
|
|
|
|
iv[1].settings_id = NGHTTP2_SETTINGS_FLOW_CONTROL_OPTIONS;
|
|
|
|
iv[1].value = 0;
|
|
|
|
iv[2].settings_id = NGHTTP2_SETTINGS_FLOW_CONTROL_OPTIONS;
|
|
|
|
iv[2].value = 1;
|
2013-08-03 11:05:14 +02:00
|
|
|
|
2013-08-17 16:41:04 +02:00
|
|
|
CU_ASSERT(nghttp2_iv_check(iv, 2, 0));
|
|
|
|
CU_ASSERT(nghttp2_iv_check(iv, 3, 0));
|
|
|
|
/* Re-enabling flow-control*/
|
|
|
|
CU_ASSERT(0 == nghttp2_iv_check(iv, 2, 1));
|
|
|
|
CU_ASSERT(0 == nghttp2_iv_check(iv, 3, 1));
|
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;
|
|
|
|
CU_ASSERT(nghttp2_iv_check(iv, 2, 0));
|
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;
|
|
|
|
CU_ASSERT(0 == nghttp2_iv_check(iv, 2, 0));
|
2013-08-03 11:05:14 +02:00
|
|
|
}
|