Skip to content
Snippets Groups Projects
Commit 10f42412 authored by Fabian Seidl's avatar Fabian Seidl
Browse files

tests for autg api

parent f0d4d76d
No related branches found
No related tags found
1 merge request!287Implement data persisting for user management
......@@ -2,6 +2,7 @@ package server
import (
"context"
"fmt"
"time"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
......@@ -125,6 +126,9 @@ func (s Auth) GetUser(ctx context.Context, request *apb.GetUserRequest) (*apb.Ge
start := metrics.StartHook(labels, grpcRequestsTotal)
defer metrics.FinishHook(labels, start, grpcRequestDurationSecondsTotal, grpcRequestDurationSeconds)
usersA, _ := userc.GetAll()
fmt.Printf("%+v", usersA)
// TODO: implement check if user is allowed to get this user data; only their own if not admin
userData, err := userc.Get(store.Query{Name: request.Name})
if err != nil {
......@@ -230,6 +234,8 @@ func (s Auth) isValidUser(user rbac.User) (bool, error) {
storedUser, err := userc.Get(store.Query{Name: user.Name()})
if err != nil {
return false, err
} else if storedUser == nil {
return false, status.Errorf(codes.Aborted, "no user object")
}
if storedUser.Name() == user.Name() {
......
This diff is collapsed.
......@@ -46,6 +46,7 @@ var deviceUUID uuid.UUID
var mockPnd *mocks.NetworkDomain
var mockDevice device.Device
var sbiStore southbound.SbiStore
var mockJwt *rbac.JWTManager
func callback(id uuid.UUID, ch chan device.Details) {
// Need for pnd creation, but not needed for this test case.
......@@ -148,8 +149,14 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}
// everyting auth related
userc = rbac.NewUserStore()
rolec = rbac.NewRoleStore()
err = clearAndCreateAuthTestSetup()
if err != nil {
log.Fatal(err)
}
jwt = rbac.NewJWTManager("", 1*time.Minute)
os.Exit(m.Run())
}
......
package store
import (
"errors"
"github.com/google/uuid"
)
......@@ -26,7 +28,7 @@ func NewGenericStore[T storableConstraint]() GenericStore[T] {
func (t *GenericStore[T]) Add(item T) error {
_, ok := t.Store[item.ID()]
if ok {
return nil
return errors.New("item not found")
}
t.Store[item.ID()] = item
......@@ -60,12 +62,12 @@ func (t *GenericStore[T]) Get(query Query) (T, error) {
// Second search for name
id, ok := t.nameLookupTable[query.Name]
if !ok {
return *new(T), nil
return *new(T), errors.New("item not found")
}
item, ok := t.Store[id]
if !ok {
return *new(T), nil
return *new(T), errors.New("item not found")
}
return item, nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment