Skip to content
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
11 changes: 9 additions & 2 deletions agent/connect/testing_ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func TestServerLeaf(t testing.T, dc string, root *structs.CARoot) (string, strin

// TestCSR returns a CSR to sign the given service along with the PEM-encoded
// private key for this certificate.
func TestCSR(t testing.T, uri CertURI) (string, string) {
func TestCSR(t Fatalfer, uri CertURI) (string, string) {
template := &x509.CertificateRequest{
URIs: []*url.URL{uri.URI()},
SignatureAlgorithm: x509.ECDSAWithSHA256,
Expand Down Expand Up @@ -387,7 +387,7 @@ func testKeyID(t testing.T, raw interface{}) []byte {
// which will be the same for multiple CAs/Leafs. Also note that our UUID
// generator also reads from crypto rand and is called far more often during
// tests than this will be.
func testPrivateKey(t testing.T, keyType string, keyBits int) (crypto.Signer, string) {
func testPrivateKey(t Fatalfer, keyType string, keyBits int) (crypto.Signer, string) {
pk, pkPEM, err := GeneratePrivateKeyWithConfig(keyType, keyBits)
if err != nil {
t.Fatalf("error generating private key: %s", err)
Expand All @@ -396,6 +396,13 @@ func testPrivateKey(t testing.T, keyType string, keyBits int) (crypto.Signer, st
return pk, pkPEM
}

// Fatalfer is a subset of testing.T that only has the Fatalf method. This is
// used to avoid import cycles in the connect package, since we use this in
// places that need to call Fatalf but don't need the full testing.T interface.
type Fatalfer interface {
Fatalf(format string, args ...any)
}

// testSerialNumber generates a serial number suitable for a certificate. For
// testing, this just sets it to a random number, but one that can fit in a
// uint64 since we use that in our datastructures and assume cert serials will
Expand Down
24 changes: 12 additions & 12 deletions agent/proxycfg/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ func TestState_WatchesAndUpdates(t *testing.T) {
Address: "10.30.1.1",
Datacenter: "dc4",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.1", 8443,
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
Expand All @@ -1377,7 +1377,7 @@ func TestState_WatchesAndUpdates(t *testing.T) {
Address: "10.30.1.2",
Datacenter: "dc4",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.2", 8443,
structs.ServiceAddress{Address: "10.30.1.2", Port: 8443},
structs.ServiceAddress{Address: "456.us-west-2.elb.notaws.com", Port: 443}),
Expand Down Expand Up @@ -1411,7 +1411,7 @@ func TestState_WatchesAndUpdates(t *testing.T) {
Address: "10.30.1.1",
Datacenter: "dc5",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.1", 8443,
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
Expand All @@ -1423,7 +1423,7 @@ func TestState_WatchesAndUpdates(t *testing.T) {
Address: "10.30.1.2",
Datacenter: "dc5",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.2", 8443,
structs.ServiceAddress{Address: "10.30.1.2", Port: 8443},
structs.ServiceAddress{Address: "456.us-west-2.elb.notaws.com", Port: 443}),
Expand Down Expand Up @@ -4163,7 +4163,7 @@ func Test_hostnameEndpoints(t *testing.T) {
Node: "mesh-gateway",
Datacenter: "dc1",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.0.1.1", 8443,
structs.ServiceAddress{},
structs.ServiceAddress{Address: "123.us-west-1.elb.notaws.com", Port: 443}),
Expand All @@ -4173,7 +4173,7 @@ func Test_hostnameEndpoints(t *testing.T) {
Node: "mesh-gateway",
Datacenter: "dc1",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.0.2.2", 8443,
structs.ServiceAddress{},
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
Expand All @@ -4190,7 +4190,7 @@ func Test_hostnameEndpoints(t *testing.T) {
Node: "mesh-gateway",
Datacenter: "dc1",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"gateway.mydomain", 8443,
structs.ServiceAddress{},
structs.ServiceAddress{Address: "123.us-west-1.elb.notaws.com", Port: 443}),
Expand All @@ -4200,7 +4200,7 @@ func Test_hostnameEndpoints(t *testing.T) {
Node: "mesh-gateway",
Datacenter: "dc1",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.0.2.2", 8443,
structs.ServiceAddress{},
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
Expand All @@ -4212,7 +4212,7 @@ func Test_hostnameEndpoints(t *testing.T) {
Node: "mesh-gateway",
Datacenter: "dc1",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"gateway.mydomain", 8443,
structs.ServiceAddress{},
structs.ServiceAddress{Address: "123.us-west-1.elb.notaws.com", Port: 443}),
Expand All @@ -4228,7 +4228,7 @@ func Test_hostnameEndpoints(t *testing.T) {
Node: "mesh-gateway",
Datacenter: "dc1",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"gateway.mydomain", 8443,
structs.ServiceAddress{},
structs.ServiceAddress{Address: "8.8.8.8", Port: 443}),
Expand All @@ -4238,7 +4238,7 @@ func Test_hostnameEndpoints(t *testing.T) {
Node: "mesh-gateway",
Datacenter: "dc1",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.0.2.2", 8443,
structs.ServiceAddress{},
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
Expand All @@ -4250,7 +4250,7 @@ func Test_hostnameEndpoints(t *testing.T) {
Node: "mesh-gateway",
Datacenter: "dc1",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.0.2.2", 8443,
structs.ServiceAddress{},
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
Expand Down
26 changes: 13 additions & 13 deletions agent/proxycfg/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func TestGatewayNodesDC1(t testing.T) structs.CheckServiceNodes {
Address: "10.10.1.1",
Datacenter: "dc1",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.10.1.1", 8443,
structs.ServiceAddress{Address: "10.10.1.1", Port: 8443},
structs.ServiceAddress{Address: "198.118.1.1", Port: 443}),
Expand All @@ -407,7 +407,7 @@ func TestGatewayNodesDC1(t testing.T) structs.CheckServiceNodes {
Address: "10.10.1.2",
Datacenter: "dc1",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.10.1.2", 8443,
structs.ServiceAddress{Address: "10.0.1.2", Port: 8443},
structs.ServiceAddress{Address: "198.118.1.2", Port: 443}),
Expand All @@ -424,7 +424,7 @@ func TestGatewayNodesDC2(t testing.T) structs.CheckServiceNodes {
Address: "10.0.1.1",
Datacenter: "dc2",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.0.1.1", 8443,
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
structs.ServiceAddress{Address: "198.18.1.1", Port: 443}),
Expand All @@ -436,7 +436,7 @@ func TestGatewayNodesDC2(t testing.T) structs.CheckServiceNodes {
Address: "10.0.1.2",
Datacenter: "dc2",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.0.1.2", 8443,
structs.ServiceAddress{Address: "10.0.1.2", Port: 8443},
structs.ServiceAddress{Address: "198.18.1.2", Port: 443}),
Expand All @@ -453,7 +453,7 @@ func TestGatewayNodesDC3(t testing.T) structs.CheckServiceNodes {
Address: "10.30.1.1",
Datacenter: "dc3",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.1", 8443,
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
structs.ServiceAddress{Address: "198.38.1.1", Port: 443}),
Expand All @@ -465,7 +465,7 @@ func TestGatewayNodesDC3(t testing.T) structs.CheckServiceNodes {
Address: "10.30.1.2",
Datacenter: "dc3",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.2", 8443,
structs.ServiceAddress{Address: "10.30.1.2", Port: 8443},
structs.ServiceAddress{Address: "198.38.1.2", Port: 443}),
Expand All @@ -482,7 +482,7 @@ func TestGatewayNodesDC4Hostname(t testing.T) structs.CheckServiceNodes {
Address: "10.30.1.1",
Datacenter: "dc4",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.1", 8443,
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
Expand All @@ -494,7 +494,7 @@ func TestGatewayNodesDC4Hostname(t testing.T) structs.CheckServiceNodes {
Address: "10.30.1.2",
Datacenter: "dc4",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.2", 8443,
structs.ServiceAddress{Address: "10.30.1.2", Port: 8443},
structs.ServiceAddress{Address: "456.us-west-2.elb.notaws.com", Port: 443}),
Expand All @@ -506,7 +506,7 @@ func TestGatewayNodesDC4Hostname(t testing.T) structs.CheckServiceNodes {
Address: "10.30.1.3",
Datacenter: "dc4",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.3", 8443,
structs.ServiceAddress{Address: "10.30.1.3", Port: 8443},
structs.ServiceAddress{Address: "198.38.1.1", Port: 443}),
Expand All @@ -523,7 +523,7 @@ func TestGatewayNodesDC5Hostname(t testing.T) structs.CheckServiceNodes {
Address: "10.30.1.1",
Datacenter: "dc5",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.1", 8443,
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
structs.ServiceAddress{Address: "123.us-west-2.elb.notaws.com", Port: 443}),
Expand All @@ -535,7 +535,7 @@ func TestGatewayNodesDC5Hostname(t testing.T) structs.CheckServiceNodes {
Address: "10.30.1.2",
Datacenter: "dc5",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.2", 8443,
structs.ServiceAddress{Address: "10.30.1.2", Port: 8443},
structs.ServiceAddress{Address: "456.us-west-2.elb.notaws.com", Port: 443}),
Expand All @@ -547,7 +547,7 @@ func TestGatewayNodesDC5Hostname(t testing.T) structs.CheckServiceNodes {
Address: "10.30.1.3",
Datacenter: "dc5",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.3", 8443,
structs.ServiceAddress{Address: "10.30.1.3", Port: 8443},
structs.ServiceAddress{Address: "198.38.1.1", Port: 443}),
Expand All @@ -564,7 +564,7 @@ func TestGatewayNodesDC6Hostname(t testing.T) structs.CheckServiceNodes {
Address: "10.30.1.1",
Datacenter: "dc6",
},
Service: structs.TestNodeServiceMeshGatewayWithAddrs(t,
Service: structs.TestNodeServiceMeshGatewayWithAddrs(
"10.30.1.1", 8443,
structs.ServiceAddress{Address: "10.0.1.1", Port: 8443},
structs.ServiceAddress{Address: "123.us-east-1.elb.notaws.com", Port: 443}),
Expand Down
4 changes: 2 additions & 2 deletions agent/proxycfg/testing_mesh_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func TestConfigSnapshotMeshGateway(t testing.T, variant string, nsFn func(ns *st
// Create a duplicate entry in FedStateGateways, with a high ModifyIndex, to
// verify that fresh data in the federation state is preferred over stale data
// in GatewayGroups.
svc := structs.TestNodeServiceMeshGatewayWithAddrs(t,
svc := structs.TestNodeServiceMeshGatewayWithAddrs(
"10.0.1.3", 8443,
structs.ServiceAddress{Address: "10.0.1.3", Port: 8443},
structs.ServiceAddress{Address: "198.18.1.3", Port: 443},
Expand All @@ -437,7 +437,7 @@ func TestConfigSnapshotMeshGateway(t testing.T, variant string, nsFn func(ns *st
// Create a duplicate entry in FedStateGateways, with a low ModifyIndex, to
// verify that stale data in the federation state is ignored in favor of the
// fresher data in GatewayGroups.
svc := structs.TestNodeServiceMeshGatewayWithAddrs(t,
svc := structs.TestNodeServiceMeshGatewayWithAddrs(
"10.0.1.3", 8443,
structs.ServiceAddress{Address: "10.0.1.3", Port: 8443},
structs.ServiceAddress{Address: "198.18.1.3", Port: 443},
Expand Down
5 changes: 3 additions & 2 deletions agent/structs/testing_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestNodeServiceExpose(t testing.T) *NodeService {

// TestNodeServiceMeshGateway returns a *NodeService representing a valid Mesh Gateway
func TestNodeServiceMeshGateway(t testing.T) *NodeService {
return TestNodeServiceMeshGatewayWithAddrs(t,
return TestNodeServiceMeshGatewayWithAddrs(
"10.1.2.3",
8443,
ServiceAddress{Address: "10.1.2.3", Port: 8443},
Expand All @@ -192,7 +192,8 @@ func TestNodeServiceTerminatingGateway(t testing.T, address string) *NodeService
}
}

func TestNodeServiceMeshGatewayWithAddrs(t testing.T, address string, port int, lanAddr, wanAddr ServiceAddress) *NodeService {
// TestNodeServiceMeshGatewayWithAddrs returns a *NodeService representing a valid Mesh Gateway with custom addresses.
func TestNodeServiceMeshGatewayWithAddrs(address string, port int, lanAddr, wanAddr ServiceAddress) *NodeService {
return &NodeService{
Kind: ServiceKindMeshGateway,
Service: "mesh-gateway",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ require (
github.com/miekg/dns v1.1.50
github.com/mitchellh/cli v1.1.4
github.com/mitchellh/copystructure v1.2.0
github.com/mitchellh/go-testing-interface v1.14.0
github.com/mitchellh/go-testing-interface v1.14.1
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452
github.com/mitchellh/hashstructure/v2 v2.0.2
github.com/mitchellh/mapstructure v1.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -691,8 +691,8 @@ github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/go-testing-interface v1.14.0 h1:/x0XQ6h+3U3nAyk1yx+bHPURrKa9sVVvYbuqZ7pIAtI=
github.com/mitchellh/go-testing-interface v1.14.0/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
Expand Down
Loading