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

xds/google-c2p: validate url for no authorities #5756

Merged
merged 3 commits into from Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions xds/googledirectpath/googlec2p.go
Expand Up @@ -92,6 +92,10 @@ type c2pResolverBuilder struct {
}

func (c2pResolverBuilder) Build(t resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
if t.URL.Host != "" {
return nil, fmt.Errorf("google-c2p URI scheme does not support authorities")
}

if !runDirectPath() {
// If not xDS, fallback to DNS.
t.Scheme = dnsName
Expand Down
13 changes: 13 additions & 0 deletions xds/googledirectpath/googlec2p_test.go
Expand Up @@ -19,6 +19,7 @@
package googledirectpath

import (
"net/url"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -251,3 +252,15 @@ func TestBuildXDS(t *testing.T) {
})
}
}

// TestBuildFailsWhenCalledWithAuthority asserts that c2p resolver.build
// fails when called with a URL with an authority.
easwars marked this conversation as resolved.
Show resolved Hide resolved
func TestBuildFailsWhenCalledWithAuthority(t *testing.T) {
builder := resolver.Get(c2pScheme)
targetURL, _ := url.Parse("google-c2p://an-authority/resource")

_, err := builder.Build(resolver.Target{URL: *targetURL}, nil, resolver.BuildOptions{})
if err == nil {
t.Fatalf("c2p resolver should not support target's with authorities, but build succeeded")
}
easwars marked this conversation as resolved.
Show resolved Hide resolved
}