Skip to content

Commit

Permalink
fix networks manager
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fischer committed Dec 17, 2024
1 parent fb75bd6 commit a52e9c6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
4 changes: 2 additions & 2 deletions management/cmd/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ var (
userManager := users.NewManager(store)
settingsManager := settings.NewManager(store)
permissionsManager := permissions.NewManager(userManager, settingsManager)
networksManager := networks.NewManager(store, permissionsManager)
groupsManager := groups.NewManager(store, permissionsManager)
resourcesManager := resources.NewManager(store, permissionsManager, accountManager)
routersManager := routers.NewManager(store, permissionsManager, accountManager)
networksManager := networks.NewManager(store, permissionsManager, resourcesManager)
groupsManager := groups.NewManager(store, permissionsManager)

httpAPIHandler, err := httpapi.APIHandler(ctx, accountManager, networksManager, resourcesManager, routersManager, groupsManager, geo, *jwtValidator, appMetrics, httpAPIAuthCfg, integratedPeerValidator)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion management/server/networks/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/rs/xid"

"github.com/netbirdio/netbird/management/server/networks/resources"
"github.com/netbirdio/netbird/management/server/networks/types"
"github.com/netbirdio/netbird/management/server/permissions"
"github.com/netbirdio/netbird/management/server/status"
Expand All @@ -23,12 +24,14 @@ type Manager interface {
type managerImpl struct {
store store.Store
permissionsManager permissions.Manager
resourcesManager resources.Manager
}

func NewManager(store store.Store, permissionsManager permissions.Manager) Manager {
func NewManager(store store.Store, permissionsManager permissions.Manager, manager resources.Manager) Manager {
return &managerImpl{
store: store,
permissionsManager: permissionsManager,
resourcesManager: manager,
}
}

Expand Down
43 changes: 33 additions & 10 deletions management/server/networks/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/stretchr/testify/require"

"github.com/netbirdio/netbird/management/server/mock_server"
"github.com/netbirdio/netbird/management/server/networks/resources"
"github.com/netbirdio/netbird/management/server/networks/types"
"github.com/netbirdio/netbird/management/server/permissions"
"github.com/netbirdio/netbird/management/server/store"
Expand All @@ -21,8 +23,10 @@ func Test_GetAllNetworksReturnsNetworks(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
manager := NewManager(s, permissionsManager)
resourcesManager := resources.NewManager(s, permissionsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

networks, err := manager.GetAllNetworks(ctx, accountID, userID)
require.NoError(t, err)
Expand All @@ -40,8 +44,10 @@ func Test_GetAllNetworksReturnsPermissionDenied(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
manager := NewManager(s, permissionsManager)
resourcesManager := resources.NewManager(s, permissionsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

networks, err := manager.GetAllNetworks(ctx, accountID, userID)
require.Error(t, err)
Expand All @@ -59,8 +65,10 @@ func Test_GetNetworkReturnsNetwork(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
manager := NewManager(s, permissionsManager)
resourcesManager := resources.NewManager(s, permissionsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

networks, err := manager.GetNetwork(ctx, accountID, userID, networkID)
require.NoError(t, err)
Expand All @@ -78,8 +86,10 @@ func Test_GetNetworkReturnsPermissionDenied(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
manager := NewManager(s, permissionsManager)
resourcesManager := resources.NewManager(s, permissionsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

network, err := manager.GetNetwork(ctx, accountID, userID, networkID)
require.Error(t, err)
Expand All @@ -99,8 +109,10 @@ func Test_CreateNetworkSuccessfully(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
manager := NewManager(s, permissionsManager)
resourcesManager := resources.NewManager(s, permissionsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

createdNetwork, err := manager.CreateNetwork(ctx, userID, network)
require.NoError(t, err)
Expand All @@ -120,8 +132,10 @@ func Test_CreateNetworkFailsWithPermissionDenied(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
manager := NewManager(s, permissionsManager)
resourcesManager := resources.NewManager(s, permissionsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

createdNetwork, err := manager.CreateNetwork(ctx, userID, network)
require.Error(t, err)
Expand All @@ -139,8 +153,10 @@ func Test_DeleteNetworkSuccessfully(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
manager := NewManager(s, permissionsManager)
resourcesManager := resources.NewManager(s, permissionsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

err = manager.DeleteNetwork(ctx, accountID, userID, networkID)
require.NoError(t, err)
Expand All @@ -157,8 +173,10 @@ func Test_DeleteNetworkFailsWithPermissionDenied(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
manager := NewManager(s, permissionsManager)
resourcesManager := resources.NewManager(s, permissionsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

err = manager.DeleteNetwork(ctx, accountID, userID, networkID)
require.Error(t, err)
Expand All @@ -178,8 +196,10 @@ func Test_UpdateNetworkSuccessfully(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(cleanUp)
am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
manager := NewManager(s, permissionsManager)
resourcesManager := resources.NewManager(s, permissionsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

updatedNetwork, err := manager.UpdateNetwork(ctx, userID, network)
require.NoError(t, err)
Expand All @@ -200,8 +220,11 @@ func Test_UpdateNetworkFailsWithPermissionDenied(t *testing.T) {
t.Fatal(err)
}
t.Cleanup(cleanUp)

am := mock_server.MockAccountManager{}
permissionsManager := permissions.NewManagerMock()
manager := NewManager(s, permissionsManager)
resourcesManager := resources.NewManager(s, permissionsManager, &am)
manager := NewManager(s, permissionsManager, resourcesManager)

updatedNetwork, err := manager.UpdateNetwork(ctx, userID, network)
require.Error(t, err)
Expand Down

0 comments on commit a52e9c6

Please sign in to comment.