Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Guy Daich <guy.daich@sap.com>
  • Loading branch information
guydc committed Jan 21, 2025
1 parent c15b5a0 commit 90bfd37
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/xds/translator/extensionserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ func (t *testingExtensionServer) PostHTTPListenerModify(_ context.Context, req *
return &pb.PostHTTPListenerModifyResponse{
Listener: modifiedListener,
}, nil
case "first-listener-error":
modifiedListener := proto.Clone(req.Listener).(*listenerV3.Listener)
modifiedListener.StatPrefix = req.Listener.Name
return &pb.PostHTTPListenerModifyResponse{
Listener: modifiedListener,
}, fmt.Errorf("simulate error when there is no default filter chain in the original resources")
}
return &pb.PostHTTPListenerModifyResponse{
Listener: req.Listener,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
http:
- name: "first-listener-error"
address: "::"
port: 10080
hostnames:
- "foo.com"
path:
mergeSlashes: true
escapedSlashesAction: UnescapeAndRedirect
tls:
alpnProtocols:
- h2
- http/1.1
certificates:
- name: first-listener
# byte slice representation of "cert-data"
serverCertificate: [99, 101, 114, 116, 45, 100, 97, 116, 97]
# byte slice representation of "key-data"
privateKey: [107, 101, 121, 45, 100, 97, 116, 97]
routes:
- name: "first-route"
hostname: "*"
destination:
name: "first-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000
- name: "second-listener"
address: "::"
port: 10080
hostnames:
- "foo.net"
path:
mergeSlashes: true
escapedSlashesAction: UnescapeAndRedirect
tls:
alpnProtocols:
- h2
- http/1.1
certificates:
- name: second-listener
# byte slice representation of "cert-data"
serverCertificate: [99, 101, 114, 116, 45, 100, 97, 116, 97]
# byte slice representation of "key-data"
privateKey: [107, 101, 121, 45, 100, 97, 116, 97]
routes:
- name: "second-route"
hostname: "*"
destination:
name: "second-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
- circuitBreakers:
thresholds:
- maxRetries: 1024
commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_PREFERRED
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: first-route-dest
ignoreHealthOnHostRemoval: true
lbPolicy: LEAST_REQUEST
name: first-route-dest
perConnectionBufferLimitBytes: 32768
type: EDS
- circuitBreakers:
thresholds:
- maxRetries: 1024
commonLbConfig:
localityWeightedLbConfig: {}
connectTimeout: 10s
dnsLookupFamily: V4_PREFERRED
edsClusterConfig:
edsConfig:
ads: {}
resourceApiVersion: V3
serviceName: second-route-dest
ignoreHealthOnHostRemoval: true
lbPolicy: LEAST_REQUEST
name: second-route-dest
perConnectionBufferLimitBytes: 32768
type: EDS
- loadAssignment:
clusterName: mock-extension-injected-cluster
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: exampleservice.examplenamespace.svc.cluster.local
portValue: 5000
name: mock-extension-injected-cluster
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- clusterName: first-route-dest
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
loadBalancingWeight: 1
loadBalancingWeight: 1
locality:
region: first-route-dest/backend/0
- clusterName: second-route-dest
endpoints:
- lbEndpoints:
- endpoint:
address:
socketAddress:
address: 1.2.3.4
portValue: 50000
loadBalancingWeight: 1
loadBalancingWeight: 1
locality:
region: second-route-dest/backend/0
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
- address:
socketAddress:
address: '::'
portValue: 10080
filterChains:
- filterChainMatch:
serverNames:
- foo.com
filters:
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
commonHttpProtocolOptions:
headersWithUnderscoresAction: REJECT_REQUEST
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
maxConcurrentStreams: 100
httpFilters:
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
suppressEnvoyHeaders: true
mergeSlashes: true
normalizePath: true
pathWithEscapedSlashesAction: UNESCAPE_AND_REDIRECT
routeConfig:
name: error_route_configuration
virtualHosts:
- domains:
- '*'
name: error_vhost
routes:
- directResponse:
status: 500
match:
prefix: /
name: error_route
serverHeaderTransformation: PASS_THROUGH
statPrefix: https-10080
useRemoteAddress: true
name: first-listener-error
transportSocket:
name: envoy.transport_sockets.tls
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
commonTlsContext:
alpnProtocols:
- h2
- http/1.1
tlsCertificateSdsSecretConfigs:
- name: first-listener
sdsConfig:
ads: {}
resourceApiVersion: V3
disableStatefulSessionResumption: true
disableStatelessSessionResumption: true
- filterChainMatch:
serverNames:
- foo.net
filters:
- name: envoy.filters.network.http_connection_manager
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
commonHttpProtocolOptions:
headersWithUnderscoresAction: REJECT_REQUEST
http2ProtocolOptions:
initialConnectionWindowSize: 1048576
initialStreamWindowSize: 65536
maxConcurrentStreams: 100
httpFilters:
- name: envoy.filters.http.router
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
suppressEnvoyHeaders: true
mergeSlashes: true
normalizePath: true
pathWithEscapedSlashesAction: UNESCAPE_AND_REDIRECT
routeConfig:
name: error_route_configuration
virtualHosts:
- domains:
- '*'
name: error_vhost
routes:
- directResponse:
status: 500
match:
prefix: /
name: error_route
serverHeaderTransformation: PASS_THROUGH
statPrefix: https-10080
useRemoteAddress: true
name: second-listener
transportSocket:
name: envoy.transport_sockets.tls
typedConfig:
'@type': type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
commonTlsContext:
alpnProtocols:
- h2
- http/1.1
tlsCertificateSdsSecretConfigs:
- name: second-listener
sdsConfig:
ads: {}
resourceApiVersion: V3
disableStatefulSessionResumption: true
disableStatelessSessionResumption: true
listenerFilters:
- name: envoy.filters.listener.tls_inspector
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.listener.tls_inspector.v3.TlsInspector
name: first-listener-error
perConnectionBufferLimitBytes: 32768
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- ignorePortInHostMatching: true
name: first-listener-error
virtualHosts:
- domains:
- '*'
name: first-listener-error/*
routes:
- match:
prefix: /
name: first-route
route:
cluster: first-route-dest
upgradeConfigs:
- upgradeType: websocket
- ignorePortInHostMatching: true
name: second-listener
virtualHosts:
- domains:
- '*'
name: second-listener/*
routes:
- match:
prefix: /
name: second-route
route:
cluster: second-route-dest
upgradeConfigs:
- upgradeType: websocket
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- name: first-listener
tlsCertificate:
certificateChain:
inlineBytes: Y2VydC1kYXRh
privateKey:
inlineBytes: a2V5LWRhdGE=
- name: second-listener
tlsCertificate:
certificateChain:
inlineBytes: Y2VydC1kYXRh
privateKey:
inlineBytes: a2V5LWRhdGE=
- genericSecret:
secret:
inlineString: super-secret-extension-secret
name: mock-extension-injected-secret
3 changes: 3 additions & 0 deletions internal/xds/translator/translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ func TestTranslateXdsWithExtension(t *testing.T) {
"http-route-extension-translate-error": {
errMsg: "rpc error: code = Unknown desc = cluster hook resource error: fail-close-error",
},
"multiple-listeners-same-port-error": {
errMsg: "rpc error: code = Unknown desc = simulate error when there is no default filter chain in the original resources",
},
}

inputFiles, err := filepath.Glob(filepath.Join("testdata", "in", "extension-xds-ir", "*.yaml"))
Expand Down

0 comments on commit 90bfd37

Please sign in to comment.