Skip to content

Commit

Permalink
Adding collision testing
Browse files Browse the repository at this point in the history
Signed-off-by: Tenshin Higashi <[email protected]>
  • Loading branch information
tenshinhigashi committed Nov 16, 2023
1 parent 576ff7d commit e16ca7b
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions pkg/ambex/transforms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,79 @@ func TestV3ListenerToRdsListener(t *testing.T) {

}
}

func TestV3ListenerToRdsListenerCollision(t *testing.T) {
//First route
testRoute := &v3Route.Route_Route{
Route: &v3Route.RouteAction{
ClusterSpecifier: &v3Route.RouteAction_Cluster{
Cluster: "cluster_quote_default_default",
},
PrefixRewrite: "/",
Timeout: durationpb.New(3 * time.Second),
},
}

testHcm := &v3Httpman.HttpConnectionManager{
RouteSpecifier: &v3Httpman.HttpConnectionManager_RouteConfig{
RouteConfig: &v3Route.RouteConfiguration{
VirtualHosts: []*v3Route.VirtualHost{{
Name: "emissary-ingress-listener-8080-*",
Domains: []string{"*"},
Routes: []*v3Route.Route{{
Match: &v3Route.RouteMatch{
PathSpecifier: &v3Route.RouteMatch_Prefix{
Prefix: "/backend/",
},
},
Action: testRoute,
}},
}},
},
},
}

anyTestHcm, err := anypb.New(testHcm)
require.NoError(t, err)

//Create a second identical Hcm
anyTestHcm2, err := anypb.New(testHcm)
require.NoError(t, err)

testListener := &v3Listener.Listener{
Name: "emissary-ingress-listener-8080",
FilterChains: []*v3Listener.FilterChain{{
Filters: []*v3Listener.Filter{{
Name: v3Wellknown.HTTPConnectionManager,
ConfigType: &v3Listener.Filter_TypedConfig{TypedConfig: anyTestHcm},
}, {
Name: v3Wellknown.HTTPConnectionManager,
ConfigType: &v3Listener.Filter_TypedConfig{TypedConfig: anyTestHcm2},
}},
FilterChainMatch: &v3Listener.FilterChainMatch{
DestinationPort: &wrapperspb.UInt32Value{Value: uint32(8080)},
},
}},
}

_, routes, err := V3ListenerToRdsListener(testListener)
require.NoError(t, err)

//Should have 2 routes
assert.Equal(t, 2, len(routes))

// Confirm that the route names are not equal
assert.NotEqual(t, routes[0].GetName(), routes[1].GetName())

for _, rc := range routes {
// Confirm that the route name was transformed to the hashed version (minus the index)
assert.Equal(t, "emissary-ingress-listener-8080-routeconfig-8c82e45fa3f94ab4e879543e0a1a30ac-", rc.GetName()[:len(rc.GetName())-1])

// Make sure the virtual hosts are unmodified
virtualHosts := rc.GetVirtualHosts()
assert.Equal(t, 1, len(virtualHosts))
assert.Equal(t, "emissary-ingress-listener-8080-*", virtualHosts[0].GetName())
assert.Equal(t, []string{"*"}, virtualHosts[0].GetDomains())

}
}

0 comments on commit e16ca7b

Please sign in to comment.