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

#104: Fix encoding of URL path #105

Merged
merged 3 commits into from
Mar 13, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- name: Go test with Exasol version ${{ matrix.db }}
env:
DB_VERSION: ${{ matrix.db }}
run: go test -v -count 1 -coverprofile=coverage.out ./...
run: go test -v -p 1 -count 1 -coverprofile=coverage.out ./...

- name: SonarCloud Scan
if: matrix.go == env.DEFAULT_GO && matrix.db == env.DEFAULT_DB && github.repository_owner == 'exasol' && env.SONAR_TOKEN != null
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ pom.xml.versionsBackup
*.orig
*.old
*.md.html
*.flattened-pom.xml
*.flattened-pom.xml
__debug_bin*
2 changes: 1 addition & 1 deletion .project-keeper.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sources:
- type: golang
path: go.mod
version: 1.0.5
version: 1.0.6
1 change: 1 addition & 0 deletions doc/changes/changelog.md

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

11 changes: 11 additions & 0 deletions doc/changes/changes_1.0.6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Exasol Driver go 1.0.6, released 2024-03-13

Code name: Fix escaping of URL path

## Summary

This release fixes an issue when the user specifies a URL path containing characters like `?` or `%`. These were incorrectly escaped. We fixed this and now the URL path is used without modification when connecting to the database.

## Bugfix

* #104: Fixed encoding of URL path
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package version

const DriverVersion = "v1.0.5"
const DriverVersion = "v1.0.6"
21 changes: 14 additions & 7 deletions pkg/connection/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"io"
"net/url"
"strings"

"github.com/exasol/exasol-driver-go/internal/utils"
"github.com/exasol/exasol-driver-go/pkg/connection/wsconn"
Expand All @@ -32,23 +33,29 @@ func (c *Connection) Connect() error {
if err != nil {
return err
}

utils.ShuffleHosts(hosts)

for _, host := range hosts {
url := url.URL{
Scheme: c.getURIScheme(),
Host: fmt.Sprintf("%s:%d", host, c.Config.Port),
Path: c.Config.UrlPath,
var url *url.URL
url, err = c.createURL(host)
if err != nil {
return err
}
c.websocket, err = c.connectToHost(url)
c.websocket, err = c.connectToHost(*url)
if err == nil {
return nil
}
}
return err
}

func (c *Connection) createURL(host string) (*url.URL, error) {
urlPath := c.Config.UrlPath
if len(urlPath) > 0 && !strings.HasPrefix(urlPath, "/") {
urlPath = "/" + urlPath
}
return url.Parse(fmt.Sprintf("%s://%s:%d%s", c.getURIScheme(), host, c.Config.Port, urlPath))
}

func (c *Connection) connectToHost(url url.URL) (wsconn.WebsocketConnection, error) {
skipVerify := !c.Config.ValidateServerCertificate || c.Config.CertificateFingerprint != ""
ws, err := wsconn.CreateConnection(c.Ctx, skipVerify, c.Config.CertificateFingerprint, url)
Expand Down
27 changes: 27 additions & 0 deletions pkg/connection/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,33 @@ func (suite *WebsocketTestSuite) TestSendFailsAtParsingResponseData() {
suite.EqualError(err, `failed to parse response data "\"invalid\"": json: cannot unmarshal string into Go value of type types.PublicKeyResponse`)
}

func (suite *WebsocketTestSuite) TestCreateURL() {
for i, testCase := range []struct {
description string
urlPath string
expectedURL string
}{
{"empty url path", "", "ws://hostName:12345"},
{"url path with slash", "/", "ws://hostName:12345/"},
{"url path with leading slash", "/path", "ws://hostName:12345/path"},
{"url path without leading slash", "path", "ws://hostName:12345/path"},
{"url path with trailing slash", "path/", "ws://hostName:12345/path/"},
{"url path with leading and trailing slash", "/path/", "ws://hostName:12345/path/"},
{"url path with query", "path?query=1", "ws://hostName:12345/path?query=1"},
{"url with multiple query parameters", "path?query1=1&query2=2", "ws://hostName:12345/path?query1=1&query2=2"},
{"url path with query and fragment", "path?query=1#fragment", "ws://hostName:12345/path?query=1#fragment"},
{"url path with fragment", "path#fragment", "ws://hostName:12345/path#fragment"},
} {
suite.Run(fmt.Sprintf("Test%02d %s", i, testCase.description), func() {
connection := suite.createOpenConnection()
connection.Config.UrlPath = testCase.urlPath
url, err := connection.createURL("hostName")
suite.Assert().NoError(err)
suite.Equal(testCase.expectedURL, url.String())
})
}
}

func (suite *WebsocketTestSuite) createOpenConnection() *Connection {
conn := &Connection{
Config: &config.Config{Host: "invalid", Port: 12345, User: "user", Password: "password", ApiVersion: 42},
Expand Down