MCPcopy
hub / github.com/cloudflare/cloudflared / TestConnections

Function TestConnections

proxy/proxy_test.go:484–737  ·  view source on GitHub ↗

TestConnections tests every possible permutation of connection protocols proxied by cloudflared. WS - WS : When a websocket based ingress is configured on the origin and the eyeball is also a websocket client streaming data. TCP - TCP : When teamnet is enabled and an http or tcp service is running

(t *testing.T)

Source from the content-addressed store, hash-verified

482// WS - TCP: When a tcp based ingress is configured on the origin and the
483// eyeball sends tcp packets wrapped in websockets. (E.g: cloudflared access).
484func TestConnections(t *testing.T) {
485 log := zerolog.Nop()
486 replayer := &replayer{rw: bytes.NewBuffer([]byte{})}
487 type args struct {
488 ingressServiceScheme string
489 originService func(*testing.T, net.Listener)
490 eyeballResponseWriter connection.ResponseWriter
491 eyeballRequestBody io.ReadCloser
492
493 // eyeball connection type.
494 connectionType connection.Type
495
496 // requestheaders to be sent in the call to proxy.Proxy
497 requestHeaders http.Header
498
499 // flowLimiterResponse is the response of the cfdflow.Limiter#Acquire method call
500 flowLimiterResponse error
501 }
502
503 originDialer := ingress.NewOriginDialer(ingress.OriginConfig{
504 DefaultDialer: testDefaultDialer,
505 TCPWriteTimeout: 0,
506 }, &log)
507
508 type want struct {
509 message []byte
510 headers http.Header
511 err bool
512 }
513
514 tests := []struct {
515 name string
516 args args
517 want want
518 }{
519 {
520 name: "ws-ws proxy",
521 args: args{
522 ingressServiceScheme: "ws://",
523 originService: runEchoWSService,
524 eyeballResponseWriter: newWSRespWriter(replayer),
525 eyeballRequestBody: newWSRequestBody([]byte("test1")),
526 connectionType: connection.TypeWebsocket,
527 requestHeaders: map[string][]string{
528 // Example key from https://tools.ietf.org/html/rfc6455#section-1.2
529 "Sec-Websocket-Key": {"dGhlIHNhbXBsZSBub25jZQ=="},
530 "Test-Cloudflared-Echo": {"Echo"},
531 },
532 },
533 want: want{
534 message: []byte("echo-test1"),
535 headers: map[string][]string{
536 "Connection": {"Upgrade"},
537 "Sec-Websocket-Accept": {"s3pPLMBiTxaQ9kYGzzhZRbK+xOo="},
538 "Upgrade": {"websocket"},
539 "Test-Cloudflared-Echo": {"Echo"},
540 },
541 },

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
WriteMethod · 0.95
ProxyTCPMethod · 0.95
ProxyHTTPMethod · 0.95
BytesMethod · 0.95
NewOriginDialerFunction · 0.92
NewMockLimiterFunction · 0.92
NewTracedHTTPRequestFunction · 0.92
newWSRequestBodyFunction · 0.85
newTCPRespWriterFunction · 0.85
newTCPRequestBodyFunction · 0.85

Tested by

no test coverage detected