mirror of
https://codeberg.org/cunicu/cunicu.git
synced 2025-10-30 02:51:56 +08:00
40 lines
889 B
Go
40 lines
889 B
Go
// SPDX-FileCopyrightText: 2023 Steffen Vogel <post@steffenvogel.de>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package crypto_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"cunicu.li/cunicu/pkg/crypto"
|
|
"cunicu.li/cunicu/pkg/tty"
|
|
"cunicu.li/cunicu/test"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
func TestSuite(t *testing.T) {
|
|
test.SetupLogging()
|
|
RegisterFailHandler(Fail)
|
|
RunSpecs(t, "Crypto Suite")
|
|
}
|
|
|
|
var _ = Describe("generate", func() {
|
|
It("nonce", func() {
|
|
nonce, err := crypto.GetNonce(100)
|
|
Expect(err).To(Succeed())
|
|
Expect(nonce).To(HaveLen(100))
|
|
Expect([]byte(nonce)).To(test.BeRandom())
|
|
})
|
|
|
|
It("random string", func() {
|
|
for i := 0; i < 10000; i++ {
|
|
s, err := crypto.GetRandomString(10, tty.RunesAlpha)
|
|
Expect(err).To(Succeed())
|
|
Expect(s).To(HaveLen(10))
|
|
Expect(s).To(MatchRegexp(`^[a-zA-Z]+$`), "Generator returned unexpected character")
|
|
}
|
|
})
|
|
})
|