Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wardviaene committed Oct 15, 2024
1 parent 3b5b45f commit 705bb76
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion cmd/rest-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func main() {
}
licenseUserCount, cloudType := licensing.GetMaxUsers(localStorage)

userStore, err := users.NewUserStore(localStorage, licenseUserCount)
userStore, err := users.NewUserStoreWithHooks(localStorage, licenseUserCount, users.UserHooks{
DisableFunc: wireguard.DisableAllClientConfigs,
DeleteFunc: wireguard.DeleteAllClientConfigs,
ReactivateFunc: wireguard.ReactivateAllClientConfigs,
})
if err != nil {
log.Fatalf("startup failed: userstore initialization error: %s", err)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/vpn/resources/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
1 change: 1 addition & 0 deletions pkg/vpn/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vpn

import (
_ "embed"
"encoding/json"
"fmt"
"net/http"
Expand Down
4 changes: 2 additions & 2 deletions pkg/vpn/vpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestSCIMCreateUserConnectionDeleteUserFlow(t *testing.T) {
if err != nil {
t.Fatalf("cannot empty user store")
}
s := scim.New(storage, userStore, "token", nil, nil)
s := scim.New(storage, userStore, "token", wireguard.DisableAllClientConfigs, wireguard.ReactivateAllClientConfigs)

l, err := net.Listen("tcp", wireguard.CONFIGMANAGER_URI)
if err != nil {
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestCreateUserConnectionSuspendUserFlow(t *testing.T) {
if err != nil {
t.Fatalf("cannot empty user store")
}
s := scim.New(storage, userStore, "token", nil, nil)
s := scim.New(storage, userStore, "token", wireguard.DisableAllClientConfigs, wireguard.ReactivateAllClientConfigs)

l, err := net.Listen("tcp", wireguard.CONFIGMANAGER_URI)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/wireguard/wireguardclientconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ func GenerateNewClientConfig(storage storage.Iface, connectionID, userID string)

return out.Bytes(), nil
}
func DeleteAllClientConfigs(storage storage.Iface, userID string) error {
func DeleteAllClientConfigs(storage storage.Iface, user users.User) error {
clients, err := storage.ReadDir(storage.ConfigPath(VPN_CLIENTS_DIR))
if err != nil {
return fmt.Errorf("cannot list files in users clients directory: %s", err)
}

for _, clientFilename := range clients {
if HasClientUserID(clientFilename, userID) {
if HasClientUserID(clientFilename, user.ID) {
filename := storage.ConfigPath(path.Join(VPN_CLIENTS_DIR, clientFilename))
err = storage.Remove(filename)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/wireguard/wireguardclientconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func TestCreateAndDeleteAllClientConfig(t *testing.T) {
t.Errorf("Public key not found in client config")
}

err = DeleteAllClientConfigs(storage, "2-2-2-2")
err = DeleteAllClientConfigs(storage, users.User{ID: "2-2-2-2"})
if err != nil {
t.Fatalf("DeleteAllClientConfigs error: %s", err)
}
Expand Down

0 comments on commit 705bb76

Please sign in to comment.