Skip to content

Commit e8dc705

Browse files
committed
Test GetRemoteCertificate
1 parent 028d12e commit e8dc705

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

peerconnection_js_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,24 @@ func TestPeerConnectionCanTrickleICECandidatesJS(t *testing.T) {
121121
pc.underlying = js.ValueOf(map[string]any{})
122122
assert.Equal(t, ICETrickleCapabilityUnknown, pc.CanTrickleICECandidates())
123123
}
124+
125+
func TestDTLSTransportGetRemoteCertificate(t *testing.T) {
126+
expected := []byte{0x01, 0x02, 0x03, 0x04}
127+
128+
u8 := js.Global().Get("Uint8Array").New(len(expected))
129+
if n := js.CopyBytesToJS(u8, expected); n != len(expected) {
130+
t.Fatalf("copied %d bytes to Uint8Array; expected %d", n, len(expected))
131+
}
132+
certBuffer := u8.Get("buffer")
133+
134+
getRemoteCertificates := js.FuncOf(func(this js.Value, args []js.Value) any {
135+
return js.ValueOf([]any{certBuffer})
136+
})
137+
defer getRemoteCertificates.Release()
138+
139+
mockTransport := js.Global().Get("Object").New()
140+
mockTransport.Set("getRemoteCertificates", getRemoteCertificates)
141+
142+
dtlsTransport := &DTLSTransport{underlying: mockTransport}
143+
assert.Equal(t, expected, dtlsTransport.GetRemoteCertificate())
144+
}

0 commit comments

Comments
 (0)