Skip to content

Commit

Permalink
added fix for listen directives in stub status and plus API configs
Browse files Browse the repository at this point in the history
  • Loading branch information
oliveromahony committed Jun 16, 2023
1 parent 2751524 commit 9d45a29
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 8 deletions.
8 changes: 6 additions & 2 deletions sdk/config_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func parseServerHost(parent *crossplane.Directive) string {
case "listen":
host, port, err := net.SplitHostPort(dir.Args[0])
if err == nil {
if host != "*" && host != "::" {
if host != "*" && host != "::" && host != "" {
serverName = host
}
listenPort = port
Expand Down Expand Up @@ -691,7 +691,11 @@ func isPort(value string) bool {
func parseLocationPath(location *crossplane.Directive) string {
path := "/"
if len(location.Args) > 0 {
path = location.Args[0]
if location.Args[0] != "=" {
path = location.Args[0]
} else {
path = location.Args[1]
}
}
return path
}
Expand Down
114 changes: 114 additions & 0 deletions sdk/config_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,54 @@ server {
deny all;
}
}
`,
},
{
plus: []string{
"http://127.0.0.1:80/api/",
},
conf: `
server {
listen 127.0.0.1;
server_name _;
location = /api/ {
api write=on;
allow 127.0.0.1;
deny all;
}
}
`,
},
{
plus: []string{
"http://localhost:80/api/",
},
conf: `
server {
listen 80;
server_name _;
location = /api/ {
api write=on;
allow 127.0.0.1;
deny all;
}
}
`,
},
{
plus: []string{
"http://localhost:80/api/",
},
conf: `
server {
listen :80;
server_name _;
location = /api/ {
api write=on;
allow 127.0.0.1;
deny all;
}
}
`,
},
{
Expand Down Expand Up @@ -939,6 +987,72 @@ server {
}
`,
},
{
oss: []string{
"http://localhost:80/stub_status",
},
conf: `
server {
server_name localhost;
listen :80;
error_page 500 502 503 504 /50x.html;
# ssl_certificate /usr/local/nginx/conf/cert.pem;
location / {
root /tmp/testdata/foo;
}
location /stub_status {
stub_status;
}
}
`,
},
{
oss: []string{
"http://localhost:80/stub_status",
},
conf: `
server {
server_name localhost;
listen 80;
error_page 500 502 503 504 /50x.html;
# ssl_certificate /usr/local/nginx/conf/cert.pem;
location / {
root /tmp/testdata/foo;
}
location /stub_status {
stub_status;
}
}
`,
},
{
oss: []string{
"http://localhost:80/stub_status",
},
conf: `
server {
server_name localhost;
listen 80;
error_page 500 502 503 504 /50x.html;
# ssl_certificate /usr/local/nginx/conf/cert.pem;
location / {
root /tmp/testdata/foo;
}
location = /stub_status {
stub_status;
}
}
`,
},
} {
f, err := os.CreateTemp(tmpDir, "conf")
assert.NoError(t, err)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9d45a29

Please sign in to comment.