mirror of
https://github.com/juanfont/headscale.git
synced 2026-07-09 01:20:21 +09:00
84c99023e5
A crypto/rand failure sliced empty output and panicked.
25 lines
635 B
Go
25 lines
635 B
Go
package util
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// TestEncodeRandomURLSafeChecksErrorFirst ensures the URL-safe random string
|
|
// encoder returns ("", err) on an RNG failure instead of slicing the empty
|
|
// base64 of nil bytes and panicking.
|
|
func TestEncodeRandomURLSafeChecksErrorFirst(t *testing.T) {
|
|
require.NotPanics(t, func() {
|
|
s, err := encodeRandomURLSafe(nil, 32, assert.AnError)
|
|
assert.Empty(t, s)
|
|
require.Error(t, err)
|
|
})
|
|
|
|
s, err := encodeRandomURLSafe(bytes.Repeat([]byte{0x1}, 32), 32, nil)
|
|
require.NoError(t, err)
|
|
assert.Len(t, s, 32)
|
|
}
|