Skip to content

Commit

Permalink
fix: uri root path checking (#5778)
Browse files Browse the repository at this point in the history
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.

This config will display `Your service is accessible at https://my-domain.com//v2` after deploy successfully.

```yaml
http:
  path: '/v2'
```

This PR fix this.
  • Loading branch information
Folyd committed May 14, 2024
1 parent eae7ae7 commit ae42fd8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/pkg/describe/uri.go
Expand Up @@ -5,6 +5,7 @@ package describe

import (
"fmt"
"regexp"
"strings"

"github.com/aws/copilot-cli/internal/pkg/term/color"
Expand Down Expand Up @@ -403,14 +404,17 @@ func (u *LBWebServiceURI) String() string {

func (u *accessURI) strings() []string {
var uris []string
re := regexp.MustCompile("/+")
for _, dnsName := range u.DNSNames {
protocol := "http://"
if u.HTTPS {
protocol = "https://"
}
path := ""
if u.Path != "/" {
if !strings.HasPrefix(u.Path, "/") {
path = fmt.Sprintf("/%s", u.Path)
} else if u.Path != "/" {
path = re.ReplaceAllString(u.Path, "/")
}
uris = append(uris, color.HighlightResource(protocol+dnsName+path))
}
Expand Down
42 changes: 41 additions & 1 deletion internal/pkg/describe/uri_test.go
Expand Up @@ -6,9 +6,10 @@ package describe
import (
"errors"
"fmt"
"github.com/aws/copilot-cli/internal/pkg/aws/ecs"
"testing"

"github.com/aws/copilot-cli/internal/pkg/aws/ecs"

"github.com/aws/copilot-cli/internal/pkg/deploy/cloudformation/stack"
"github.com/aws/copilot-cli/internal/pkg/describe/mocks"
"github.com/aws/copilot-cli/internal/pkg/template"
Expand Down Expand Up @@ -680,6 +681,24 @@ func TestLBWebServiceURI_String(t *testing.T) {

wanted: "http://jobs.test.phonetool.com",
},
"http with /v2 path": {
accessDNSNames: []string{"jobs.test.phonetool.com"},
accessPath: "/v2",

wanted: "http://jobs.test.phonetool.com/v2",
},
"http with multiple slash path": {
accessDNSNames: []string{"jobs.test.phonetool.com"},
accessPath: "//v2",

wanted: "http://jobs.test.phonetool.com/v2",
},
"http with non-root path": {
accessDNSNames: []string{"jobs.test.phonetool.com"},
accessPath: "v2",

wanted: "http://jobs.test.phonetool.com/v2",
},
"cloudfront": {
accessDNSNames: []string{"abc.cloudfront.net"},
accessPath: "svc",
Expand Down Expand Up @@ -707,6 +726,27 @@ func TestLBWebServiceURI_String(t *testing.T) {

wanted: "https://jobs.test.phonetool.com",
},
"https with /v2 path": {
accessDNSNames: []string{"jobs.test.phonetool.com"},
accessPath: "/v2",
accessHTTPS: true,

wanted: "https://jobs.test.phonetool.com/v2",
},
"https with multiple slash path": {
accessDNSNames: []string{"jobs.test.phonetool.com"},
accessPath: "//v2",
accessHTTPS: true,

wanted: "https://jobs.test.phonetool.com/v2",
},
"https with non-root path": {
accessDNSNames: []string{"jobs.test.phonetool.com"},
accessPath: "v2",
accessHTTPS: true,

wanted: "https://jobs.test.phonetool.com/v2",
},
}

for name, tc := range testCases {
Expand Down

0 comments on commit ae42fd8

Please sign in to comment.