forked from TrueCloudLab/frostfs-node
[#549] network/Address: Add TLS
There is no TLS protocol support in `go-multiaddr` library, but there is public function that can register any protocol that can be implemented outside the library. Also `TLSEnabled` function for parsing TLS protocol from `network.Address` was added. Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
33bef46f31
commit
f267fbc56a
4 changed files with 191 additions and 0 deletions
48
pkg/network/tls_test.go
Normal file
48
pkg/network/tls_test.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAddress_TLSEnabled(t *testing.T) {
|
||||
testCases := [...]struct {
|
||||
input string
|
||||
wantTLS bool
|
||||
}{
|
||||
{"/dns4/localhost/tcp/8080", false},
|
||||
{"/dns4/localhost/tcp/8080/tls", true},
|
||||
{"/tls/dns4/localhost/tcp/8080", true},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
addr := Address{
|
||||
ma: buildMultiaddr(test.input, t),
|
||||
}
|
||||
|
||||
require.Equal(t, test.wantTLS, addr.TLSEnabled(), test.input)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddress_AddTLS(t *testing.T) {
|
||||
input, tls := "/dns4/localhost/tcp/8080", tls.String()
|
||||
|
||||
testCases := [...]struct {
|
||||
input string
|
||||
want string
|
||||
}{
|
||||
{input, input + tls},
|
||||
{input + tls, input + tls},
|
||||
}
|
||||
|
||||
for _, test := range testCases {
|
||||
addr := Address{
|
||||
ma: buildMultiaddr(test.input, t),
|
||||
}
|
||||
|
||||
addr.AddTLS()
|
||||
|
||||
require.Equal(t, test.want, addr.String(), test.input)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue