1
0
Fork 0
mirror of https://github.com/SamTherapy/dnscrypt.git synced 2024-07-02 21:56:06 +00:00
dnscrypt/util_test.go
Mohammad Zolfaghari f28a1a337a
fix: pad function calculating minQuestionSize (#25)
fix problem with calculating closest divisible by 64
closes #24
2024-04-17 18:02:24 +02:00

32 lines
637 B
Go

package dnscrypt
import (
"crypto/rand"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPadUnpad(t *testing.T) {
longBuf := make([]byte, 272)
_, err := rand.Read(longBuf)
require.NoError(t, err)
tests := []struct {
packet []byte
expPaddedLen int
}{
{[]byte("Example Test DNS packet"), 256},
{longBuf, 320},
}
for i, test := range tests {
padded := pad(test.packet)
assert.Equal(t, test.expPaddedLen, len(padded), "test %d", i)
unpadded, err := unpad(padded)
assert.Nil(t, err, "test %d", i)
assert.Equal(t, test.packet, unpadded, "test %d", i)
}
}