Skip to content
Open
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
2 changes: 1 addition & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func (c *conn) handleStagingRemove(ctx context.Context, presignedUrl string, hea
content, err := io.ReadAll(res.Body)

if err != nil || !Succeeded(res) {
return dbsqlerrint.NewDriverError(ctx, fmt.Sprintf("staging operation over HTTP was unsuccessful: %d-%s, nil", res.StatusCode, content), nil)
return dbsqlerrint.NewDriverError(ctx, fmt.Sprintf("staging operation over HTTP was unsuccessful: %d-%s", res.StatusCode, content), nil)
}

return nil
Expand Down
18 changes: 18 additions & 0 deletions staging_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
package dbsql

import (
"context"
"net/http"
"net/http/httptest"
"testing"

"github.com/databricks/databricks-sql-go/internal/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestHandleStagingRemoveHTTPError(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusForbidden)
w.Write([]byte("Access Denied"))
}))
defer server.Close()

c := &conn{cfg: config.WithDefaults()}
err := c.handleStagingRemove(context.Background(), server.URL, map[string]string{})
require.NotNil(t, err)
assert.NotContains(t, err.Error(), ", nil", "error message should not contain literal \", nil\"")
}

func TestPathAllowed(t *testing.T) {
t.Run("Should not allow paths that don't share directory", func(t *testing.T) {
stagingAllowedLocalPath := []string{"/var/www/html"}
Expand Down