-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolver/dns: support custom dns authority
wip add custom resolver test
- Loading branch information
Elliot Shepherd
committed
Sep 17, 2018
1 parent
f2aaa9b
commit 91db3ef
Showing
10 changed files
with
359 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// +build go1.9 | ||
|
||
/* | ||
* | ||
* Copyright 2018 gRPC authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package dns | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
|
||
"golang.org/x/net/context" | ||
"google.golang.org/grpc/internal/leakcheck" | ||
"google.golang.org/grpc/resolver" | ||
) | ||
|
||
func TestCustomAuthority(t *testing.T) { | ||
defer leakcheck.Check(t) | ||
|
||
tests := []struct { | ||
authority string | ||
authorityWant string | ||
parseError bool | ||
}{ | ||
{ | ||
"4.3.2.1:53", | ||
"4.3.2.1:53", | ||
false, | ||
}, | ||
{ | ||
"4.3.2.1:123", | ||
"4.3.2.1:123", | ||
false, | ||
}, | ||
{ | ||
"4.3.2.1", | ||
"4.3.2.1:53", | ||
false, | ||
}, | ||
{ | ||
"::1", | ||
"[::1]:53", | ||
false, | ||
}, | ||
{ | ||
"[::1]", | ||
"[::1]:53", | ||
false, | ||
}, | ||
{ | ||
"[::1]:123", | ||
"[::1]:123", | ||
false, | ||
}, | ||
{ | ||
"dnsserver.com", | ||
"dnsserver.com:53", | ||
false, | ||
}, | ||
{ | ||
":123", | ||
"localhost:123", | ||
false, | ||
}, | ||
{ | ||
":", | ||
"", | ||
true, | ||
}, | ||
{ | ||
"[::1]:", | ||
"", | ||
true, | ||
}, | ||
{ | ||
"dnsserver.com:", | ||
"", | ||
true, | ||
}, | ||
} | ||
oldCustomAuthorityDialler := customAuthorityDialler | ||
defer func() { | ||
customAuthorityDialler = oldCustomAuthorityDialler | ||
}() | ||
for _, a := range tests { | ||
|
||
parsed, err := ensureAuthorityPort(a.authority) | ||
if err != nil { | ||
if !a.parseError { | ||
t.Errorf("unexpected authority parse error. input: %s error: %s", a.authority, err) | ||
} | ||
continue | ||
} | ||
if parsed != a.authorityWant { | ||
t.Errorf("authority did not parse correctly. input: %s expected: %s actual: %s", a.authority, a.authorityWant, parsed) | ||
} | ||
|
||
customAuthorityDialler = func(authority string) func(ctx context.Context, network, address string) (net.Conn, error) { | ||
if authority != a.authorityWant { | ||
t.Errorf("wrong custom authority passed to resolver. input: %s expected: %s actual: %s", a.authority, a.authorityWant, authority) | ||
} | ||
return func(ctx context.Context, network, address string) (net.Conn, error) { | ||
var dialer net.Dialer | ||
return dialer.DialContext(ctx, network, authority) | ||
} | ||
} | ||
|
||
b := NewBuilder() | ||
cc := &testClientConn{target: "foo.bar.com"} | ||
r, _ := b.Build(resolver.Target{Endpoint: "foo.bar.com", Authority: a.authority}, cc, resolver.BuildOption{}) | ||
r.Close() | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.