mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-27 06:49:07 +01:00
The mobile bridges only carried the policy fetcher, leaving every enforcement decision to the native apps: the desktop derived its UI restrictions in the Wails service layer, the daemon kept the conflict machinery in the server package, and both mobile bridges duplicated the JSON fetch adapter. Anything the native side had to reimplement was a place for iOS and Android to drift apart. Enforcement now lives in client/mdm and is consumed identically by all three platforms: - conflicts.go holds the value-aware conflict checks lifted out of the daemon, so the same normalization (canonical URLs, PSK sentinel echo) applies wherever a config change is validated. - restrictions.go derives the UI enforcement snapshot from a policy and renders it in the JSON shape the desktop frontend already consumes. The service-layer types become aliases, keeping one source of truth. - jsonloader.go replaces the adapter that was copy-pasted into both bridges. - changedetector.go moves change detection off the native side: the caller forwards the OS notification and asks whether the managed configuration actually changed, instead of diffing dictionaries itself. The mobile bridges gain the enforcement the daemon already had. The Preferences getters resolve managed keys from the policy, so a naive UI shows the enforced value; Commit rejects a staged change that diverges from a managed key; NewAuth resolves the managed management URL before persisting the config and overlays the policy on it, so a login can no longer run against a URL the policy forbids. Android's profile mutations fail closed when disableProfiles is set. NewAuth takes the fetcher as a required argument rather than keeping a policy-blind overload: the apps consume this code as a submodule, so a compile error at the bump is the point. The mobile PSK getter is replaced by a presence check — the key has no reason to cross the bridge, and not returning it means the native side needs no redaction sentinel of its own.
52 lines
1.9 KiB
Go
52 lines
1.9 KiB
Go
package android
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// NewAuth must reuse the configuration already at cfgPath rather than building a fresh one.
|
|
//
|
|
// Creating a new in-memory config on every call gives the client a new WireGuard private key each
|
|
// time. The peer registers under that key and the key is written out, so a peer registered by an
|
|
// earlier call is orphaned on the server — a client that enrols twice leaves two entries and owns
|
|
// neither. It also breaks enrol-then-run: RunWithoutLogin reloads the configuration from disk, so
|
|
// the identity that registered is not the identity that runs, and the management stream rejects it
|
|
// with "no peer auth method provided, please use a setup key or interactive SSO login".
|
|
func TestNewAuth_ReusesPersistedIdentity(t *testing.T) {
|
|
cfgPath := filepath.Join(t.TempDir(), "config.json")
|
|
|
|
first, err := NewAuth(cfgPath, "https://api.example.com:443", nil)
|
|
if err != nil {
|
|
t.Fatalf("first NewAuth: %v", err)
|
|
}
|
|
if first.config.PrivateKey == "" {
|
|
t.Fatal("first NewAuth produced no private key")
|
|
}
|
|
|
|
second, err := NewAuth(cfgPath, "https://api.example.com:443", nil)
|
|
if err != nil {
|
|
t.Fatalf("second NewAuth: %v", err)
|
|
}
|
|
|
|
if second.config.PrivateKey != first.config.PrivateKey {
|
|
t.Errorf("private key changed between calls: a second enrolment would orphan the peer registered by the first")
|
|
}
|
|
}
|
|
|
|
// A missing configuration is still created, so a first enrolment works unchanged.
|
|
func TestNewAuth_CreatesConfigWhenAbsent(t *testing.T) {
|
|
cfgPath := filepath.Join(t.TempDir(), "config.json")
|
|
|
|
auth, err := NewAuth(cfgPath, "https://api.example.com:443", nil)
|
|
if err != nil {
|
|
t.Fatalf("NewAuth: %v", err)
|
|
}
|
|
if auth.config == nil || auth.config.PrivateKey == "" {
|
|
t.Fatal("NewAuth did not create a usable configuration")
|
|
}
|
|
if auth.cfgPath != cfgPath {
|
|
t.Errorf("cfgPath = %q, want %q", auth.cfgPath, cfgPath)
|
|
}
|
|
}
|