Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC 9113 section 7 tests #188

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions crates/httpwg-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,29 @@ use __group::sends_continuation_frame_preceded_by_data_frame as test;
$body
}
}

/// Section 7: Error Codes
mod _7_error_codes {
use super::__suite::_7_error_codes as __group;

/// Unknown or unsupported error codes MUST NOT trigger any special
/// behavior. These MAY be treated by an implementation as being
/// equivalent to INTERNAL_ERROR.
#[test]
fn sends_goaway_frame_with_unknown_error_code() {
use __group::sends_goaway_frame_with_unknown_error_code as test;
$body
}

/// Unknown or unsupported error codes MUST NOT trigger any special
/// behavior. These MAY be treated by an implementation as being
/// equivalent to INTERNAL_ERROR.
#[test]
fn sends_rst_stream_frame_with_unknown_error_code() {
use __group::sends_rst_stream_frame_with_unknown_error_code as test;
$body
}
}
}
}
}
50 changes: 50 additions & 0 deletions crates/httpwg/src/rfc9113/_7_error_codes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Section 7: Error Codes

use fluke_buffet::{IntoHalves, Piece};
use fluke_h2_parse::{ErrorCode, FrameType, GoAway, HeadersFlags, StreamId};

use crate::Conn;

/// Unknown or unsupported error codes MUST NOT trigger any special
/// behavior. These MAY be treated by an implementation as being
/// equivalent to INTERNAL_ERROR.
pub async fn sends_goaway_frame_with_unknown_error_code<IO: IntoHalves + 'static>(
mut conn: Conn<IO>,
) -> eyre::Result<()> {
conn.handshake().await?;

conn.write_frame(
FrameType::GoAway.into_frame(StreamId::CONNECTION),
GoAway {
additional_debug_data: Piece::empty(),
error_code: ErrorCode(0xff),
last_stream_id: StreamId(0),
},
)
.await?;

conn.verify_connection_still_alive().await?;

Ok(())
}

/// Unknown or unsupported error codes MUST NOT trigger any special
/// behavior. These MAY be treated by an implementation as being
/// equivalent to INTERNAL_ERROR.
pub async fn sends_rst_stream_frame_with_unknown_error_code<IO: IntoHalves + 'static>(
mut conn: Conn<IO>,
) -> eyre::Result<()> {
let stream_id = StreamId(1);

conn.handshake().await?;

let block_fragment = conn.encode_headers(&conn.common_headers("POST"))?;
conn.write_headers(stream_id, HeadersFlags::EndHeaders, block_fragment)
.await?;

conn.write_rst_stream(stream_id, ErrorCode(0xff)).await?;

conn.verify_connection_still_alive().await?;

Ok(())
}
1 change: 1 addition & 0 deletions crates/httpwg/src/rfc9113/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ pub mod _3_starting_http2;
pub mod _4_http_frames;
pub mod _5_streams_and_multiplexing;
pub mod _6_frame_definitions;
pub mod _7_error_codes;