Skip to content

Commit

Permalink
Added hex support to key and license tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Samyoul authored and fdelbos committed May 31, 2019
1 parent a043476 commit 238331f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions keys_test.go
Expand Up @@ -59,6 +59,19 @@ var _ = Describe("Keys", func() {
Ω(k2).To(BeNil())
})

It("should test private key hex", func() {
b, err := k.ToHexString()
Ω(err).To(BeNil())
k1, err := lk.PrivateKeyFromHexString(b)
Ω(err).To(BeNil())
Ω(k1).To(Equal(k))

invalidB32Str := uniuri.NewLen(42)
k2, err := lk.PrivateKeyFromHexString(invalidB32Str)
Ω(err).To(HaveOccurred())
Ω(k2).To(BeNil())
})

It("should test pubic key bytes", func() {
b := k.GetPublicKey().ToBytes()
k1, err := lk.PublicKeyFromBytes(b)
Expand Down Expand Up @@ -96,4 +109,16 @@ var _ = Describe("Keys", func() {
Ω(k2).To(BeNil())
})

It("should test pubic key hex", func() {
b := k.GetPublicKey().ToHexString()
k1, err := lk.PublicKeyFromHexString(b)
Ω(err).To(BeNil())
Ω(k1).To(Equal(k.GetPublicKey()))

invalidHexStr := uniuri.NewLen(42)
k2, err := lk.PublicKeyFromHexString(invalidHexStr)
Ω(err).To(HaveOccurred())
Ω(k2).To(BeNil())
})

})
12 changes: 12 additions & 0 deletions license_test.go
Expand Up @@ -87,4 +87,16 @@ var _ = Describe("License", func() {

})

It("should test a license with hex", func() {
b2, err := license.ToHexString()
Ω(err).To(BeNil())
l2, err := lk.LicenseFromHexString(b2)
Ω(err).To(BeNil())
ok, err := l2.Verify(privateKey.GetPublicKey())
Ω(err).To(BeNil())
Ω(ok).To(BeTrue())
Ω(bytes.Equal(license.Data, l2.Data)).To(BeTrue())

})

})

0 comments on commit 238331f

Please sign in to comment.