Skip to content
Snippets Groups Projects
Commit 3bb4d35c authored by André Sterba's avatar André Sterba
Browse files

Adjust role and tests

parent 81f439cd
Branches
No related tags found
6 merge requests!376Add additional example application hostname-checker,!349Northbound refactoring to implement NIB concept for devices,!343Add basic application framework and example application to show interaction between events an NBI,!339Create basic venv-manager for use with arista,!327Remove NBI package global services and refactor NBI servers,!324Provide prototype implementation for topology handling
This commit is part of merge request !343. Comments created here will be created in the context of that merge request.
...@@ -23,10 +23,11 @@ type Role struct { ...@@ -23,10 +23,11 @@ type Role struct {
roleService rbacInterfaces.RoleService roleService rbacInterfaces.RoleService
} }
// NewRoleServer receives a JWTManager and returns a new Role. // NewRoleServer receives a JWTManager and a RoleService and returns a new RoleServer.
func NewRoleServer(jwtManager *rbac.JWTManager) *Role { func NewRoleServer(jwtManager *rbac.JWTManager, roleService rbacInterfaces.RoleService) *Role {
return &Role{ return &Role{
jwtManager: jwtManager, jwtManager: jwtManager,
roleService: roleService,
} }
} }
......
...@@ -4,11 +4,31 @@ import ( ...@@ -4,11 +4,31 @@ import (
"context" "context"
"reflect" "reflect"
"testing" "testing"
"time"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
"code.fbi.h-da.de/danet/gosdn/controller/rbac"
"github.com/google/uuid" "github.com/google/uuid"
) )
func getTestRoleServer(t *testing.T) *Role {
jwtManager := rbac.NewJWTManager("test", time.Second)
userStore := rbac.NewMemoryUserStore()
userService := rbac.NewUserService(userStore)
roleStore := rbac.NewMemoryRoleStore()
roleService := rbac.NewRoleService(roleStore)
s := NewRoleServer(jwtManager, roleService)
err := clearAndCreateAuthTestSetup(userService, roleService)
if err != nil {
t.Fatalf("%v", err)
}
return s
}
func TestRole_CreateRoles(t *testing.T) { func TestRole_CreateRoles(t *testing.T) {
type args struct { type args struct {
ctx context.Context ctx context.Context
...@@ -39,7 +59,7 @@ func TestRole_CreateRoles(t *testing.T) { ...@@ -39,7 +59,7 @@ func TestRole_CreateRoles(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := Role{} s := getTestRoleServer(t)
got, err := s.CreateRoles(tt.args.ctx, tt.args.request) got, err := s.CreateRoles(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("Role.CreateRoles() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("Role.CreateRoles() error = %v, wantErr %v", err, tt.wantErr)
...@@ -95,7 +115,7 @@ func TestRole_GetRole(t *testing.T) { ...@@ -95,7 +115,7 @@ func TestRole_GetRole(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := Role{} s := getTestRoleServer(t)
got, err := s.GetRole(tt.args.ctx, tt.args.request) got, err := s.GetRole(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("Role.GetRole() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("Role.GetRole() error = %v, wantErr %v", err, tt.wantErr)
...@@ -116,11 +136,6 @@ func TestRole_GetRole(t *testing.T) { ...@@ -116,11 +136,6 @@ func TestRole_GetRole(t *testing.T) {
} }
func TestRole_GetRoles(t *testing.T) { func TestRole_GetRoles(t *testing.T) {
err := clearAndCreateAuthTestSetup()
if err != nil {
t.Fatalf("%v", err)
}
type args struct { type args struct {
ctx context.Context ctx context.Context
request *apb.GetRolesRequest request *apb.GetRolesRequest
...@@ -171,7 +186,7 @@ func TestRole_GetRoles(t *testing.T) { ...@@ -171,7 +186,7 @@ func TestRole_GetRoles(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := Role{} s := getTestRoleServer(t)
got, err := s.GetRoles(tt.args.ctx, tt.args.request) got, err := s.GetRoles(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("Role.GetRoles() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("Role.GetRoles() error = %v, wantErr %v", err, tt.wantErr)
...@@ -250,7 +265,7 @@ func TestRole_UpdateRoles(t *testing.T) { ...@@ -250,7 +265,7 @@ func TestRole_UpdateRoles(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := Role{} s := getTestRoleServer(t)
got, err := s.UpdateRoles(tt.args.ctx, tt.args.request) got, err := s.UpdateRoles(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("Role.UpdateRoles() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("Role.UpdateRoles() error = %v, wantErr %v", err, tt.wantErr)
...@@ -265,7 +280,6 @@ func TestRole_UpdateRoles(t *testing.T) { ...@@ -265,7 +280,6 @@ func TestRole_UpdateRoles(t *testing.T) {
} }
func TestRole_DeletePermissionsForRole(t *testing.T) { func TestRole_DeletePermissionsForRole(t *testing.T) {
clearAndCreateAuthTestSetup()
type args struct { type args struct {
ctx context.Context ctx context.Context
...@@ -311,7 +325,7 @@ func TestRole_DeletePermissionsForRole(t *testing.T) { ...@@ -311,7 +325,7 @@ func TestRole_DeletePermissionsForRole(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := Role{} s := getTestRoleServer(t)
got, err := s.DeletePermissionsForRole(tt.args.ctx, tt.args.request) got, err := s.DeletePermissionsForRole(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("Role.DeletePermissionsForRole() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("Role.DeletePermissionsForRole() error = %v, wantErr %v", err, tt.wantErr)
...@@ -370,8 +384,7 @@ func TestRole_DeleteRoles(t *testing.T) { ...@@ -370,8 +384,7 @@ func TestRole_DeleteRoles(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
s := Role{} s := getTestRoleServer(t)
clearAndCreateAuthTestSetup()
got, err := s.DeleteRoles(tt.args.ctx, tt.args.request) got, err := s.DeleteRoles(tt.args.ctx, tt.args.request)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment