Skip to content

Commit

Permalink
Merge pull request #70 from nginxinc/NLB-3682-http3
Browse files Browse the repository at this point in the history
NLB-3682: Allow parsing for http3 module
  • Loading branch information
xynicole authored Oct 5, 2023
2 parents f54c08a + fcbb88f commit 73c76f9
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 0 deletions.
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": {
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": {
&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": {
&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": {
&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 {
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")
}
})
}
}

0 comments on commit 73c76f9

Please sign in to comment.