2022-06-15 15:36:17 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-10-05 09:57:12 +00:00
|
|
|
connectionString = "cs2:4FHRnp:Q4:uqnnMwVUfJc2Fkcaojet8F1ufKC3hZdGEt47joyBx9yd:BbnZ7Gc66t54a9kEFCf7FW8SGQuYypwHVeNkRYeNoqV6:3"
|
2022-06-15 15:36:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestConnectionParamsSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(ConnectionParamsSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
type ConnectionParamsSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
TestKeyComponents
|
|
|
|
TestCertComponents
|
|
|
|
|
|
|
|
server *PairingServer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ConnectionParamsSuite) SetupSuite() {
|
|
|
|
s.SetupKeyComponents(s.T())
|
|
|
|
s.SetupCertComponents(s.T())
|
|
|
|
|
|
|
|
cert, _, err := GenerateCertFromKey(s.PK, s.NotBefore, defaultIP.String())
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2022-08-07 07:35:54 +00:00
|
|
|
bs := NewServer(&cert, defaultIP.String(), func(int) {})
|
2022-06-15 15:36:17 +00:00
|
|
|
bs.port = 1337
|
|
|
|
|
|
|
|
s.server = &PairingServer{
|
|
|
|
Server: bs,
|
2022-08-07 22:14:33 +00:00
|
|
|
pk: &s.PK.PublicKey,
|
|
|
|
ek: s.AES,
|
2022-06-15 15:36:17 +00:00
|
|
|
mode: Sending,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ConnectionParamsSuite) TestConnectionParams_ToString() {
|
|
|
|
cp, err := s.server.MakeConnectionParams()
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
2022-08-07 22:14:33 +00:00
|
|
|
cps := cp.ToString()
|
2022-06-15 15:36:17 +00:00
|
|
|
s.Require().Equal(connectionString, cps)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ConnectionParamsSuite) TestConnectionParams_Generate() {
|
|
|
|
cp := new(ConnectionParams)
|
|
|
|
err := cp.FromString(connectionString)
|
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Exactly(Sending, cp.serverMode)
|
|
|
|
|
2022-08-07 22:14:33 +00:00
|
|
|
u, err := cp.URL()
|
2022-06-15 15:36:17 +00:00
|
|
|
s.Require().NoError(err)
|
|
|
|
|
|
|
|
s.Require().Equal("https://127.0.0.1:1337", u.String())
|
|
|
|
s.Require().Equal(defaultIP.String(), u.Hostname())
|
|
|
|
s.Require().Equal("1337", u.Port())
|
|
|
|
|
2022-08-07 22:14:33 +00:00
|
|
|
s.Require().True(cp.publicKey.Equal(&s.PK.PublicKey))
|
|
|
|
s.Require().Equal(s.AES, cp.aesKey)
|
2022-06-15 15:36:17 +00:00
|
|
|
}
|