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
14 changes: 10 additions & 4 deletions catalog/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func handleNon200(rsp *http.Response, override map[int]error) error {
return e
}

func fromProps(props iceberg.Properties, o *options) {
func fromProps(props iceberg.Properties, o *options) error {
for k, v := range props {
switch k {
case keyWarehouseLocation:
Expand All @@ -464,7 +464,7 @@ func fromProps(props iceberg.Properties, o *options) {
case keyAuthUrl:
u, err := url.Parse(v)
if err != nil {
continue
return fmt.Errorf("invalid %s %q: %w", keyAuthUrl, v, err)
}
o.authUri = u
case keyOauthCredential:
Expand Down Expand Up @@ -496,6 +496,8 @@ func fromProps(props iceberg.Properties, o *options) {
}
}
}

return nil
}

func toProps(o *options) iceberg.Properties {
Expand Down Expand Up @@ -551,7 +553,9 @@ type Catalog struct {

func newCatalogFromProps(ctx context.Context, name string, uri string, p iceberg.Properties) (*Catalog, error) {
var ops options
fromProps(p, &ops)
if err := fromProps(p, &ops); err != nil {
return nil, err
}

r := &Catalog{name: name}
if err := r.init(ctx, &ops, uri); err != nil {
Expand Down Expand Up @@ -765,7 +769,9 @@ func (r *Catalog) fetchConfig(ctx context.Context, opts *options) (*http.Client,
r.endpoints = resolveEndpoints(rsp.Endpoints, cfg.GetBool(keyViewEndpointsSupported, false))

o := *opts
fromProps(cfg, &o)
if err := fromProps(cfg, &o); err != nil {
return nil, nil, err
}

if uri, ok := cfg["uri"]; ok {
r.baseURI, err = url.Parse(uri)
Expand Down
36 changes: 36 additions & 0 deletions catalog/rest/rest_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import (
"testing"
"time"

"github.com/apache/iceberg-go"
"github.com/apache/iceberg-go/catalog"
"github.com/aws/aws-sdk-go-v2/aws"
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/aws/aws-sdk-go-v2/config"
Expand All @@ -49,6 +51,40 @@ import (
"golang.org/x/sync/errgroup"
)

func TestLoadRegisteredCatalogRejectsInvalidAuthURL(t *testing.T) {
t.Parallel()

cat, err := catalog.Load(context.Background(), "rest", iceberg.Properties{
"uri": "http://example.com",
"rest.authorization-url": "http://[::1",
})
require.Error(t, err)
assert.Nil(t, cat)
assert.ErrorContains(t, err, "invalid rest.authorization-url")
}

func TestNewCatalogRejectsInvalidAuthURLFromConfig(t *testing.T) {
t.Parallel()

mux := http.NewServeMux()
srv := httptest.NewServer(mux)
defer srv.Close()

mux.HandleFunc("/v1/config", func(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(map[string]any{
"defaults": map[string]any{
"rest.authorization-url": "http://[::1",
},
"overrides": map[string]any{},
})
})

cat, err := NewCatalog(context.Background(), "rest", srv.URL)
require.Error(t, err)
assert.Nil(t, cat)
assert.ErrorContains(t, err, "invalid rest.authorization-url")
}

func TestTokenAuthenticationPriority(t *testing.T) {
t.Parallel()
mux := http.NewServeMux()
Expand Down
Loading