move the STK generation from the ServerConfig to a separate struct

This commit is contained in:
Marten Seemann
2017-05-13 11:47:36 +08:00
parent 6cc6d49a10
commit 9562df5838
7 changed files with 86 additions and 21 deletions

View File

@@ -0,0 +1,35 @@
package handshake
import (
"net"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("STK Generator", func() {
var stkGen *STKGenerator
BeforeEach(func() {
var err error
stkGen, err = NewSTKGenerator()
Expect(err).ToNot(HaveOccurred())
})
It("generates an STK", func() {
ip := net.IPv4(127, 0, 0, 1)
token, err := stkGen.NewToken(ip)
Expect(err).ToNot(HaveOccurred())
Expect(token).ToNot(BeEmpty())
})
It("verifies an STK", func() {
ip := net.IPv4(192, 168, 0, 1)
token, err := stkGen.NewToken(ip)
Expect(err).ToNot(HaveOccurred())
t, err := stkGen.VerifyToken(ip, token)
Expect(err).ToNot(HaveOccurred())
Expect(t).To(BeTemporally("~", time.Now(), time.Second))
})
})