Skip to content

Commit

Permalink
regression test for duplicate hsts
Browse files Browse the repository at this point in the history
  • Loading branch information
ElvinEfendi committed Dec 12, 2019
1 parent d5e197c commit 49ba53b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/e2e/framework/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Request Body:
location / {
lua_need_request_body on;
header_filter_by_lua_block {
if ngx.var.arg_hsts == "true" then
ngx.header["Strict-Transport-Security"] = "max-age=3600; preload"
end
}
content_by_lua_block {
ngx.header["Server"] = "echoserver"
Expand Down
12 changes: 12 additions & 0 deletions test/e2e/settings/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ var _ = framework.IngressNginxDescribe("Settings - TLS)", func() {
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(http.StatusOK))
Expect(resp.Header.Get("Strict-Transport-Security")).Should(Equal("max-age=86400; preload"))

By("overriding what's set from the upstream")

// we can not use gorequest here because it flattens the duplicate headers
// and specifically in case of Strict-Transport-Security it ignore extra headers
// intead of concatenating, rightfully. And I don't know of any API it provides for getting raw headers.
curlCmd := fmt.Sprintf("curl -I -k --fail --silent --resolve settings-tls:443:127.0.0.1 https://settings-tls/%v", "?hsts=true")
output, err := f.ExecIngressPod(curlCmd)
Expect(err).ToNot(HaveOccurred())
Expect(output).Should(ContainSubstring("strict-transport-security: max-age=86400; preload"))
// this is what the upstream sets
Expect(output).ShouldNot(ContainSubstring("strict-transport-security: max-age=3600; preload"))
})

It("should not use ports during the HTTP to HTTPS redirection", func() {
Expand Down

0 comments on commit 49ba53b

Please sign in to comment.