Skip to content

Commit

Permalink
Fix test cases using NEW_CONNECTION_ID frame
Browse files Browse the repository at this point in the history
seq_id must be >= retire_prior_to.

Add negative testcase.
  • Loading branch information
t8m committed May 5, 2023
1 parent b36a0bd commit cd7da83
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
8 changes: 4 additions & 4 deletions test/quic_txp_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ static int schedule_cfq_new_conn_id(struct helper *h)
size_t l = 0;
OSSL_QUIC_FRAME_NEW_CONN_ID ncid = {0};

ncid.seq_num = 1234;
ncid.retire_prior_to = 2345;
ncid.seq_num = 2345;
ncid.retire_prior_to = 1234;
ncid.conn_id = cid_1;
memcpy(ncid.stateless_reset_token, reset_token_1, sizeof(reset_token_1));

Expand Down Expand Up @@ -416,8 +416,8 @@ static int schedule_cfq_new_conn_id(struct helper *h)

static int check_cfq_new_conn_id(struct helper *h)
{
if (!TEST_uint64_t_eq(h->frame.new_conn_id.seq_num, 1234)
|| !TEST_uint64_t_eq(h->frame.new_conn_id.retire_prior_to, 2345)
if (!TEST_uint64_t_eq(h->frame.new_conn_id.seq_num, 2345)
|| !TEST_uint64_t_eq(h->frame.new_conn_id.retire_prior_to, 1234)
|| !TEST_mem_eq(&h->frame.new_conn_id.conn_id, sizeof(cid_1),
&cid_1, sizeof(cid_1))
|| !TEST_mem_eq(&h->frame.new_conn_id.stateless_reset_token,
Expand Down
53 changes: 50 additions & 3 deletions test/quic_wire_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,8 @@ static const unsigned char encode_case_16_conn_id[] = {
};

static const OSSL_QUIC_FRAME_NEW_CONN_ID encode_case_16_f = {
0x1234,
0x9781,
0x1234,
{
0x4,
{0x33, 0x44, 0x55, 0x66}
Expand Down Expand Up @@ -745,10 +745,10 @@ static int encode_case_16_dec(PACKET *pkt, ossl_ssize_t fail)
if (fail >= 0)
return 1;

if (!TEST_uint64_t_eq(f.seq_num, 0x1234))
if (!TEST_uint64_t_eq(f.seq_num, 0x9781))
return 0;

if (!TEST_uint64_t_eq(f.retire_prior_to, 0x9781))
if (!TEST_uint64_t_eq(f.retire_prior_to, 0x1234))
return 0;

if (!TEST_uint64_t_eq(f.conn_id.id_len, sizeof(encode_case_16_conn_id)))
Expand All @@ -768,6 +768,52 @@ static int encode_case_16_dec(PACKET *pkt, ossl_ssize_t fail)
}

static const unsigned char encode_case_16_expect[] = {
0x18, /* Type */
0x80, 0x00, 0x97, 0x81, /* Sequence Number */
0x52, 0x34, /* Retire Prior To */
0x04, /* Connection ID Length */
0x33, 0x44, 0x55, 0x66, /* Connection ID */
0xde, 0x06, 0xcb, 0x76, 0x5d, 0xb1, 0xa7, 0x71, /* Stateless Reset Token */
0x78, 0x09, 0xbb, 0xe8, 0x50, 0x19, 0x12, 0x9a
};

/* 16b. NEW_CONNECTION_ID seq_num < retire_prior_to */
static const OSSL_QUIC_FRAME_NEW_CONN_ID encode_case_16b_f = {
0x1234,
0x9781,
{
0x4,
{0x33, 0x44, 0x55, 0x66}
},
{
0xde, 0x06, 0xcb, 0x76, 0x5d, 0xb1, 0xa7, 0x71,
0x78, 0x09, 0xbb, 0xe8, 0x50, 0x19, 0x12, 0x9a
}
};

static int encode_case_16b_enc(WPACKET *pkt)
{
if (!TEST_int_eq(ossl_quic_wire_encode_frame_new_conn_id(pkt,
&encode_case_16b_f), 1))
return 0;

return 1;
}

static int encode_case_16b_dec(PACKET *pkt, ossl_ssize_t fail)
{
OSSL_QUIC_FRAME_NEW_CONN_ID f = {0};

if (!TEST_int_eq(ossl_quic_wire_decode_frame_new_conn_id(pkt, &f), 0))
return 0;

if (!TEST_true(PACKET_forward(pkt, PACKET_remaining(pkt))))
return 0;

return 1;
}

static const unsigned char encode_case_16b_expect[] = {
0x18, /* Type */
0x52, 0x34, /* Sequence Number */
0x80, 0x00, 0x97, 0x81, /* Retire Prior To */
Expand Down Expand Up @@ -1137,6 +1183,7 @@ static const struct encode_test_case encode_cases[] = {
ENCODE_CASE(14)
ENCODE_CASE(15)
ENCODE_CASE(16)
ENCODE_CASE(16b)
ENCODE_CASE(17)
ENCODE_CASE(18)
ENCODE_CASE(19)
Expand Down

0 comments on commit cd7da83

Please sign in to comment.