mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-16 11:39:57 +00:00
Stand up the full agent-network data path in containers and drive a real chat-completion through the gateway: - harness: a shared docker network (combined server reachable by alias), a proxy container built from the published reverse-proxy image (NB_PROXY_PRIVATE, NB_PROXY_ALLOW_INSECURE, NB_RELAY_TRANSPORT=ws to match the combined server's WS-multiplexed relay) with a generated self-signed wildcard cert, and a netbird client container that joins via a setup key. - the combined image, proxy image, and client image default to the published rc.2 releases (overridable via NB_E2E_*_IMAGE; a bare local tag is built from source instead). Geolocation download is disabled so the server starts without external fetches. - one shared domain is used for the management exposed address, the proxy domain, and the agent-network cluster; the proxy token is minted via the server CLI (global) to match the manual install. TestChatCompletionThroughProxy provisions provider+policy+group+setup key, runs proxy+client, drives an OpenAI chat-completion through the tunnel, and asserts a 200 plus the ingested access-log row. Requires OPENAI_TOKEN (skips otherwise). The provider must be created with enabled=true explicitly — the create default is false despite the API doc.
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
//go:build e2e
|
|
|
|
package harness
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/netbirdio/netbird/shared/management/client/rest"
|
|
"github.com/netbirdio/netbird/shared/management/http/api"
|
|
)
|
|
|
|
// Bootstrap creates the initial admin owner through the unauthenticated
|
|
// /api/setup endpoint and returns the plaintext admin PAT. It also wires an
|
|
// authenticated REST client on the Combined (see API). create_pat requires the
|
|
// server to run with NB_SETUP_PAT_ENABLED=true, which the harness sets. A
|
|
// second call returns an error (the server reports setup already completed).
|
|
func (c *Combined) Bootstrap(ctx context.Context) (string, error) {
|
|
// The setup endpoint is unauthenticated; use a tokenless client.
|
|
setupClient := rest.NewWithOptions(rest.WithManagementURL(c.BaseURL))
|
|
|
|
createPAT := true
|
|
expireDays := 1
|
|
resp, err := setupClient.Instance.Setup(ctx, api.PostApiSetupJSONRequestBody{ //nolint:gosec // static throwaway test credentials
|
|
Email: "admin@netbird.test",
|
|
Password: "Netbird-e2e-Passw0rd!",
|
|
Name: "E2E Admin",
|
|
CreatePat: &createPAT,
|
|
PatExpireIn: &expireDays,
|
|
})
|
|
if err != nil {
|
|
return "", fmt.Errorf("instance setup: %w", err)
|
|
}
|
|
if resp.PersonalAccessToken == nil || *resp.PersonalAccessToken == "" {
|
|
return "", fmt.Errorf("setup succeeded but no PAT returned (is NB_SETUP_PAT_ENABLED set?)")
|
|
}
|
|
|
|
c.PAT = *resp.PersonalAccessToken
|
|
c.api = rest.New(c.BaseURL, c.PAT)
|
|
return c.PAT, nil
|
|
}
|
|
|
|
// API returns the PAT-authenticated management REST client. It is nil until
|
|
// Bootstrap runs.
|
|
func (c *Combined) API() *rest.Client {
|
|
return c.api
|
|
}
|