Fixed PairingPayloadMarshaller logger issue

This commit is contained in:
Samuel Hawksby-Robinson 2022-10-21 16:19:46 +01:00
parent 71170e7099
commit 95eba8c123
6 changed files with 28 additions and 17 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/btcsuite/btcutil/base58"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"github.com/status-im/status-go/logutils"
)
@ -117,6 +118,14 @@ func (tpsc *TestPairingServerComponents) SetupPairingServerComponents(t *testing
require.NoError(t, err)
}
type TestLoggerComponents struct {
Logger *zap.Logger
}
func (tlc *TestLoggerComponents) SetupLoggerComponents() {
tlc.Logger = logutils.ZapLogger()
}
type MockEncryptOnlyPayloadManager struct {
*PayloadEncryptionManager
}

View File

@ -4,8 +4,6 @@ import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/logutils"
)
var (
@ -20,6 +18,7 @@ type ConnectionParamsSuite struct {
suite.Suite
TestKeyComponents
TestCertComponents
TestLoggerComponents
server *PairingServer
}
@ -27,11 +26,12 @@ type ConnectionParamsSuite struct {
func (s *ConnectionParamsSuite) SetupSuite() {
s.SetupKeyComponents(s.T())
s.SetupCertComponents(s.T())
s.SetupLoggerComponents()
cert, _, err := GenerateCertFromKey(s.PK, s.NotBefore, defaultIP.String())
s.Require().NoError(err)
bs := NewServer(&cert, defaultIP.String(), nil, logutils.ZapLogger())
bs := NewServer(&cert, defaultIP.String(), nil, s.Logger)
err = bs.SetPort(1337)
s.Require().NoError(err)

View File

@ -68,7 +68,7 @@ func NewPairingPayloadManager(aesKey []byte, config *PairingPayloadManagerConfig
logger: l,
pp: p,
PayloadEncryptionManager: pem,
ppm: NewPairingPayloadMarshaller(p),
ppm: NewPairingPayloadMarshaller(p, l),
ppr: NewPairingPayloadRepository(p, config),
}, nil
}
@ -229,8 +229,8 @@ type PairingPayloadMarshaller struct {
*PairingPayload
}
func NewPairingPayloadMarshaller(p *PairingPayload) *PairingPayloadMarshaller {
return &PairingPayloadMarshaller{PairingPayload: p}
func NewPairingPayloadMarshaller(p *PairingPayload, logger *zap.Logger) *PairingPayloadMarshaller {
return &PairingPayloadMarshaller{logger: logger, PairingPayload: p}
}
func (ppm *PairingPayloadMarshaller) MarshalToProtobuf() ([]byte, error) {

View File

@ -39,6 +39,7 @@ func TestPayloadMarshallerSuite(t *testing.T) {
type PayloadMarshallerSuite struct {
suite.Suite
TestLoggerComponents
teardown func()
@ -115,6 +116,8 @@ func getFiles(t *testing.T, keyStorePath string) map[string][]byte {
}
func (pms *PayloadMarshallerSuite) SetupTest() {
pms.SetupLoggerComponents()
db1, db1td := setupTestDB(pms.T())
db2, db2td := setupTestDB(pms.T())
keystore1, keystore2, kstd := makeKeystores(pms.T())
@ -194,7 +197,7 @@ func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_MarshalToProtobuf() {
pms.Require().NoError(err)
// Make and Load PairingPayloadMarshaller 1
ppm := NewPairingPayloadMarshaller(pp)
ppm := NewPairingPayloadMarshaller(pp, pms.Logger)
// TEST PairingPayloadMarshaller 1 MarshalToProtobuf()
pb, err := ppm.MarshalToProtobuf()
@ -223,7 +226,7 @@ func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_UnmarshalProtobuf() {
pms.Require().NoError(err)
// Make and Load PairingPayloadMarshaller 1
ppm := NewPairingPayloadMarshaller(pp)
ppm := NewPairingPayloadMarshaller(pp, pms.Logger)
pb, err := ppm.MarshalToProtobuf()
pms.Require().NoError(err)
@ -232,7 +235,7 @@ func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_UnmarshalProtobuf() {
pp2 := new(PairingPayload)
// Make PairingPayloadMarshaller 2
ppm2 := NewPairingPayloadMarshaller(pp2)
ppm2 := NewPairingPayloadMarshaller(pp2, pms.Logger)
// TEST PairingPayloadMarshaller 2 is empty
pms.Require().Nil(ppm2.keys)
@ -276,7 +279,7 @@ func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_StorePayloads() {
pms.Require().NoError(err)
// Make and Load PairingPayloadMarshaller 1
ppm := NewPairingPayloadMarshaller(pp)
ppm := NewPairingPayloadMarshaller(pp, pms.Logger)
pb, err := ppm.MarshalToProtobuf()
pms.Require().NoError(err)
@ -285,7 +288,7 @@ func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_StorePayloads() {
pp2 := new(PairingPayload)
// Make PairingPayloadMarshaller 2
ppm2 := NewPairingPayloadMarshaller(pp2)
ppm2 := NewPairingPayloadMarshaller(pp2, pms.Logger)
err = ppm2.UnmarshalProtobuf(pb)
pms.Require().NoError(err)

View File

@ -31,7 +31,7 @@ func (s *PairingServerSuite) TestMultiBackgroundForeground() {
s.PS.ToBackground()
s.PS.ToForeground()
s.PS.ToForeground()
s.Require().Regexp(regexp.MustCompile("(https://192\\.168\\.0\\.\\d+:\\d+)"), s.PS.MakeBaseURL().String())
s.Require().Regexp(regexp.MustCompile("(https://\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}:\\d{1,5})"), s.PS.MakeBaseURL().String())
}
func (s *PairingServerSuite) TestPairingServer_StartPairing() {

View File

@ -5,8 +5,6 @@ import (
"time"
"github.com/stretchr/testify/suite"
"github.com/status-im/status-go/logutils"
)
const (
@ -20,6 +18,7 @@ func TestServerURLSuite(t *testing.T) {
type ServerURLSuite struct {
suite.Suite
TestKeyComponents
TestLoggerComponents
server *MediaServer
serverNoPort *MediaServer
@ -28,18 +27,18 @@ type ServerURLSuite struct {
func (s *ServerURLSuite) SetupTest() {
s.SetupKeyComponents(s.T())
logger := logutils.ZapLogger()
s.SetupLoggerComponents()
s.server = &MediaServer{Server: Server{
hostname: defaultIP.String(),
portManger: newPortManager(logger, nil),
portManger: newPortManager(s.Logger, nil),
}}
err := s.server.SetPort(1337)
s.Require().NoError(err)
s.serverNoPort = &MediaServer{Server: Server{
hostname: defaultIP.String(),
portManger: newPortManager(logger, nil),
portManger: newPortManager(s.Logger, nil),
}}
go func() {
time.Sleep(waitTime)