mirror of https://github.com/XTLS/Xray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
810 B
39 lines
810 B
4 years ago
|
package kcp_test
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/google/go-cmp/cmp"
|
||
|
|
||
|
"github.com/xtls/xray-core/v1/common"
|
||
|
. "github.com/xtls/xray-core/v1/transport/internet/kcp"
|
||
|
)
|
||
|
|
||
|
func TestSimpleAuthenticator(t *testing.T) {
|
||
|
cache := make([]byte, 512)
|
||
|
|
||
|
payload := []byte{'a', 'b', 'c', 'd', 'e', 'f', 'g'}
|
||
|
|
||
|
auth := NewSimpleAuthenticator()
|
||
|
b := auth.Seal(cache[:0], nil, payload, nil)
|
||
|
c, err := auth.Open(cache[:0], nil, b, nil)
|
||
|
common.Must(err)
|
||
|
if r := cmp.Diff(c, payload); r != "" {
|
||
|
t.Error(r)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestSimpleAuthenticator2(t *testing.T) {
|
||
|
cache := make([]byte, 512)
|
||
|
|
||
|
payload := []byte{'a', 'b'}
|
||
|
|
||
|
auth := NewSimpleAuthenticator()
|
||
|
b := auth.Seal(cache[:0], nil, payload, nil)
|
||
|
c, err := auth.Open(cache[:0], nil, b, nil)
|
||
|
common.Must(err)
|
||
|
if r := cmp.Diff(c, payload); r != "" {
|
||
|
t.Error(r)
|
||
|
}
|
||
|
}
|