fix: use personal login for default IM tenant
Deploy olons-server production / deploy (push) Successful in 2m48s
Deploy olons-server production / deploy (push) Successful in 2m48s
This commit is contained in:
@@ -25,6 +25,8 @@ import (
|
|||||||
|
|
||||||
const maxResponseBody = 2 << 20
|
const maxResponseBody = 2 << 20
|
||||||
|
|
||||||
|
const defaultIMTenantCode = "default"
|
||||||
|
|
||||||
type Error struct {
|
type Error struct {
|
||||||
Status int
|
Status int
|
||||||
Code int
|
Code int
|
||||||
@@ -181,9 +183,13 @@ func (c *Client) LoginBasic(ctx context.Context, username, password, deviceID, p
|
|||||||
}
|
}
|
||||||
loginID := "login-" + requestID()
|
loginID := "login-" + requestID()
|
||||||
secret := base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
|
secret := base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
|
||||||
|
loginType := 0
|
||||||
|
if strings.EqualFold(strings.TrimSpace(c.cfg.TenantCode), defaultIMTenantCode) {
|
||||||
|
loginType = 1
|
||||||
|
}
|
||||||
if err = conn.WriteJSON(map[string]any{"login": map[string]any{
|
if err = conn.WriteJSON(map[string]any{"login": map[string]any{
|
||||||
"id": loginID, "scheme": "basic", "secret": secret,
|
"id": loginID, "scheme": "basic", "secret": secret,
|
||||||
"login_type": 0, "tenant_code": c.cfg.TenantCode,
|
"login_type": loginType, "tenant_code": c.cfg.TenantCode,
|
||||||
}}); err != nil {
|
}}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,39 @@ func TestLoginBasicUsesExistingWebSocketProtocol(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoginBasicUsesPersonalTypeForDefaultTenant(t *testing.T) {
|
||||||
|
upgrader := websocket.Upgrader{}
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
conn, err := upgrader.Upgrade(w, r, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
var packet map[string]map[string]any
|
||||||
|
if err = conn.ReadJSON(&packet); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_ = conn.WriteJSON(map[string]any{"ctrl": map[string]any{"id": packet["hi"]["id"], "code": 201, "text": "created"}})
|
||||||
|
if err = conn.ReadJSON(&packet); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
login := packet["login"]
|
||||||
|
if login["login_type"] != float64(1) || login["tenant_code"] != defaultIMTenantCode {
|
||||||
|
t.Fatalf("unexpected login: %#v", login)
|
||||||
|
}
|
||||||
|
_ = conn.WriteJSON(map[string]any{"ctrl": map[string]any{"id": login["id"], "code": 200, "text": "ok",
|
||||||
|
"params": map[string]any{"user": "usr_member", "token": "token", "expires": "2026-10-27T10:00:00Z"}}})
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
client := New(config.IMConfig{BaseURL: server.URL, HTTPAPIURL: server.URL,
|
||||||
|
WebSocketURL: "ws" + strings.TrimPrefix(server.URL, "http"), TenantCode: defaultIMTenantCode,
|
||||||
|
APIKey: "public-key", InternalService: "olons-server", InternalSecret: "secret", Timeout: time.Second})
|
||||||
|
if _, err := client.LoginBasic(context.Background(), "member01", "password", "web-1", "web"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestResetPasswordSendsBase64BcryptHash(t *testing.T) {
|
func TestResetPasswordSendsBase64BcryptHash(t *testing.T) {
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
var body struct {
|
var body struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user