diff --git a/lex_test.go b/lex_test.go index cb3c5148..ba569121 100644 --- a/lex_test.go +++ b/lex_test.go @@ -315,6 +315,73 @@ var lexFixtures = []lexFixture{ {"}", 39}, {"}", 40}, }}, + {"lua-block-cert-slim", []tokenLine{ + {"http", 1}, + {"{", 1}, + {"server", 2}, + {"{", 2}, + {"ssl_certificate_by_lua_block", 3}, + {"{", 3}, + {"print(\"Test lua ssl certificate!\")", 4}, + {"}", 5}, + {"}", 6}, + {"}", 7}, + }}, + {"lua-block-cert-double-server", []tokenLine{ + {"http", 1}, + {"{", 1}, + {"server", 2}, + {"{", 2}, + {"listen", 3}, + {"443", 3}, + {"ssl", 3}, + {";", 3}, + {"server_name", 4}, + {"lua.example.com", 4}, + {";", 4}, + {"location", 6}, + {"/", 6}, + {"{", 6}, + {"root", 7}, + {"/usr/share/nginx/html", 7}, + {";", 7}, + {"index", 8}, + {"index.html", 8}, + {"index.htm", 8}, + {";", 8}, + {"}", 9}, + {"error_page", 11}, + {"500", 11}, + {"502", 11}, + {"503", 11}, + {"504", 11}, + {"/50x.html", 11}, + {";", 11}, + {"location", 12}, + {"=", 12}, + {"/50x.html", 12}, + {"{", 12}, + {"root", 13}, + {"/usr/share/nginx/html", 13}, + {";", 13}, + {"}", 14}, + {"ssl_certificate", 16}, + {"/etc/nginx/ssl/cert1.crt", 16}, + {";", 16}, + {"ssl_certificate_key", 17}, + {"/etc/nginx/ssl/key1.key", 17}, + {";", 17}, + {"ssl_certificate_by_lua_block", 19}, + {"{", 19}, + {"\n print(\"Test lua ssl certificate!\")\n ", 19}, + {")", 20}, + {"}", 21}, + {"}", 22}, + {"server", 24}, + {"{", 24}, + {"}", 25}, + {"}", 26}, + }}, {"lua-block-larger", []tokenLine{ {"http", 1}, {"{", 1}, diff --git a/parse_test.go b/parse_test.go index a245d052..ef9e65b2 100644 --- a/parse_test.go +++ b/parse_test.go @@ -1834,6 +1834,144 @@ var parseFixtures = []parseFixture{ }, }, }}, + {"lua-block-cert-slim", "", ParseOptions{ + SingleFile: true, + ErrorOnUnknownDirectives: true, + DirectiveSources: []MatchFunc{MatchNginxPlusLatest, MatchLuaLatest}, + LexOptions: LexOptions{ + Lexers: []RegisterLexer{lua.RegisterLexer()}, + }, + }, Payload{ + Status: "ok", + Errors: []PayloadError{}, + Config: []Config{ + { + File: getTestConfigPath("lua-block-cert-slim", "nginx.conf"), + Status: "ok", + Parsed: Directives{ + { + Directive: "http", + Line: 1, + Args: []string{}, + Block: Directives{ + { + Directive: "server", + Line: 2, + Args: []string{}, + Block: Directives{ + { + Directive: "ssl_certificate_by_lua_block", + Line: 3, + Args: []string{"\n print(\"Test lua ssl certificate!\")\n "}, + }, + }, + }, + }, + }, + }, + }, + }, + }}, + {"lua-block-cert-double-server", "", ParseOptions{ + SingleFile: true, + ErrorOnUnknownDirectives: true, + DirectiveSources: []MatchFunc{MatchNginxPlusLatest, MatchLuaLatest}, + LexOptions: LexOptions{ + Lexers: []RegisterLexer{lua.RegisterLexer()}, + }, + }, Payload{ + Status: "ok", + Errors: []PayloadError{}, + Config: []Config{ + { + File: "testdata/configs/lua-block-cert-double-server/nginx.conf", + Status: "ok", + Errors: []ConfigError{}, + Parsed: Directives{ + { + Directive: "http", + Line: 1, + Args: []string{}, + Block: Directives{ + { + Directive: "server", + Line: 2, + Args: []string{}, + Block: Directives{ + { + Directive: "listen", + Line: 3, + Args: []string{"443", "ssl"}, + }, + { + Directive: "server_name", + Line: 4, + Args: []string{"lua.example.com"}, + }, + { + Directive: "location", + Line: 6, + Args: []string{"/"}, + Block: Directives{ + { + Directive: "root", + Line: 7, + Args: []string{"/usr/share/nginx/html"}, + }, + { + Directive: "index", + Line: 8, + Args: []string{"index.html", "index.htm"}, + }, + }, + }, + { + Directive: "error_page", + Line: 11, + Args: []string{"500", "502", "503", "504", "/50x.html"}, + }, + { + Directive: "location", + Line: 12, + Args: []string{"=", "/50x.html"}, + Block: Directives{ + { + Directive: "root", + Line: 13, + Args: []string{"/usr/share/nginx/html"}, + }, + }, + }, + { + Directive: "ssl_certificate", + Line: 16, + Args: []string{"/etc/nginx/ssl/cert1.crt"}, + }, + { + Directive: "ssl_certificate_key", + Line: 17, + Args: []string{"/etc/nginx/ssl/key1.key"}, + }, + { + Directive: "ssl_certificate_by_lua_block", + Line: 19, + Args: []string{ + "\n print(\"Test lua ssl certificate!\")\n ", + }, + }, + }, + }, + { + Directive: "server", + Line: 24, + Args: []string{}, + }, + }, + }, + }, + }, + }, + }}, {"lua-block-larger", "", ParseOptions{ SingleFile: true, ErrorOnUnknownDirectives: true, diff --git a/testdata/configs/lua-block-cert-double-server/nginx.conf b/testdata/configs/lua-block-cert-double-server/nginx.conf new file mode 100644 index 00000000..029f4c10 --- /dev/null +++ b/testdata/configs/lua-block-cert-double-server/nginx.conf @@ -0,0 +1,26 @@ +http { + server { + listen 443 ssl; + server_name lua.example.com; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } + + ssl_certificate /etc/nginx/ssl/cert1.crt; + ssl_certificate_key /etc/nginx/ssl/key1.key; + + ssl_certificate_by_lua_block { + print("Test lua ssl certificate!") + } + } + + server { + } +} diff --git a/testdata/configs/lua-block-cert-double-server/nginx.json b/testdata/configs/lua-block-cert-double-server/nginx.json new file mode 100644 index 00000000..ca5a48b3 --- /dev/null +++ b/testdata/configs/lua-block-cert-double-server/nginx.json @@ -0,0 +1,93 @@ +{ + "status": "ok", + "errors": [], + "config": [ + { + "file": "testdata/configs/lua-block-cert-double-server/nginx.conf", + "status": "ok", + "errors": [], + "parsed": [ + { + "directive": "http", + "line": 1, + "args": [], + "block": [ + { + "directive": "server", + "line": 2, + "args": [], + "block": [ + { + "directive": "listen", + "line": 3, + "args": ["443", "ssl"] + }, + { + "directive": "server_name", + "line": 4, + "args": ["lua.example.com"] + }, + { + "directive": "location", + "line": 6, + "args": ["/"], + "block": [ + { + "directive": "root", + "line": 7, + "args": ["/usr/share/nginx/html"] + }, + { + "directive": "index", + "line": 8, + "args": ["index.html", "index.htm"] + } + ] + }, + { + "directive": "error_page", + "line": 11, + "args": ["500", "502", "503", "504", "/50x.html"] + }, + { + "directive": "location", + "line": 12, + "args": ["=", "/50x.html"], + "block": [ + { + "directive": "root", + "line": 13, + "args": ["/usr/share/nginx/html"] + } + ] + }, + { + "directive": "ssl_certificate", + "line": 16, + "args": ["/etc/nginx/ssl/cert1.crt"] + }, + { + "directive": "ssl_certificate_key", + "line": 17, + "args": ["/etc/nginx/ssl/key1.key"] + }, + { + "directive": "ssl_certificate_by_lua_block", + "line": 19, + "args": [ + "\n print(\"Test lua ssl certificate!\")\n " + ] + } + ] + }, + { + "directive": "server", + "line": 24, + "args": [] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/testdata/configs/lua-block-cert-slim/nginx.conf b/testdata/configs/lua-block-cert-slim/nginx.conf new file mode 100644 index 00000000..dc61c65a --- /dev/null +++ b/testdata/configs/lua-block-cert-slim/nginx.conf @@ -0,0 +1,7 @@ +http { + server { + ssl_certificate_by_lua_block { + print("Test lua ssl certificate!") + } + } +} diff --git a/testdata/configs/lua-block-cert-slim/nginx.json b/testdata/configs/lua-block-cert-slim/nginx.json new file mode 100644 index 00000000..ce229a04 --- /dev/null +++ b/testdata/configs/lua-block-cert-slim/nginx.json @@ -0,0 +1,34 @@ +{ + "status": "ok", + "errors": [], + "config": [ + { + "file": "testdata/configs/lua-block-cert-slim/nginx.conf", + "status": "ok", + "errors": [], + "parsed": [ + { + "directive": "http", + "line": 1, + "args": [], + "block": [ + { + "directive": "server", + "line": 2, + "args": [], + "block": [ + { + "directive": "ssl_certificate_by_lua_block", + "line": 3, + "args": [ + "\n print(\"Test lua ssl certificate!\")\n " + ] + } + ] + } + ] + } + ] + } + ] +} \ No newline at end of file