mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-25 09:33:24 +01:00
d4b6d7646c
Implement user deletion across all IDP-ss. Expires all user peers when the user is deleted. Users are permanently removed from a local store, but in IDP, we remove Netbird attributes for the user untilUserDeleteFromIDPEnabled setting is not enabled. To test, an admin user should remove any additional users. Until the UI incorporates this feature, use a curl DELETE request targeting the /users/<USER_ID> management endpoint. Note that this request only removes user attributes and doesn't trigger a delete from the IDP. To enable user removal from the IdP, set UserDeleteFromIDPEnabled to true in account settings. Until we have a UI for this, make this change directly in the store file. Store the deleted email addresses in encrypted in activity store.
123 lines
2.8 KiB
Go
123 lines
2.8 KiB
Go
package cmd
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/netbirdio/netbird/management/server/activity"
|
|
|
|
"github.com/netbirdio/netbird/util"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
clientProto "github.com/netbirdio/netbird/client/proto"
|
|
client "github.com/netbirdio/netbird/client/server"
|
|
mgmtProto "github.com/netbirdio/netbird/management/proto"
|
|
mgmt "github.com/netbirdio/netbird/management/server"
|
|
sigProto "github.com/netbirdio/netbird/signal/proto"
|
|
sig "github.com/netbirdio/netbird/signal/server"
|
|
)
|
|
|
|
func startTestingServices(t *testing.T) string {
|
|
config := &mgmt.Config{}
|
|
_, err := util.ReadJson("../testdata/management.json", config)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
testDir := t.TempDir()
|
|
config.Datadir = testDir
|
|
err = util.CopyFileContents("../testdata/store.json", filepath.Join(testDir, "store.json"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
_, signalLis := startSignal(t)
|
|
signalAddr := signalLis.Addr().String()
|
|
config.Signal.URI = signalAddr
|
|
|
|
_, mgmLis := startManagement(t, config)
|
|
mgmAddr := mgmLis.Addr().String()
|
|
return mgmAddr
|
|
}
|
|
|
|
func startSignal(t *testing.T) (*grpc.Server, net.Listener) {
|
|
lis, err := net.Listen("tcp", ":0")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := grpc.NewServer()
|
|
sigProto.RegisterSignalExchangeServer(s, sig.NewServer())
|
|
go func() {
|
|
if err := s.Serve(lis); err != nil {
|
|
panic(err)
|
|
}
|
|
}()
|
|
|
|
return s, lis
|
|
}
|
|
|
|
func startManagement(t *testing.T, config *mgmt.Config) (*grpc.Server, net.Listener) {
|
|
lis, err := net.Listen("tcp", ":0")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := grpc.NewServer()
|
|
store, err := mgmt.NewFileStore(config.Datadir, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
peersUpdateManager := mgmt.NewPeersUpdateManager()
|
|
eventStore := &activity.InMemoryEventStore{}
|
|
if err != nil {
|
|
return nil, nil
|
|
}
|
|
accountManager, err := mgmt.BuildManager(store, peersUpdateManager, nil, "", "",
|
|
eventStore, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
turnManager := mgmt.NewTimeBasedAuthSecretsManager(peersUpdateManager, config.TURNConfig)
|
|
mgmtServer, err := mgmt.NewServer(config, accountManager, peersUpdateManager, turnManager, nil, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mgmtProto.RegisterManagementServiceServer(s, mgmtServer)
|
|
go func() {
|
|
if err := s.Serve(lis); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}()
|
|
|
|
return s, lis
|
|
}
|
|
|
|
func startClientDaemon(
|
|
t *testing.T, ctx context.Context, managementURL, configPath string,
|
|
) (*grpc.Server, net.Listener) {
|
|
lis, err := net.Listen("tcp", "127.0.0.1:0")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := grpc.NewServer()
|
|
|
|
server := client.New(ctx,
|
|
configPath, "")
|
|
if err := server.Start(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
clientProto.RegisterDaemonServiceServer(s, server)
|
|
go func() {
|
|
if err := s.Serve(lis); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}()
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
return s, lis
|
|
}
|