Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fix for listen directives in stub status and plus API configs #348

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.