feat: validate personal and enterprise auth tenants
This commit is contained in:
+60
-16
@@ -19,6 +19,10 @@ type testTenantStore struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func ptrInt(v int) *int {
|
||||
return &v
|
||||
}
|
||||
|
||||
type testLoginDeviceStore struct {
|
||||
devices map[types.Uid][]types.DeviceDef
|
||||
updates int
|
||||
@@ -365,9 +369,11 @@ func TestDispatchLogin(t *testing.T) {
|
||||
|
||||
msg := &ClientComMessage{
|
||||
Login: &MsgClientLogin{
|
||||
Id: "123",
|
||||
Scheme: "basic",
|
||||
Secret: []byte(secret),
|
||||
Id: "123",
|
||||
Scheme: "basic",
|
||||
Secret: []byte(secret),
|
||||
LoginType: ptrInt(registrationTypeEnterprise),
|
||||
TenantCode: "test",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -425,7 +431,7 @@ func TestDispatchLoginRejectsAuthenticatorTenantMismatch(t *testing.T) {
|
||||
|
||||
s := &Session{send: make(chan any, 1), ver: 16, tenantID: 1, tenantCode: "acme"}
|
||||
s.login(&ClientComMessage{
|
||||
Login: &MsgClientLogin{Id: "login-1", Scheme: "basic", Secret: secret},
|
||||
Login: &MsgClientLogin{Id: "login-1", Scheme: "basic", Secret: secret, LoginType: ptrInt(registrationTypeEnterprise), TenantCode: "acme"},
|
||||
Timestamp: time.Now(),
|
||||
})
|
||||
|
||||
@@ -438,6 +444,40 @@ func TestDispatchLoginRejectsAuthenticatorTenantMismatch(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatchLoginRejectsEnterpriseDefaultTenant(t *testing.T) {
|
||||
s := &Session{send: make(chan any, 1), ver: 16, tenantID: 1, tenantCode: imDefaultTenantCode}
|
||||
s.login(&ClientComMessage{
|
||||
Login: &MsgClientLogin{Id: "login-1", Scheme: "basic", Secret: []byte("alice:password"), LoginType: ptrInt(registrationTypeEnterprise), TenantCode: imDefaultTenantCode},
|
||||
Timestamp: time.Now(),
|
||||
})
|
||||
|
||||
resp := (<-s.send).(*ServerComMessage)
|
||||
if resp.Ctrl == nil || resp.Ctrl.Code != http.StatusUnprocessableEntity {
|
||||
t.Fatalf("unexpected response: %+v", resp)
|
||||
}
|
||||
params, _ := resp.Ctrl.Params.(map[string]any)
|
||||
if params["reason"] != "TENANT_CODE_FORBIDDEN" {
|
||||
t.Fatalf("unexpected params: %+v", resp.Ctrl.Params)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDispatchLoginRequiresTypeForBasic(t *testing.T) {
|
||||
s := &Session{send: make(chan any, 1), ver: 16, tenantID: 1, tenantCode: imDefaultTenantCode}
|
||||
s.login(&ClientComMessage{
|
||||
Login: &MsgClientLogin{Id: "login-1", Scheme: "basic", Secret: []byte("alice:password")},
|
||||
Timestamp: time.Now(),
|
||||
})
|
||||
|
||||
resp := (<-s.send).(*ServerComMessage)
|
||||
if resp.Ctrl == nil || resp.Ctrl.Code != http.StatusUnprocessableEntity {
|
||||
t.Fatalf("unexpected response: %+v", resp)
|
||||
}
|
||||
params, _ := resp.Ctrl.Params.(map[string]any)
|
||||
if params["reason"] != "LOGIN_TYPE_REQUIRED" {
|
||||
t.Fatalf("unexpected params: %+v", resp.Ctrl.Params)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishSysRequiresRoot(t *testing.T) {
|
||||
s := &Session{
|
||||
send: make(chan any, 1),
|
||||
@@ -1420,12 +1460,14 @@ func TestDispatchAccNew(t *testing.T) {
|
||||
public := "public name"
|
||||
msg := &ClientComMessage{
|
||||
Acc: &MsgClientAcc{
|
||||
Id: "123",
|
||||
User: "newXYZ",
|
||||
Scheme: "basic",
|
||||
Username: "alice",
|
||||
Phone: "13800138000",
|
||||
Secret: []byte(secret),
|
||||
Id: "123",
|
||||
User: "newXYZ",
|
||||
Scheme: "basic",
|
||||
Username: "alice",
|
||||
Phone: "13800138000",
|
||||
RegistrationType: ptrInt(registrationTypeEnterprise),
|
||||
TenantCode: "test",
|
||||
Secret: []byte(secret),
|
||||
Cred: []MsgCredClient{{
|
||||
Method: "tel", Value: "+8613800138000", Response: "AbCdE",
|
||||
Params: map[string]any{"challenge_id": "challenge-1"},
|
||||
@@ -1540,12 +1582,14 @@ func TestDispatchAccNewUsernameOnlyDoesNotRequireInvite(t *testing.T) {
|
||||
|
||||
msg := &ClientComMessage{
|
||||
Acc: &MsgClientAcc{
|
||||
Id: "username-only",
|
||||
User: "new",
|
||||
Scheme: "basic",
|
||||
Username: "alice",
|
||||
Secret: []byte(secret),
|
||||
Desc: &MsgSetDesc{Public: map[string]any{"fn": "Alice"}},
|
||||
Id: "username-only",
|
||||
User: "new",
|
||||
Scheme: "basic",
|
||||
Username: "alice",
|
||||
RegistrationType: ptrInt(registrationTypeEnterprise),
|
||||
TenantCode: "test",
|
||||
Secret: []byte(secret),
|
||||
Desc: &MsgSetDesc{Public: map[string]any{"fn": "Alice"}},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user