MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestInteropTLS

Function TestInteropTLS

pkg/component/interop_test.go:96–190  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

94}
95
96func TestInteropTLS(t *testing.T) {
97 a := assertions.New(t)
98
99 config := &component.Config{
100 ServiceBase: config.ServiceBase{
101 TLS: tlsconfig.Config{
102 ServerAuth: tlsconfig.ServerAuth{
103 Certificate: "testdata/servercert.pem",
104 Key: "testdata/serverkey.pem",
105 },
106 Client: tlsconfig.Client{
107 RootCA: "testdata/serverca.pem",
108 },
109 },
110 Interop: config.InteropServer{
111 ListenTLS: ":9188",
112 SenderClientCA: config.SenderClientCA{
113 Source: "directory",
114 Directory: "testdata",
115 },
116 },
117 },
118 }
119
120 mockInterop := &mockInterop{}
121 c := component.MustNew(test.GetLogger(t), config)
122 c.RegisterInterop(mockInterop)
123
124 test.Must[any](nil, c.Start())
125 defer c.Close()
126
127 certPool := x509.NewCertPool()
128 certContent, err := os.ReadFile("testdata/serverca.pem")
129 a.So(err, should.BeNil)
130 certPool.AppendCertsFromPEM(certContent)
131 client := http.Client{
132 Transport: &http.Transport{
133 TLSClientConfig: &tls.Config{
134 RootCAs: certPool,
135 GetClientCertificate: func(info *tls.CertificateRequestInfo) (*tls.Certificate, error) {
136 cert, err := tls.LoadX509KeyPair("testdata/clientcert.pem", "testdata/clientkey.pem")
137 if err != nil {
138 return nil, err
139 }
140 return &cert, nil
141 },
142 },
143 },
144 }
145
146 // Correct SenderID.
147 {
148 req := &interop.JoinReq{
149 NsJsMessageHeader: interop.NsJsMessageHeader{
150 MessageHeader: interop.MessageHeader{
151 MessageType: interop.MessageTypeJoinReq,
152 ProtocolVersion: "1.0",
153 },

Callers

nothing calls this directly

Calls 11

MustNewFunction · 0.92
GetLoggerFunction · 0.92
MACVersionTypeAlias · 0.92
NewDecoderMethod · 0.80
NewMethod · 0.65
RegisterInteropMethod · 0.65
CloseMethod · 0.65
ReadFileMethod · 0.65
MarshalMethod · 0.65
DecodeMethod · 0.65
StartMethod · 0.45

Tested by

no test coverage detected