mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-04-16 12:35:54 +00:00
1. **Fixed XPadding Placement Dropdown**: - Added the missing `cookie` and `query` options to `xPaddingPlacement` (`stream_xhttp.html`). - *Why:* Previously, users wanting `cookie` obfuscation were forced to use the `header` placement string. This caused Xray-core to blindly intercept the entire monolithic HTTP Cookie header, failing internal padding-length validations and causing the inbound to silently drop the connection. 2. **Fixed Uplink Data Placement Validation**: - Replaced the unsupported `query` option with `cookie` in `uplinkDataPlacement`. - *Why:* Xray-core's `transport_internet.go` explicitly forbids `query` as an uplink placement option. Selecting it from the UI previously sent a payload that would cause Xray-core to instantly throw an `unsupported uplink data placement: query` panic. Adding `cookie` perfectly aligns the UI with Xray-core restrictions. ### Related Issues - Resolves #3992
70 lines
1.5 KiB
Go
70 lines
1.5 KiB
Go
package buf_test
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
"github.com/xtls/xray-core/common/buf"
|
|
"github.com/xtls/xray-core/common/errors"
|
|
"github.com/xtls/xray-core/testing/mocks"
|
|
)
|
|
|
|
func TestReadError(t *testing.T) {
|
|
mockCtl := gomock.NewController(t)
|
|
defer mockCtl.Finish()
|
|
|
|
mockReader := mocks.NewReader(mockCtl)
|
|
mockReader.EXPECT().Read(gomock.Any()).Return(0, errors.New("error"))
|
|
|
|
err := buf.Copy(buf.NewReader(mockReader), buf.Discard)
|
|
if err == nil {
|
|
t.Fatal("expected error, but nil")
|
|
}
|
|
|
|
if !buf.IsReadError(err) {
|
|
t.Error("expected to be ReadError, but not")
|
|
}
|
|
|
|
if err.Error() != "common/buf_test: error" {
|
|
t.Fatal("unexpected error message: ", err.Error())
|
|
}
|
|
}
|
|
|
|
func TestWriteError(t *testing.T) {
|
|
mockCtl := gomock.NewController(t)
|
|
defer mockCtl.Finish()
|
|
|
|
mockWriter := mocks.NewWriter(mockCtl)
|
|
mockWriter.EXPECT().Write(gomock.Any()).Return(0, errors.New("error"))
|
|
|
|
err := buf.Copy(buf.NewReader(rand.Reader), buf.NewWriter(mockWriter))
|
|
if err == nil {
|
|
t.Fatal("expected error, but nil")
|
|
}
|
|
|
|
if !buf.IsWriteError(err) {
|
|
t.Error("expected to be WriteError, but not")
|
|
}
|
|
|
|
if err.Error() != "common/buf_test: error" {
|
|
t.Fatal("unexpected error message: ", err.Error())
|
|
}
|
|
}
|
|
|
|
type TestReader struct{}
|
|
|
|
func (TestReader) Read(b []byte) (int, error) {
|
|
return len(b), nil
|
|
}
|
|
|
|
func BenchmarkCopy(b *testing.B) {
|
|
reader := buf.NewReader(io.LimitReader(TestReader{}, 10240))
|
|
writer := buf.Discard
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
_ = buf.Copy(reader, writer)
|
|
}
|
|
}
|