Skip to content
Snippets Groups Projects

Add basic application framework and example application to show interaction between events an NBI

Merged Ghost User requested to merge istaester/init-application-framework into develop
3 files
+ 114
155
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -58,19 +58,24 @@ func dialer(interceptorServer *AuthInterceptor, userServer *User, roleServer *Ro
}
func TestAuthInterceptor_Unary(t *testing.T) {
a, u, r, s := getTestAuthInterceptorServer(t)
validToken, err := createTestUserToken("testAdmin", true, a.userService, a.jwtManager)
authServer, userServer, roleServer, sbiServer := getTestAuthInterceptorServer(t)
validToken, err := createTestUserToken("testAdmin", true, authServer.userService, authServer.jwtManager)
if err != nil {
t.Fatal(err)
}
wrongUserToken, err := createTestUserToken("foo", false, a.userService, a.jwtManager)
wrongUserToken, err := createTestUserToken("foo", false, authServer.userService, authServer.jwtManager)
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
conn, err := grpc.DialContext(ctx, "", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(dialer(a, u, r, s)))
conn, err := grpc.DialContext(
ctx,
"",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(dialer(authServer, userServer, roleServer, sbiServer)),
)
if err != nil {
t.Fatal(err)
}
@@ -145,14 +150,19 @@ func TestAuthInterceptor_Unary(t *testing.T) {
}
func TestAuthInterceptor_Stream(t *testing.T) {
a, u, r, s := getTestAuthInterceptorServer(t)
validToken, err := createTestUserToken("testAdmin", true, a.userService, a.jwtManager)
authServer, userServer, roleServer, sbiServer := getTestAuthInterceptorServer(t)
validToken, err := createTestUserToken("testAdmin", true, authServer.userService, authServer.jwtManager)
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
conn, err := grpc.DialContext(ctx, "", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(dialer(a, u, r, s)))
conn, err := grpc.DialContext(
ctx,
"",
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithContextDialer(dialer(authServer, userServer, roleServer, sbiServer)),
)
if err != nil {
t.Fatal(err)
}
@@ -211,13 +221,13 @@ func TestAuthInterceptor_Stream(t *testing.T) {
}
func TestAuthInterceptor_authorize(t *testing.T) {
a, _, _, _ := getTestAuthInterceptorServer(t)
validToken, err := createTestUserToken("testAdmin", true, a.userService, a.jwtManager)
authServer, _, _, _ := getTestAuthInterceptorServer(t)
validToken, err := createTestUserToken("testAdmin", true, authServer.userService, authServer.jwtManager)
if err != nil {
t.Fatal(err)
}
wrongUserToken, err := createTestUserToken("foo", false, a.userService, a.jwtManager)
wrongUserToken, err := createTestUserToken("foo", false, authServer.userService, authServer.jwtManager)
if err != nil {
t.Fatal(err)
}
@@ -258,7 +268,7 @@ func TestAuthInterceptor_authorize(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := a.authorize(tt.args.ctx, tt.args.method); (err != nil) != tt.wantErr {
if err := authServer.authorize(tt.args.ctx, tt.args.method); (err != nil) != tt.wantErr {
t.Errorf("AuthInterceptor.authorize() error = %v, wantErr %v", err, tt.wantErr)
}
})
Loading