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

added test for api/login

parent b7271496
No related branches found
No related tags found
No related merge requests found
This commit is part of merge request !308. Comments created here will be created in the context of that merge request.
package api
import (
"context"
"reflect"
"testing"
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"
)
func TestLogin(t *testing.T) {
type args struct {
ctx context.Context
addr string
username string
pwd string
}
tests := []struct {
name string
args args
want *apb.LoginResponse
wantErr bool
}{
{
name: "default",
args: args{
ctx: context.TODO(),
addr: testAPIEndpoint,
username: "admin",
pwd: "admin",
},
want: &apb.LoginResponse{
Status: apb.Status_STATUS_OK,
},
wantErr: false,
},
}
err := userService.Add(&rbac.User{UserID: uuid.New(), UserName: "admin", Roles: map[string]string{pndID: "admin"}, Password: "admin"})
if err != nil {
t.Errorf("Login() error = %v", err)
return
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Login(tt.args.ctx, tt.args.addr, tt.args.username, tt.args.pwd)
if (err != nil) != tt.wantErr {
t.Errorf("Login() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got.Status != apb.Status_STATUS_OK || got.Token == "" {
t.Errorf("Login() = %v, want %v", got, tt.want)
}
})
}
}
func TestLogout(t *testing.T) {
type args struct {
ctx context.Context
addr string
username string
}
tests := []struct {
name string
args args
want *apb.LogoutResponse
wantErr bool
}{
// TODO: Add test cases.
// Not implemented yet!
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Logout(tt.args.ctx, tt.args.addr, tt.args.username)
if (err != nil) != tt.wantErr {
t.Errorf("Logout() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Logout() = %v, want %v", got, tt.want)
}
})
}
}
......@@ -10,6 +10,7 @@ import (
cpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/core"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
"code.fbi.h-da.de/danet/gosdn/controller/config"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
......@@ -132,9 +133,16 @@ func bootstrapUnitTest() {
if err := pndStore.Add(&mockPnd); err != nil {
log.Fatal(err)
}
jwtManager := rbacImpl.NewJWTManager("", (10000 * time.Hour))
northbound := nbi.NewNBI(pndStore, userService, roleService)
northbound.Auth = nbi.NewAuthServer(jwtManager)
cpb.RegisterCoreServiceServer(s, northbound.Core)
ppb.RegisterPndServiceServer(s, northbound.Pnd)
apb.RegisterAuthServiceServer(s, northbound.Auth)
go func() {
if err := s.Serve(lis); err != nil {
log.Fatalf("Server exited with error: %v", err)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment