mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
Fix: systemInfoService is nil
Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
@@ -129,9 +129,10 @@ func (a *authenticationServiceImpl) newDexHandler(ctx context.Context, req apisv
|
||||
return nil, err
|
||||
}
|
||||
return &dexHandlerImpl{
|
||||
idToken: idToken,
|
||||
Store: a.Store,
|
||||
projectService: a.ProjectService,
|
||||
idToken: idToken,
|
||||
Store: a.Store,
|
||||
projectService: a.ProjectService,
|
||||
systemInfoService: a.SystemInfoService,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -477,6 +478,7 @@ func (d *dexHandlerImpl) login(ctx context.Context) (*apisv1.UserBase, error) {
|
||||
if len(users) > 0 {
|
||||
u := users[0].(*model.User)
|
||||
u.LastLoginTime = time.Now()
|
||||
u.DexSub = claims.Sub
|
||||
if err := d.Store.Put(ctx, u); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -490,6 +492,7 @@ func (d *dexHandlerImpl) login(ctx context.Context) (*apisv1.UserBase, error) {
|
||||
LastLoginTime: time.Now(),
|
||||
}
|
||||
if err := d.Store.Add(ctx, user); err != nil {
|
||||
log.Logger.Errorf("failed to save the user from the dex: %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
systemInfo, err := d.systemInfoService.GetSystemInfo(ctx)
|
||||
|
||||
@@ -19,6 +19,7 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"reflect"
|
||||
"strconv"
|
||||
@@ -64,8 +65,9 @@ var _ = Describe("Test authentication service functions", func() {
|
||||
})
|
||||
It("Test Dex login", func() {
|
||||
testIDToken := &oidc.IDToken{}
|
||||
sub := "248289761001"
|
||||
patch := ApplyMethod(reflect.TypeOf(testIDToken), "Claims", func(_ *oidc.IDToken, v interface{}) error {
|
||||
return json.Unmarshal([]byte(`{"email":"test@test.com", "name":"show name", "sub": "testuser"}`), v)
|
||||
return json.Unmarshal([]byte(fmt.Sprintf(`{"email":"test@test.com", "name":"show name", "sub": "%s"}`, sub)), v)
|
||||
})
|
||||
defer patch.Reset()
|
||||
|
||||
@@ -94,22 +96,22 @@ var _ = Describe("Test authentication service functions", func() {
|
||||
resp, err := dexHandler.login(context.Background())
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(resp.Email).Should(Equal("test@test.com"))
|
||||
Expect(resp.Name).Should(Equal("testuser"))
|
||||
Expect(resp.Name).Should(Equal(sub))
|
||||
Expect(resp.Alias).Should(Equal("show name"))
|
||||
|
||||
projects, err := projectService.ListUserProjects(context.TODO(), "testuser")
|
||||
projects, err := projectService.ListUserProjects(context.TODO(), sub)
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(len(projects)).Should(Equal(1))
|
||||
|
||||
user := &model.User{
|
||||
Name: "testuser",
|
||||
Name: sub,
|
||||
}
|
||||
err = ds.Get(context.Background(), user)
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(user.Email).Should(Equal("test@test.com"))
|
||||
|
||||
existUser := &model.User{
|
||||
Name: "testuser",
|
||||
Name: sub,
|
||||
}
|
||||
err = ds.Delete(context.Background(), existUser)
|
||||
Expect(err).Should(BeNil())
|
||||
@@ -131,7 +133,7 @@ var _ = Describe("Test authentication service functions", func() {
|
||||
existUser = &model.User{
|
||||
Name: "zhangsan",
|
||||
Email: "test2@test.com",
|
||||
DexSub: "testuser",
|
||||
DexSub: sub,
|
||||
}
|
||||
err = ds.Add(context.Background(), existUser)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
@@ -82,8 +82,13 @@ func (v *velaQLServiceImpl) QueryView(ctx context.Context, velaQL string) (*apis
|
||||
return nil, bcode.ErrParseQuery2Json
|
||||
}
|
||||
if strings.Contains(velaQL, "collect-logs") {
|
||||
enc, _ := base64.StdEncoding.DecodeString(resp["logs"].(string))
|
||||
resp["logs"] = string(enc)
|
||||
logs, ok := resp["logs"].(string)
|
||||
if ok {
|
||||
enc, _ := base64.StdEncoding.DecodeString(logs)
|
||||
resp["logs"] = string(enc)
|
||||
} else {
|
||||
resp["logs"] = ""
|
||||
}
|
||||
}
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user