Files
cunicu/pkg/proto/signaling/signaling_test.go
Steffen Vogel 92a7ad2f7f daemon: use per-interface features
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
2022-10-07 18:30:50 +02:00

52 lines
1.2 KiB
Go

package signaling_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"google.golang.org/protobuf/proto"
"github.com/stv0g/cunicu/pkg/crypto"
"github.com/stv0g/cunicu/test"
protoepdisc "github.com/stv0g/cunicu/pkg/proto/feature/epdisc"
signalingproto "github.com/stv0g/cunicu/pkg/proto/signaling"
)
var _ = Describe("message encryption", func() {
var c protoepdisc.Candidate
var ourKP, theirKP *crypto.KeyPair
var em signalingproto.EncryptedMessage
BeforeEach(func() {
var err error
c = protoepdisc.Candidate{
Foundation: "1234",
}
ourKP, theirKP, err = test.GenerateKeyPairs()
Expect(err).To(Succeed())
em = signalingproto.EncryptedMessage{}
err = em.Marshal(&c, ourKP)
Expect(err).To(Succeed(), "Failed to encrypt message: %s", err)
})
It("can en/decrypt a message", func() {
c2 := protoepdisc.Candidate{}
err := em.Unmarshal(&c2, theirKP)
Expect(err).To(Succeed(), "Failed to decrypt message: %s", err)
Expect(proto.Equal(&c, &c2)).To(BeTrue())
})
It("fails to decrypt an altered message", func() {
em.Body[0] ^= 1
c2 := protoepdisc.Candidate{}
err := em.Unmarshal(&c2, theirKP)
Expect(err).To(HaveOccurred(), "Decrypted invalid message: %s", err)
})
})