From d3ac251dfba62dcd66a8aed10fb909c00b73f1ef Mon Sep 17 00:00:00 2001 From: Edward Viaene Date: Tue, 15 Oct 2024 14:21:24 -0500 Subject: [PATCH] fix tests --- .github/workflows/tests.yml | 2 +- cmd/rest-server/main.go | 2 +- go.mod | 2 +- go.sum | 4 ++++ pkg/vpn/vpn_test.go | 33 ++++++++++++++++++++++++++++----- webapp/package.json | 2 +- webapp/src/Routes/Logs/Logs.tsx | 6 +++--- 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6cadf56..50bf310 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,6 +18,6 @@ jobs: - name: Go generate run: | go generate ./... - touch pkg/rest/static/placeholder # we're not building frontend, so we put a placeholder + touch cmd/rest-server/static/placeholder # we're not building frontend, so we put a placeholder - name: Test run: make test diff --git a/cmd/rest-server/main.go b/cmd/rest-server/main.go index 1417db4..bce3055 100644 --- a/cmd/rest-server/main.go +++ b/cmd/rest-server/main.go @@ -43,7 +43,7 @@ func main() { log.Fatalf("startup failed: userstore initialization error: %s", err) } - scimInstance := scim.New(localStorage, userStore, "", wireguard.DisableAllClientConfigs, wireguard.ReactivateAllClientConfigs) + scimInstance := scim.New(localStorage, userStore, "") apps := map[string]rest.AppClient{ "vpn": vpn.New(localStorage, userStore), diff --git a/go.mod b/go.mod index 3893290..64b81b5 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( golang.org/x/term v0.25.0 ) -require github.com/in4it/go-devops-platform v0.0.0-20241015173332-a45080cabae5 // indirect +require github.com/in4it/go-devops-platform v0.0.0-20241015191315-e2f711a32e69 // indirect require ( github.com/aws/aws-sdk-go-v2 v1.32.2 // indirect diff --git a/go.sum b/go.sum index 675bfac..d3f98d7 100644 --- a/go.sum +++ b/go.sum @@ -104,6 +104,10 @@ github.com/in4it/go-devops-platform v0.0.0-20241015173130-0b49ea0db408 h1:iQl/CX github.com/in4it/go-devops-platform v0.0.0-20241015173130-0b49ea0db408/go.mod h1:xugWZer+8U7DcIWlE95SiPvtVPmJzhB9YCYiIScLK5Q= github.com/in4it/go-devops-platform v0.0.0-20241015173332-a45080cabae5 h1:pcZ2PeYjk5/Bis6llji5uTqocjbIpxPlm4flLoweVt0= github.com/in4it/go-devops-platform v0.0.0-20241015173332-a45080cabae5/go.mod h1:xugWZer+8U7DcIWlE95SiPvtVPmJzhB9YCYiIScLK5Q= +github.com/in4it/go-devops-platform v0.0.0-20241015191019-e2183445416a h1:y0pHhwuhAZYB4v99PHYScjyPv45mfCM5iiUWL6rAhIg= +github.com/in4it/go-devops-platform v0.0.0-20241015191019-e2183445416a/go.mod h1:xugWZer+8U7DcIWlE95SiPvtVPmJzhB9YCYiIScLK5Q= +github.com/in4it/go-devops-platform v0.0.0-20241015191315-e2f711a32e69 h1:/1BTKr5cqiQKAf8KMhR8z6Pup7eqzDbh32qQb+xh4Tw= +github.com/in4it/go-devops-platform v0.0.0-20241015191315-e2f711a32e69/go.mod h1:xugWZer+8U7DcIWlE95SiPvtVPmJzhB9YCYiIScLK5Q= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= diff --git a/pkg/vpn/vpn_test.go b/pkg/vpn/vpn_test.go index 8632a91..a01d8e7 100644 --- a/pkg/vpn/vpn_test.go +++ b/pkg/vpn/vpn_test.go @@ -24,7 +24,11 @@ const USERSTORE_MAX_USERS = 1000 func TestSCIMCreateUserConnectionDeleteUserFlow(t *testing.T) { storage := &memorystorage.MockMemoryStorage{} - userStore, err := users.NewUserStore(storage, USERSTORE_MAX_USERS) + userStore, err := users.NewUserStoreWithHooks(storage, USERSTORE_MAX_USERS, users.UserHooks{ + DisableFunc: wireguard.DisableAllClientConfigs, + DeleteFunc: wireguard.DeleteAllClientConfigs, + ReactivateFunc: wireguard.ReactivateAllClientConfigs, + }) if err != nil { t.Fatalf("cannot create new user store: %s", err) } @@ -32,7 +36,7 @@ func TestSCIMCreateUserConnectionDeleteUserFlow(t *testing.T) { if err != nil { t.Fatalf("cannot empty user store") } - s := scim.New(storage, userStore, "token", wireguard.DisableAllClientConfigs, wireguard.ReactivateAllClientConfigs) + s := scim.New(storage, userStore, "token") l, err := net.Listen("tcp", wireguard.CONFIGMANAGER_URI) if err != nil { @@ -145,7 +149,11 @@ func TestSCIMCreateUserConnectionDeleteUserFlow(t *testing.T) { func TestCreateUserConnectionSuspendUserFlow(t *testing.T) { storage := &memorystorage.MockMemoryStorage{} - userStore, err := users.NewUserStore(storage, USERSTORE_MAX_USERS) + userStore, err := users.NewUserStoreWithHooks(storage, USERSTORE_MAX_USERS, users.UserHooks{ + DisableFunc: wireguard.DisableAllClientConfigs, + DeleteFunc: wireguard.DeleteAllClientConfigs, + ReactivateFunc: wireguard.ReactivateAllClientConfigs, + }) if err != nil { t.Fatalf("cannot create new user store: %s", err) } @@ -153,7 +161,7 @@ func TestCreateUserConnectionSuspendUserFlow(t *testing.T) { if err != nil { t.Fatalf("cannot empty user store") } - s := scim.New(storage, userStore, "token", wireguard.DisableAllClientConfigs, wireguard.ReactivateAllClientConfigs) + s := scim.New(storage, userStore, "token") l, err := net.Listen("tcp", wireguard.CONFIGMANAGER_URI) if err != nil { @@ -316,7 +324,16 @@ func TestCreateUserConnectionDeleteUserFlow(t *testing.T) { // first create a new user storage := &memorystorage.MockMemoryStorage{} - v := New(storage, &users.UserStore{}) + userStore, err := users.NewUserStoreWithHooks(storage, USERSTORE_MAX_USERS, users.UserHooks{ + DisableFunc: wireguard.DisableAllClientConfigs, + DeleteFunc: wireguard.DeleteAllClientConfigs, + ReactivateFunc: wireguard.ReactivateAllClientConfigs, + }) + if err != nil { + t.Fatalf("cannot create new user store: %s", err) + } + + v := New(storage, userStore) err = v.UserStore.Empty() if err != nil { @@ -392,6 +409,12 @@ func TestCreateUserConnectionDeleteUserFlow(t *testing.T) { t.Fatalf("user deletion error: %s", err) } + err = v.UserStore.UserHooks.DeleteFunc(v.Storage, users.User{ID: user.ID}) + if err != nil { + t.Fatalf("could not delete all clients for user %s: %s", user.ID, err) + + } + _, err = storage.ReadFile(userConfigFilename) if err == nil { t.Fatalf("could read user config file, expected not to") diff --git a/webapp/package.json b/webapp/package.json index 41d6964..8625e78 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "vite", - "build": "tsc && vite build && cp -r dist/* ../pkg/rest/static", + "build": "tsc && vite build && cp -r dist/* ../cmd/rest-server/static", "lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview", "test": "vitest" diff --git a/webapp/src/Routes/Logs/Logs.tsx b/webapp/src/Routes/Logs/Logs.tsx index dd8a0e5..375c000 100644 --- a/webapp/src/Routes/Logs/Logs.tsx +++ b/webapp/src/Routes/Logs/Logs.tsx @@ -1,9 +1,9 @@ -import { Card, Container, Text, Table, Title, Button, Grid, Popover, Group, TextInput, rem, ActionIcon, Checkbox, Highlight, MultiSelect} from "@mantine/core"; +import { Container, Table, Title, Button, Grid, Popover, Group, TextInput, rem, ActionIcon, Checkbox, Highlight} from "@mantine/core"; import { AppSettings } from "../../Constants/Constants"; import { useInfiniteQuery } from "@tanstack/react-query"; import { useAuthContext } from "../../Auth/Auth"; -import { Link, useSearchParams } from "react-router-dom"; -import { TbArrowRight, TbSearch, TbSettings } from "react-icons/tb"; +import { useSearchParams } from "react-router-dom"; +import { TbArrowRight, TbSearch } from "react-icons/tb"; import { DatePickerInput } from "@mantine/dates"; import { useEffect, useState } from "react"; import React from "react";