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

NLB-3682: Allow parsing for http3 module #70

Merged
merged 6 commits into from
Oct 5, 2023
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
27 changes: 27 additions & 0 deletions analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,18 @@ var directives = map[string][]uint{
"http2_recv_timeout": {
ngxHTTPMainConf | ngxHTTPSrvConf | ngxConfTake1,
},
"http3": {
xynicole marked this conversation as resolved.
Show resolved Hide resolved
ngxHTTPMainConf | ngxHTTPSrvConf | ngxConfFlag,
},
"http3_hq": {
ngxHTTPMainConf | ngxHTTPSrvConf | ngxConfFlag,
},
"http3_max_concurrent_streams": {
ngxHTTPMainConf | ngxHTTPSrvConf | ngxConfTake1,
},
"http3_stream_buffer_size": {
ngxHTTPMainConf | ngxHTTPSrvConf | ngxConfTake1,
},
"if": {
ngxHTTPSrvConf | ngxHTTPLocConf | ngxConfBlock | ngxConfExpr | ngxConf1More,
},
Expand Down Expand Up @@ -1302,6 +1314,21 @@ var directives = map[string][]uint{
"proxy_upload_rate": {
ngxStreamMainConf | ngxStreamSrvConf | ngxConfTake1,
},
"quic_active_connection_id_limit": {
ngxHTTPMainConf | ngxHTTPSrvConf | ngxConfTake1,
},
"quic_bpf": {
ngxMainConf | ngxDirectConf | ngxConfFlag,
},
"quic_gso": {
ngxHTTPMainConf | ngxHTTPSrvConf | ngxConfFlag,
},
"quic_host_key": {
ngxHTTPMainConf | ngxHTTPSrvConf | ngxConfTake1,
},
"quic_retry": {
ngxHTTPMainConf | ngxHTTPSrvConf | ngxConfFlag,
},
"random": {
ngxHTTPUpsConf | ngxConfNoArgs | ngxConfTake12,
ngxStreamUpsConf | ngxConfNoArgs | ngxConfTake12,
Expand Down
207 changes: 207 additions & 0 deletions analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,3 +1093,210 @@ func TestAnalyze_nap_app_protect_reconnect_period_seconds(t *testing.T) {
})
}
}

//nolint:funlen
func TestAnalyze_http3(t *testing.T) {
t.Parallel()
testcases := map[string]struct {
stmt *Directive
ctx blockCtx
wantErr bool
}{
"http3 ok": {
&Directive{
Directive: "http3",
Args: []string{"on"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"http3 not ok": {
&Directive{
Directive: "http3",
Args: []string{"somevalue"},
Line: 5,
},
blockCtx{"http", "server"},
true,
},
"http3_hq ok": {
xynicole marked this conversation as resolved.
Show resolved Hide resolved
&Directive{
Directive: "http3_hq",
Args: []string{"on"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"http3_hq not ok": {
&Directive{
Directive: "http3_hq",
Args: []string{"somevalue"},
Line: 5,
},
blockCtx{"http", "server"},
true,
},
"http3_max_concurrent_streams ok": {
xynicole marked this conversation as resolved.
Show resolved Hide resolved
&Directive{
Directive: "http3_max_concurrent_streams",
Args: []string{"10"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"http3_max_concurrent_streams not ok": {
&Directive{
Directive: "http3_max_concurrent_streams",
Args: []string{"10"},
Line: 5,
},
blockCtx{"http", "location"},
true,
},
"http3_stream_buffer_size ok": {
xynicole marked this conversation as resolved.
Show resolved Hide resolved
&Directive{
Directive: "http3_stream_buffer_size",
Args: []string{"128k"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"http3_stream_buffer_size not ok": {
&Directive{
Directive: "http3_stream_buffer_size",
Args: []string{"128k"},
Line: 5,
},
blockCtx{"http", "location"},
true,
},
}

for name, tc := range testcases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
err := analyze("nginx.conf", tc.stmt, ";", tc.ctx, &ParseOptions{})

if !tc.wantErr && err != nil {
xynicole marked this conversation as resolved.
Show resolved Hide resolved
t.Fatal(err)
}

if tc.wantErr && err == nil {
t.Fatal("expected error, got nil")
}
})
}
}

//nolint:funlen
func TestAnalyze_quic(t *testing.T) {
t.Parallel()
testcases := map[string]struct {
stmt *Directive
ctx blockCtx
wantErr bool
}{
"quic_active_connection_id_limit ok": {
&Directive{
Directive: "quic_active_connection_id_limit",
Args: []string{"2"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"quic_active_connection_id_limit not ok": {
&Directive{
Directive: "quic_active_connection_id_limit",
Args: []string{"2"},
Line: 5,
},
blockCtx{"http", "location"},
true,
},
"quic_bpf ok": {
&Directive{
Directive: "quic_bpf",
Args: []string{"on"},
Line: 5,
},
blockCtx{"main"},
false,
},
"quic_bpf not ok": {
&Directive{
Directive: "quic_bpf",
Args: []string{"on"},
Line: 5,
},
blockCtx{"http", "server"},
true,
},
"quic_gso ok": {
&Directive{
Directive: "quic_gso",
Args: []string{"on"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"quic_gso not ok": {
&Directive{
Directive: "quic_gso",
Args: []string{"somevalue"},
Line: 5,
},
blockCtx{"http", "server"},
true,
},
"quic_host_key ok": {
&Directive{
Directive: "http3_max_concurrent_streams",
Args: []string{"somefile"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"quic_retry ok": {
&Directive{
Directive: "quic_retry",
Args: []string{"off"},
Line: 5,
},
blockCtx{"http", "server"},
false,
},
"quic_retry not ok": {
&Directive{
Directive: "quic_retry",
Args: []string{"somevalue"},
Line: 5,
},
blockCtx{"http", "server"},
true,
},
}

for name, tc := range testcases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
err := analyze("nginx.conf", tc.stmt, ";", tc.ctx, &ParseOptions{})

if !tc.wantErr && err != nil {
t.Fatal(err)
}

if tc.wantErr && err == nil {
t.Fatal("expected error, got nil")
}
})
}
}