3
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package fabricvpn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLiveFabricControlRequest(t *testing.T) {
|
||||
cfg := strings.TrimSpace(os.Getenv("RAP_LIVE_FABRIC_CONTROL_CONFIG"))
|
||||
if cfg == "" {
|
||||
t.Skip("set RAP_LIVE_FABRIC_CONTROL_CONFIG to run live fabric control test")
|
||||
}
|
||||
path := strings.TrimSpace(os.Getenv("RAP_LIVE_FABRIC_CONTROL_PATH"))
|
||||
if path == "" {
|
||||
path = "/organizations/?user_id=3fded8a8-f19b-4974-919f-44d34ac5f63d"
|
||||
}
|
||||
method := strings.TrimSpace(os.Getenv("RAP_LIVE_FABRIC_CONTROL_METHOD"))
|
||||
if method == "" {
|
||||
method = "GET"
|
||||
}
|
||||
body := strings.TrimSpace(os.Getenv("RAP_LIVE_FABRIC_CONTROL_BODY"))
|
||||
manager := NewManager()
|
||||
if err := manager.Start(cfg); err != nil {
|
||||
t.Fatalf("start manager: %v", err)
|
||||
}
|
||||
defer manager.Stop()
|
||||
request := map[string]any{"method": method, "path": path}
|
||||
if body != "" {
|
||||
var raw json.RawMessage
|
||||
if err := json.Unmarshal([]byte(body), &raw); err != nil {
|
||||
t.Fatalf("invalid request body: %v", err)
|
||||
}
|
||||
request["body"] = raw
|
||||
}
|
||||
payload, err := json.Marshal(request)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
response, err := manager.ControlRequest(string(payload))
|
||||
if err != nil {
|
||||
t.Fatalf("control request failed: %v", err)
|
||||
}
|
||||
if !strings.Contains(response, "status_code") {
|
||||
t.Fatalf("unexpected control response: %s", response)
|
||||
}
|
||||
t.Log(response)
|
||||
}
|
||||
@@ -243,7 +243,7 @@ func (m *Manager) connect(ctx context.Context, cfg runtimeConfig, cancel context
|
||||
if lastErr == nil {
|
||||
lastErr = fmt.Errorf("no QUIC exit endpoints available")
|
||||
}
|
||||
return lastErr
|
||||
return fmt.Errorf("fabric bootstrap failed after %d endpoint candidates: %w", len(cfg.Endpoints), lastErr)
|
||||
}
|
||||
|
||||
func (m *Manager) protectedQUICDialer() func(context.Context, string, *tls.Config, *quic.Config) (*quic.Conn, error) {
|
||||
@@ -447,11 +447,17 @@ func (m *Manager) ControlRequest(payloadJSON string) (string, error) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return "", ctx.Err()
|
||||
case err := <-session.Errors():
|
||||
case err, ok := <-session.Errors():
|
||||
if !ok {
|
||||
return "", fmt.Errorf("fabric control error stream closed")
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
case frame := <-session.Frames():
|
||||
case frame, ok := <-session.Frames():
|
||||
if !ok {
|
||||
return "", fmt.Errorf("fabric control stream closed")
|
||||
}
|
||||
if frame.Type != fabricproto.FrameData || frame.StreamID != mesh.FabricControlForwardQUICStreamID {
|
||||
continue
|
||||
}
|
||||
@@ -460,7 +466,7 @@ func (m *Manager) ControlRequest(payloadJSON string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
if response.Error != "" {
|
||||
return "", fmt.Errorf(response.Error)
|
||||
return "", fmt.Errorf("%s", response.Error)
|
||||
}
|
||||
return string(response.Payload), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user