9ffa124511
* upgrade to our go.mod enabled of psiphon-tunnel-core such that we're now using v2.0.24 of the tunnel-core; * upgrade to the latest lucas-clemente/quic-go release; * upgrade to the latest ooni/oohttp release (which is based on go1.19 but the diff seems good enough to continue using go1.18.x as well); * upgrade to the latest ooni/oocrypto release (for which we can make the same remarks regarding using go1.18.x); * deal with changes in lucas-clemente/quic-go API as well as changes in what a go1.19 *tls.Conn compatible type should look like. Unfortunately, we cannot switch to go1.19 because psiphon forks quic-go and their fork's still not building using such a version of go. Part of ooni/probe#2211.
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package mocks
|
|
|
|
import (
|
|
"context"
|
|
"crypto/tls"
|
|
"net"
|
|
)
|
|
|
|
// TLSHandshaker is a mockable TLS handshaker.
|
|
type TLSHandshaker struct {
|
|
MockHandshake func(ctx context.Context, conn net.Conn, config *tls.Config) (
|
|
net.Conn, tls.ConnectionState, error)
|
|
}
|
|
|
|
// Handshake calls MockHandshake.
|
|
func (th *TLSHandshaker) Handshake(ctx context.Context, conn net.Conn, config *tls.Config) (
|
|
net.Conn, tls.ConnectionState, error) {
|
|
return th.MockHandshake(ctx, conn, config)
|
|
}
|
|
|
|
// TLSConn allows to mock netxlite.TLSConn.
|
|
type TLSConn struct {
|
|
// Conn is the embedded mockable Conn.
|
|
Conn
|
|
|
|
// MockConnectionState allows to mock the ConnectionState method.
|
|
MockConnectionState func() tls.ConnectionState
|
|
|
|
// MockHandshakeContext allows to mock the HandshakeContext method.
|
|
MockHandshakeContext func(ctx context.Context) error
|
|
|
|
// MockNetConn returns the underlying net.Conn
|
|
MockNetConn func() net.Conn
|
|
}
|
|
|
|
// ConnectionState calls MockConnectionState.
|
|
func (c *TLSConn) ConnectionState() tls.ConnectionState {
|
|
return c.MockConnectionState()
|
|
}
|
|
|
|
// HandshakeContext calls MockHandshakeContext.
|
|
func (c *TLSConn) HandshakeContext(ctx context.Context) error {
|
|
return c.MockHandshakeContext(ctx)
|
|
}
|
|
|
|
// NetConn calls MockNetConn.
|
|
func (c *TLSConn) NetConn() net.Conn {
|
|
return c.MockNetConn()
|
|
}
|
|
|
|
// TLSDialer allows to mock netxlite.TLSDialer.
|
|
type TLSDialer struct {
|
|
// MockCloseIdleConnections allows to mock the CloseIdleConnections method.
|
|
MockCloseIdleConnections func()
|
|
|
|
// MockDialTLSContext allows to mock the DialTLSContext method.
|
|
MockDialTLSContext func(ctx context.Context, network, address string) (net.Conn, error)
|
|
}
|
|
|
|
// CloseIdleConnections calls MockCloseIdleConnections.
|
|
func (d *TLSDialer) CloseIdleConnections() {
|
|
d.MockCloseIdleConnections()
|
|
}
|
|
|
|
// DialTLSContext calls MockDialTLSContext.
|
|
func (d *TLSDialer) DialTLSContext(ctx context.Context, network, address string) (net.Conn, error) {
|
|
return d.MockDialTLSContext(ctx, network, address)
|
|
}
|