Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
goSDN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
goSDN
Commits
5528a68e
Commit
5528a68e
authored
3 years ago
by
Fabian Seidl
Browse files
Options
Downloads
Patches
Plain Diff
added test for api/login
parent
b7271496
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
controller/api/auth_test.go
+88
-0
88 additions, 0 deletions
controller/api/auth_test.go
controller/api/initialise_test.go
+8
-0
8 additions, 0 deletions
controller/api/initialise_test.go
with
96 additions
and
0 deletions
controller/api/auth_test.go
0 → 100644
+
88
−
0
View file @
5528a68e
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
)
}
})
}
}
This diff is collapsed.
Click to expand it.
controller/api/initialise_test.go
+
8
−
0
View file @
5528a68e
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
cpb
"code.fbi.h-da.de/danet/gosdn/api/go/gosdn/core"
cpb
"code.fbi.h-da.de/danet/gosdn/api/go/gosdn/core"
ppb
"code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
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"
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/config"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/device"
...
@@ -132,9 +133,16 @@ func bootstrapUnitTest() {
...
@@ -132,9 +133,16 @@ func bootstrapUnitTest() {
if
err
:=
pndStore
.
Add
(
&
mockPnd
);
err
!=
nil
{
if
err
:=
pndStore
.
Add
(
&
mockPnd
);
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
jwtManager
:=
rbacImpl
.
NewJWTManager
(
""
,
(
10000
*
time
.
Hour
))
northbound
:=
nbi
.
NewNBI
(
pndStore
,
userService
,
roleService
)
northbound
:=
nbi
.
NewNBI
(
pndStore
,
userService
,
roleService
)
northbound
.
Auth
=
nbi
.
NewAuthServer
(
jwtManager
)
cpb
.
RegisterCoreServiceServer
(
s
,
northbound
.
Core
)
cpb
.
RegisterCoreServiceServer
(
s
,
northbound
.
Core
)
ppb
.
RegisterPndServiceServer
(
s
,
northbound
.
Pnd
)
ppb
.
RegisterPndServiceServer
(
s
,
northbound
.
Pnd
)
apb
.
RegisterAuthServiceServer
(
s
,
northbound
.
Auth
)
go
func
()
{
go
func
()
{
if
err
:=
s
.
Serve
(
lis
);
err
!=
nil
{
if
err
:=
s
.
Serve
(
lis
);
err
!=
nil
{
log
.
Fatalf
(
"Server exited with error: %v"
,
err
)
log
.
Fatalf
(
"Server exited with error: %v"
,
err
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment