[MM-20620] Handle trailing slash when building marketplace api… (#13273)
Этот коммит содержится в:
коммит произвёл
Ben Schumacher
родитель
6e6a44764c
Коммит
8cafd11162
@@ -8,6 +8,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/services/httpservice"
|
||||
@@ -84,7 +85,7 @@ func closeBody(r *http.Response) {
|
||||
}
|
||||
|
||||
func (c *Client) buildURL(urlPath string, args ...interface{}) string {
|
||||
return fmt.Sprintf("%s%s", c.address, fmt.Sprintf(urlPath, args...))
|
||||
return fmt.Sprintf("%s/%s", strings.TrimRight(c.address, "/"), strings.TrimLeft(fmt.Sprintf(urlPath, args...), "/"))
|
||||
}
|
||||
|
||||
func (c *Client) doGet(u string) (*http.Response, error) {
|
||||
|
||||
44
services/marketplace/client_test.go
Обычный файл
44
services/marketplace/client_test.go
Обычный файл
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package marketplace
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBuildURL(t *testing.T) {
|
||||
config := &Client{}
|
||||
|
||||
testCases := map[string]struct {
|
||||
base string
|
||||
path string
|
||||
expected string
|
||||
}{
|
||||
"Base url with trailing slash and path with leading slash": {
|
||||
base: "https://api.integrations.mattermost.com/",
|
||||
path: "/api/v1/plugins",
|
||||
expected: "https://api.integrations.mattermost.com/api/v1/plugins",
|
||||
},
|
||||
"Base url without trailing slash and path with leading slash": {
|
||||
base: "https://api.integrations.mattermost.com",
|
||||
path: "/api/v1/plugins",
|
||||
expected: "https://api.integrations.mattermost.com/api/v1/plugins",
|
||||
},
|
||||
"Base url without trailing slash and path without leading slash": {
|
||||
base: "https://api.integrations.mattermost.com",
|
||||
path: "api/v1/plugins",
|
||||
expected: "https://api.integrations.mattermost.com/api/v1/plugins",
|
||||
},
|
||||
}
|
||||
|
||||
for name, tt := range testCases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
config.address = tt.base
|
||||
actual := config.buildURL(tt.path)
|
||||
assert.Equal(t, tt.expected, actual)
|
||||
})
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user