2021-10-08 12:39:31 +00:00
|
|
|
// SPDX-FileCopyrightText: 2021 The NGI Pointer Secure-Scuttlebutt Team of 2020/2021
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-03-29 10:23:11 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/base64"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2022-11-07 09:18:13 +00:00
|
|
|
refs "github.com/ssbc/go-ssb-refs"
|
2021-03-29 10:23:11 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestMultiserverAddress(t *testing.T) {
|
|
|
|
a := assert.New(t)
|
|
|
|
|
|
|
|
var sed ServerEndpointDetails
|
|
|
|
sed.Domain = "the.ho.st"
|
2021-04-19 12:52:12 +00:00
|
|
|
sed.ListenAddressMUXRPC = ":8008"
|
2021-03-29 10:23:11 +00:00
|
|
|
|
2022-11-07 09:18:13 +00:00
|
|
|
roomID, err := refs.NewFeedRefFromBytes(bytes.Repeat([]byte("ohai"), 8), refs.RefAlgoFeedSSB1)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
2021-03-29 10:23:11 +00:00
|
|
|
}
|
2022-11-07 09:18:13 +00:00
|
|
|
sed.RoomID = roomID
|
2021-03-29 10:23:11 +00:00
|
|
|
|
|
|
|
gotMultiAddr := sed.MultiserverAddress()
|
|
|
|
|
|
|
|
a.Equal("net:the.ho.st:8008~shs:b2hhaW9oYWlvaGFpb2hhaW9oYWlvaGFpb2hhaW9oYWk=", gotMultiAddr)
|
|
|
|
a.True(strings.HasPrefix(gotMultiAddr, "net:the.ho.st:8008~shs:"), "not for the test host? %s", gotMultiAddr)
|
|
|
|
a.True(strings.HasSuffix(gotMultiAddr, base64.StdEncoding.EncodeToString(sed.RoomID.PubKey())), "public key missing? %s", gotMultiAddr)
|
|
|
|
|
|
|
|
}
|