Initial commit: crypto.go and protocol.go implementation + unit tests
This commit is contained in:
36
protocol_test.go
Normal file
36
protocol_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package ownwire_sdk_test
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
sdk "ownwire.net/ownwire-sdk"
|
||||
)
|
||||
|
||||
var _ = Describe("ParseSessionInit", func() {
|
||||
It("parses a valid /session line", func() {
|
||||
line := "/session:cb653f53-6f7d-4aeb-ba0d-d2b17c290d8a:SERVERPUBB64:SALTB64:12:34"
|
||||
parsed, err := sdk.ParseSessionInit(line)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(parsed.SessionId).To(Equal("cb653f53-6f7d-4aeb-ba0d-d2b17c290d8a"))
|
||||
Expect(parsed.ServerPubKeyB64).To(Equal("SERVERPUBB64"))
|
||||
Expect(parsed.SaltB64).To(Equal("SALTB64"))
|
||||
Expect(parsed.SeqOut).To(Equal(uint64(12)))
|
||||
Expect(parsed.SeqInMax).To(Equal(uint64(34)))
|
||||
})
|
||||
|
||||
It("rejects non-session lines", func() {
|
||||
_, err := sdk.ParseSessionInit("/wat:1:2:3:4:5")
|
||||
Expect(err).ToNot(BeNil())
|
||||
})
|
||||
|
||||
It("rejects missing fields", func() {
|
||||
_, err := sdk.ParseSessionInit("/session:1:2:3")
|
||||
Expect(err).ToNot(BeNil())
|
||||
})
|
||||
|
||||
It("rejects bad sequence numbers", func() {
|
||||
_, err := sdk.ParseSessionInit("/session:1:2:3:nope:5")
|
||||
Expect(err).ToNot(BeNil())
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user