Fix some tests and format code (#830)

* Increase some tls test timeout

* Fix TestUserValidator

* Change all tests to VMessAEAD

Old VMess MD5 tests will be rejected and fail in 2022

* Chore: auto format code
This commit is contained in:
yuhan6665 2021-12-14 19:28:47 -05:00 committed by GitHub
parent d5a7901601
commit e93da4bd02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
77 changed files with 137 additions and 234 deletions

View file

@ -6,8 +6,6 @@ import (
"sync"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"golang.org/x/net/dns/dnsmessage"
"github.com/xtls/xray-core/common"
@ -22,6 +20,7 @@ import (
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/stat"
)
func init() {

View file

@ -7,8 +7,6 @@ import (
"sync/atomic"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/log"
@ -20,6 +18,7 @@ import (
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet/stat"
)
func init() {

View file

@ -6,8 +6,6 @@ import (
"context"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/dice"
@ -22,6 +20,7 @@ import (
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/stat"
)
func init() {

View file

@ -9,8 +9,6 @@ import (
"net/url"
"sync"
"github.com/xtls/xray-core/transport/internet/stat"
"golang.org/x/net/http2"
"github.com/xtls/xray-core/common"
@ -26,6 +24,7 @@ import (
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/transport/internet/tls"
)

View file

@ -9,8 +9,6 @@ import (
"strings"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
@ -24,6 +22,7 @@ import (
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet/stat"
)
// Server is an HTTP proxy server.

View file

@ -2,11 +2,11 @@ package loopback
import (
"context"
"github.com/xtls/xray-core/common/net/cnc"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/net/cnc"
"github.com/xtls/xray-core/common/retry"
"github.com/xtls/xray-core/common/session"
"github.com/xtls/xray-core/common/task"

View file

@ -5,8 +5,6 @@ import (
"context"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/crypto"
@ -18,6 +16,7 @@ import (
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet/stat"
)
var dcList = []net.Address{

View file

@ -8,13 +8,12 @@ package proxy
import (
"context"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/stat"
)
// An Inbound processes inbound connections.

View file

@ -4,8 +4,6 @@ import (
"context"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/net"
@ -18,6 +16,7 @@ import (
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/stat"
)
// Client is a inbound handler for Shadowsocks protocol

View file

@ -4,8 +4,6 @@ import (
"context"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/log"
@ -18,6 +16,7 @@ import (
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/transport/internet/udp"
)

View file

@ -4,8 +4,6 @@ import (
"context"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/net"
@ -19,6 +17,7 @@ import (
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/stat"
)
// Client is a Socks5 client.

View file

@ -5,8 +5,6 @@ import (
"io"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/log"
@ -20,6 +18,7 @@ import (
"github.com/xtls/xray-core/features"
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/transport/internet/udp"
)

View file

@ -5,8 +5,6 @@ import (
"syscall"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
@ -22,6 +20,7 @@ import (
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/transport/internet/xtls"
)

View file

@ -8,8 +8,6 @@ import (
"runtime"
"syscall"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
@ -17,6 +15,7 @@ import (
"github.com/xtls/xray-core/common/session"
"github.com/xtls/xray-core/common/signal"
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/transport/internet/xtls"
)

View file

@ -8,8 +8,6 @@ import (
"syscall"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
@ -26,6 +24,7 @@ import (
"github.com/xtls/xray-core/features/policy"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/transport/internet/tls"
"github.com/xtls/xray-core/transport/internet/udp"
"github.com/xtls/xray-core/transport/internet/xtls"

View file

@ -9,8 +9,6 @@ import (
"runtime"
"syscall"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
@ -19,6 +17,7 @@ import (
"github.com/xtls/xray-core/common/signal"
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/proxy/vless"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/transport/internet/xtls"
)

View file

@ -10,8 +10,6 @@ import (
"syscall"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
@ -31,6 +29,7 @@ import (
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/proxy/vless"
"github.com/xtls/xray-core/proxy/vless/encoding"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/transport/internet/tls"
"github.com/xtls/xray-core/transport/internet/xtls"
)

View file

@ -7,8 +7,6 @@ import (
"syscall"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/net"
@ -26,6 +24,7 @@ import (
"github.com/xtls/xray-core/proxy/vless/encoding"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/transport/internet/xtls"
)

View file

@ -5,11 +5,10 @@ import (
"encoding/binary"
"hash/fnv"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/crypto"
"golang.org/x/crypto/sha3"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/crypto"
)
// Authenticate authenticates a byte array using Fnv hash.

View file

@ -28,8 +28,7 @@ func TestRequestSerialization(t *testing.T) {
}
id := uuid.New()
account := &vmess.Account{
Id: id.String(),
AlterId: 0,
Id: id.String(),
}
user.Account = toAccount(account)
@ -78,8 +77,7 @@ func TestInvalidRequest(t *testing.T) {
}
id := uuid.New()
account := &vmess.Account{
Id: id.String(),
AlterId: 0,
Id: id.String(),
}
user.Account = toAccount(account)
@ -120,8 +118,7 @@ func TestMuxRequest(t *testing.T) {
}
id := uuid.New()
account := &vmess.Account{
Id: id.String(),
AlterId: 0,
Id: id.String(),
}
user.Account = toAccount(account)

View file

@ -9,8 +9,6 @@ import (
"sync"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/errors"
@ -28,6 +26,7 @@ import (
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/proxy/vmess"
"github.com/xtls/xray-core/proxy/vmess/encoding"
"github.com/xtls/xray-core/transport/internet/stat"
)
var (

View file

@ -9,8 +9,6 @@ import (
"hash/crc64"
"time"
"github.com/xtls/xray-core/transport/internet/stat"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/net"
@ -27,6 +25,7 @@ import (
"github.com/xtls/xray-core/proxy/vmess/encoding"
"github.com/xtls/xray-core/transport"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/stat"
)
// Handler is an outbound connection handler for VMess protocol.

View file

@ -71,6 +71,11 @@ func NewTimedUserValidator(hasher protocol.IDHash) *TimedUserValidator {
return tuv
}
// visible for testing
func (v *TimedUserValidator) GetBaseTime() protocol.Timestamp {
return v.baseTime
}
func (v *TimedUserValidator) generateNewHashes(nowSec protocol.Timestamp, user *user) {
var hashValue [16]byte
genEndSec := nowSec + cacheDurationSec

View file

@ -2,7 +2,6 @@ package vmess_test
import (
"testing"
"time"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/protocol"
@ -26,15 +25,14 @@ func TestUserValidator(t *testing.T) {
user := &protocol.MemoryUser{
Email: "test",
Account: toAccount(&Account{
Id: id.String(),
AlterId: 8,
Id: id.String(),
}),
}
common.Must(v.Add(user))
{
testSmallLag := func(lag time.Duration) {
ts := protocol.Timestamp(time.Now().Add(time.Second * lag).Unix())
testSmallLag := func(lag int64) {
ts := int64(v.GetBaseTime()) + lag + 240
idHash := hasher(id.Bytes())
common.Must2(serial.WriteUint64(idHash, uint64(ts)))
userHash := idHash.Sum(nil)
@ -46,7 +44,7 @@ func TestUserValidator(t *testing.T) {
if euser.Email != user.Email {
t.Error("unexpected user email: ", euser.Email, " want ", user.Email)
}
if ets != ts {
if int64(ets) != ts {
t.Error("unexpected timestamp: ", ets, " want ", ts)
}
}
@ -61,8 +59,8 @@ func TestUserValidator(t *testing.T) {
}
{
testBigLag := func(lag time.Duration) {
ts := protocol.Timestamp(time.Now().Add(time.Second * lag).Unix())
testBigLag := func(lag int64) {
ts := int64(v.GetBaseTime()) + lag + 240
idHash := hasher(id.Bytes())
common.Must2(serial.WriteUint64(idHash, uint64(ts)))
userHash := idHash.Sum(nil)
@ -99,8 +97,7 @@ func BenchmarkUserValidator(b *testing.B) {
v.Add(&protocol.MemoryUser{
Email: "test",
Account: toAccount(&Account{
Id: id.String(),
AlterId: 16,
Id: id.String(),
}),
})
}