Skip to content

Commit

Permalink
Merge pull request #259 from pasinskim/1.3
Browse files Browse the repository at this point in the history
MEN-1620 Remove trailing slash from server URL configuration.
  • Loading branch information
pasinskim committed Dec 5, 2017
2 parents d3360e0 + 2d17e60 commit def00f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package main
import (
"encoding/json"
"io/ioutil"
"strings"

"github.com/mendersoftware/log"
"github.com/mendersoftware/mender/client"
Expand Down Expand Up @@ -56,6 +57,10 @@ func LoadConfig(configFile string) (*menderConfig, error) {
return nil, err
}

if strings.HasSuffix(confFromFile.ServerURL, "/") {
confFromFile.ServerURL = strings.TrimSuffix(confFromFile.ServerURL, "/")
}

return &confFromFile, nil
}

Expand Down
11 changes: 11 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,14 @@ func Test_loadConfig_correctConfFile_returnsConfiguration(t *testing.T) {

validateConfiguration(t, config)
}

func TestServerURLConfig(t *testing.T) {
configFile, _ := os.Create("mender.config")
defer os.Remove("mender.config")

configFile.WriteString(`{"ServerURL": "https://mender.io/"}`)

config, err := LoadConfig("mender.config")
assert.NoError(t, err)
assert.Equal(t, "https://mender.io", config.ServerURL)
}

0 comments on commit def00f1

Please sign in to comment.