From 72674222cd2981e951460d43a093693d85ba62fa Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 1 Nov 2021 19:31:26 +0800 Subject: [PATCH 1/4] chore: add a test case for single quoted arguments --- internal/lagoonyml/lint_test.go | 4 ++++ .../lagoonyml/testdata/valid.4.lagoon.yml | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 internal/lagoonyml/testdata/valid.4.lagoon.yml diff --git a/internal/lagoonyml/lint_test.go b/internal/lagoonyml/lint_test.go index ba98808..b698b35 100644 --- a/internal/lagoonyml/lint_test.go +++ b/internal/lagoonyml/lint_test.go @@ -27,6 +27,10 @@ func TestLint(t *testing.T) { input: "testdata/valid.3.lagoon.yml", valid: true, }, + "single quoted arguments": { + input: "testdata/valid.4.lagoon.yml", + valid: true, + }, "invalid.0.lagoon.yml": { input: "testdata/invalid.0.lagoon.yml", valid: false, diff --git a/internal/lagoonyml/testdata/valid.4.lagoon.yml b/internal/lagoonyml/testdata/valid.4.lagoon.yml new file mode 100644 index 0000000..aa9f947 --- /dev/null +++ b/internal/lagoonyml/testdata/valid.4.lagoon.yml @@ -0,0 +1,21 @@ +environments: + main: + monitoring_urls: + - "https://www.example.com" + - "https://www.example.com/special_page" + routes: + - nginx: + - example.com + - "www.example.com": + tls-acme: 'true' + insecure: Redirect + hsts: max-age=31536000 + - "example.com": + annotations: + nginx.ingress.kubernetes.io/server-snippet: | + set_real_ip_from 1.2.3.4/32; + - "dev.example.com": + annotations: + nginx.ingress.kubernetes.io/server-snippet: | + set_real_ip_from 1.2.3.4/32; + add_header 'Permissions-Policy' 'geolocation=(), microphone=()'; From 67ceb86091a7aca3715553df2b5da9641c0bb570 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 1 Nov 2021 19:18:31 +0800 Subject: [PATCH 2/4] fix: handle single-quoted header arguments --- internal/lagoonyml/routeannotation.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/lagoonyml/routeannotation.go b/internal/lagoonyml/routeannotation.go index 44d39ae..ecd2834 100644 --- a/internal/lagoonyml/routeannotation.go +++ b/internal/lagoonyml/routeannotation.go @@ -18,9 +18,9 @@ const ( // annotations. var validSnippets = regexp.MustCompile( `^(rewrite +[^; ]+ +[^; ]+( (last|break|redirect|permanent))?;|` + - `add_header +([^; ]+|"[^"]+")+ +([^; ]+|"[^"]+");|` + + `add_header +([^; ]+|"[^"]+"|'[^']+') +([^; ]+|"[^"]+"|'[^']+');|` + `set_real_ip_from +[^; ]+;|` + - `more_set_headers +(-s +"[^"]+"|-t +"[^"]+"|"[^"]+")+;|` + + `more_set_headers +(-s +("[^"]+"|'[^']+')|-t +("[^"]+"|'[^']+')|("[^"]+"|'[^']+'))+;|` + ` )+$`) // validate returns true if the annotations are valid, and false otherwise. From 19c6b6842d8ab3f0b57f439d3e60a0052a317758 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 1 Nov 2021 20:22:07 +0800 Subject: [PATCH 3/4] chore: add test for optional add_headers "always" suffix --- internal/lagoonyml/lint_test.go | 4 ++++ internal/lagoonyml/testdata/valid.5.lagoon.yml | 9 +++++++++ 2 files changed, 13 insertions(+) create mode 100644 internal/lagoonyml/testdata/valid.5.lagoon.yml diff --git a/internal/lagoonyml/lint_test.go b/internal/lagoonyml/lint_test.go index b698b35..c68bc18 100644 --- a/internal/lagoonyml/lint_test.go +++ b/internal/lagoonyml/lint_test.go @@ -31,6 +31,10 @@ func TestLint(t *testing.T) { input: "testdata/valid.4.lagoon.yml", valid: true, }, + "add_header ... always": { + input: "testdata/valid.5.lagoon.yml", + valid: true, + }, "invalid.0.lagoon.yml": { input: "testdata/invalid.0.lagoon.yml", valid: false, diff --git a/internal/lagoonyml/testdata/valid.5.lagoon.yml b/internal/lagoonyml/testdata/valid.5.lagoon.yml new file mode 100644 index 0000000..e435fcc --- /dev/null +++ b/internal/lagoonyml/testdata/valid.5.lagoon.yml @@ -0,0 +1,9 @@ +environments: + main: + routes: + - nginx: + - "dev.example.com": + annotations: + nginx.ingress.kubernetes.io/server-snippet: | + set_real_ip_from 1.2.3.4/32; + add_header 'Permissions-Policy' 'geolocation=(), microphone=()' always; From ff5be588a346a58212a80dcdf4b2f01794c45fa6 Mon Sep 17 00:00:00 2001 From: Scott Leggett Date: Mon, 1 Nov 2021 20:22:45 +0800 Subject: [PATCH 4/4] fix: handle optional add_headers "always" suffix --- internal/lagoonyml/routeannotation.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/lagoonyml/routeannotation.go b/internal/lagoonyml/routeannotation.go index ecd2834..69799f5 100644 --- a/internal/lagoonyml/routeannotation.go +++ b/internal/lagoonyml/routeannotation.go @@ -18,7 +18,7 @@ const ( // annotations. var validSnippets = regexp.MustCompile( `^(rewrite +[^; ]+ +[^; ]+( (last|break|redirect|permanent))?;|` + - `add_header +([^; ]+|"[^"]+"|'[^']+') +([^; ]+|"[^"]+"|'[^']+');|` + + `add_header +([^; ]+|"[^"]+"|'[^']+') +([^; ]+|"[^"]+"|'[^']+')( always)?;|` + `set_real_ip_from +[^; ]+;|` + `more_set_headers +(-s +("[^"]+"|'[^']+')|-t +("[^"]+"|'[^']+')|("[^"]+"|'[^']+'))+;|` + ` )+$`)