Skip to content

Commit c6327ed

Browse files
committed
fix: add auth_jwt_require directive
1 parent 94d50bf commit c6327ed

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

analyze.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,9 @@ var directives = map[string][]uint{
20742074
"auth_jwt_type": {
20752075
ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxHTTPLmtConf | ngxConfTake1,
20762076
},
2077+
"auth_jwt_require": {
2078+
ngxHTTPMainConf | ngxHTTPSrvConf | ngxHTTPLocConf | ngxHTTPLmtConf | ngxConf1More,
2079+
},
20772080
"f4f": {
20782081
ngxHTTPLocConf | ngxConfNoArgs,
20792082
},

analyze_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,59 @@ func TestAnalyze_auth_jwt(t *testing.T) {
119119
}
120120
}
121121

122+
func TestAnalyze_auth_jwt_require(t *testing.T) {
123+
t.Parallel()
124+
testcases := map[string]struct {
125+
stmt *Directive
126+
ctx blockCtx
127+
wantErr bool
128+
}{
129+
"auth_jwt_require ok": {
130+
&Directive{
131+
Directive: "auth_jwt_require",
132+
Args: []string{"$value1", "$value2"},
133+
Line: 5,
134+
},
135+
blockCtx{"http", "location", "limit_except"},
136+
false,
137+
},
138+
"auth_jwt_require with error code ok": {
139+
&Directive{
140+
Directive: "auth_jwt_require",
141+
Args: []string{"$value1", "$value2", "error=403"},
142+
Line: 5,
143+
},
144+
blockCtx{"http", "location", "limit_except"},
145+
false,
146+
},
147+
"auth_jwt_require not ok": {
148+
&Directive{
149+
Directive: "auth_jwt_require",
150+
Args: []string{"$value"},
151+
Line: 5,
152+
},
153+
blockCtx{"stream"},
154+
true,
155+
},
156+
}
157+
158+
for name, tc := range testcases {
159+
tc := tc
160+
t.Run(name, func(t *testing.T) {
161+
t.Parallel()
162+
err := analyze("nginx.conf", tc.stmt, ";", tc.ctx, &ParseOptions{})
163+
164+
if !tc.wantErr && err != nil {
165+
t.Fatal(err)
166+
}
167+
168+
if tc.wantErr && err == nil {
169+
t.Fatal("expected error, got nil")
170+
}
171+
})
172+
}
173+
}
174+
122175
func TestAnalyze_njs(t *testing.T) {
123176
t.Parallel()
124177
testcases := map[string]struct {

0 commit comments

Comments
 (0)