mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-21 13:03:09 -06:00
fix rebase, fix docker ldap test
This commit is contained in:
parent
623e55a871
commit
0cf909be67
4
.github/workflows/dendrite.yml
vendored
4
.github/workflows/dendrite.yml
vendored
|
|
@ -93,8 +93,10 @@ jobs:
|
||||||
--health-retries 5
|
--health-retries 5
|
||||||
openldap:
|
openldap:
|
||||||
image: bitnami/openldap:2.5.14
|
image: bitnami/openldap:2.5.14
|
||||||
|
ports:
|
||||||
|
389:1389
|
||||||
volumes:
|
volumes:
|
||||||
- ${{ github.workspace }}/test/openldap:/ldifs
|
- ./test/openldap:/ldifs
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
func TestLdapAuthenticator_Authenticate_DirectBind_AdminUser(t *testing.T) {
|
func TestLdapAuthenticator_Authenticate_DirectBind_AdminUser(t *testing.T) {
|
||||||
authenticator := NewLdapAuthenticator(config.Ldap{
|
authenticator := NewLdapAuthenticator(config.Ldap{
|
||||||
Uri: "ldap://openldap:1389",
|
Uri: "ldap://openldap:389",
|
||||||
BaseDn: "dc=example,dc=org",
|
BaseDn: "dc=example,dc=org",
|
||||||
AdminBindEnabled: false,
|
AdminBindEnabled: false,
|
||||||
UserBindDn: "cn={username},ou=users,dc=example,dc=org",
|
UserBindDn: "cn={username},ou=users,dc=example,dc=org",
|
||||||
|
|
@ -25,7 +25,7 @@ func TestLdapAuthenticator_Authenticate_DirectBind_AdminUser(t *testing.T) {
|
||||||
|
|
||||||
func TestLdapAuthenticator_Authenticate_DirectBind_RegularUser(t *testing.T) {
|
func TestLdapAuthenticator_Authenticate_DirectBind_RegularUser(t *testing.T) {
|
||||||
authenticator := NewLdapAuthenticator(config.Ldap{
|
authenticator := NewLdapAuthenticator(config.Ldap{
|
||||||
Uri: "ldap://openldap:1389",
|
Uri: "ldap://openldap:389",
|
||||||
BaseDn: "dc=example,dc=org",
|
BaseDn: "dc=example,dc=org",
|
||||||
AdminBindEnabled: false,
|
AdminBindEnabled: false,
|
||||||
UserBindDn: "cn={username},ou=users,dc=example,dc=org",
|
UserBindDn: "cn={username},ou=users,dc=example,dc=org",
|
||||||
|
|
@ -42,7 +42,7 @@ func TestLdapAuthenticator_Authenticate_DirectBind_RegularUser(t *testing.T) {
|
||||||
|
|
||||||
func TestLdapAuthenticator_Authenticate_AdminBind(t *testing.T) {
|
func TestLdapAuthenticator_Authenticate_AdminBind(t *testing.T) {
|
||||||
authenticator := NewLdapAuthenticator(config.Ldap{
|
authenticator := NewLdapAuthenticator(config.Ldap{
|
||||||
Uri: "ldap://openldap:1389",
|
Uri: "ldap://openldap:389",
|
||||||
BaseDn: "dc=example,dc=org",
|
BaseDn: "dc=example,dc=org",
|
||||||
AdminBindEnabled: true,
|
AdminBindEnabled: true,
|
||||||
AdminBindDn: "cn=admin,dc=example,dc=org",
|
AdminBindDn: "cn=admin,dc=example,dc=org",
|
||||||
|
|
@ -63,7 +63,7 @@ func TestLdapAuthenticator_Authenticate_AdminBind(t *testing.T) {
|
||||||
|
|
||||||
func TestLdapAuthenticator_Authenticate_AdminBind_UserNotFound(t *testing.T) {
|
func TestLdapAuthenticator_Authenticate_AdminBind_UserNotFound(t *testing.T) {
|
||||||
authenticator := NewLdapAuthenticator(config.Ldap{
|
authenticator := NewLdapAuthenticator(config.Ldap{
|
||||||
Uri: "ldap://openldap:1389",
|
Uri: "ldap://openldap:389",
|
||||||
BaseDn: "dc=example,dc=org",
|
BaseDn: "dc=example,dc=org",
|
||||||
AdminBindEnabled: true,
|
AdminBindEnabled: true,
|
||||||
AdminBindDn: "cn=admin,dc=example,dc=org",
|
AdminBindDn: "cn=admin,dc=example,dc=org",
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ import (
|
||||||
// called after authorization has completed, with the result of the authorization.
|
// called after authorization has completed, with the result of the authorization.
|
||||||
// If the final return value is non-nil, an error occurred and the cleanup function
|
// If the final return value is non-nil, an error occurred and the cleanup function
|
||||||
// is nil.
|
// is nil.
|
||||||
func LoginFromJSONReader(ctx context.Context, r io.Reader, useraccountAPI uapi.UserLoginAPI, userAPI UserInternalAPIForLogin, cfg *config.ClientAPI) (*Login, LoginCleanupFunc, *util.JSONResponse) {
|
func LoginFromJSONReader(ctx context.Context, r io.Reader, userAPI UserInternalAPIForLogin, cfg *config.ClientAPI) (*Login, LoginCleanupFunc, *util.JSONResponse) {
|
||||||
reqBytes, err := io.ReadAll(r)
|
reqBytes, err := io.ReadAll(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := &util.JSONResponse{
|
err := &util.JSONResponse{
|
||||||
|
|
@ -57,7 +57,7 @@ func LoginFromJSONReader(ctx context.Context, r io.Reader, useraccountAPI uapi.U
|
||||||
switch header.Type {
|
switch header.Type {
|
||||||
case authtypes.LoginTypePassword:
|
case authtypes.LoginTypePassword:
|
||||||
typ = &LoginTypePassword{
|
typ = &LoginTypePassword{
|
||||||
UserAPI: useraccountAPI,
|
UserAPI: userAPI,
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
}
|
}
|
||||||
case authtypes.LoginTypeToken:
|
case authtypes.LoginTypeToken:
|
||||||
|
|
@ -79,4 +79,5 @@ func LoginFromJSONReader(ctx context.Context, r io.Reader, useraccountAPI uapi.U
|
||||||
// UserInternalAPIForLogin contains the aspects of UserAPI required for logging in.
|
// UserInternalAPIForLogin contains the aspects of UserAPI required for logging in.
|
||||||
type UserInternalAPIForLogin interface {
|
type UserInternalAPIForLogin interface {
|
||||||
uapi.LoginTokenInternalAPI
|
uapi.LoginTokenInternalAPI
|
||||||
|
uapi.UserLoginAPI
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ func TestLoginFromJSONReader(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
login, cleanup, err := LoginFromJSONReader(ctx, strings.NewReader(tst.Body), &userAPI, &userAPI, cfg)
|
login, cleanup, err := LoginFromJSONReader(ctx, strings.NewReader(tst.Body), &userAPI, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("LoginFromJSONReader failed: %+v", err)
|
t.Fatalf("LoginFromJSONReader failed: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -153,7 +153,7 @@ func TestBadLoginFromJSONReader(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, cleanup, errRes := LoginFromJSONReader(ctx, strings.NewReader(tst.Body), &userAPI, &userAPI, cfg)
|
_, cleanup, errRes := LoginFromJSONReader(ctx, strings.NewReader(tst.Body), &userAPI, cfg)
|
||||||
if errRes == nil {
|
if errRes == nil {
|
||||||
cleanup(ctx, nil)
|
cleanup(ctx, nil)
|
||||||
t.Fatalf("LoginFromJSONReader err: got %+v, want code %q", errRes, tst.WantErrCode)
|
t.Fatalf("LoginFromJSONReader err: got %+v, want code %q", errRes, tst.WantErrCode)
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@ var (
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
serverName = gomatrixserverlib.ServerName("example.com")
|
serverName = gomatrixserverlib.ServerName("example.com")
|
||||||
// space separated localpart+password -> account
|
// space separated localpart+password -> account
|
||||||
lookup = make(map[string]*api.Account)
|
lookup = make(map[string]*api.Account)
|
||||||
device = &api.Device{
|
accounts = make(map[string]*api.Account)
|
||||||
|
device = &api.Device{
|
||||||
AccessToken: "flibble",
|
AccessToken: "flibble",
|
||||||
DisplayName: "My Device",
|
DisplayName: "My Device",
|
||||||
ID: "device_id_goes_here",
|
ID: "device_id_goes_here",
|
||||||
|
|
@ -26,6 +27,26 @@ var (
|
||||||
|
|
||||||
type fakeAccountDatabase struct{}
|
type fakeAccountDatabase struct{}
|
||||||
|
|
||||||
|
func (d *fakeAccountDatabase) QueryAccountByLocalpart(ctx context.Context, req *api.QueryAccountByLocalpartRequest, res *api.QueryAccountByLocalpartResponse) error {
|
||||||
|
acc, ok := lookup[req.Localpart]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unknown user/password")
|
||||||
|
}
|
||||||
|
res.Account = acc
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *fakeAccountDatabase) PerformAccountCreation(ctx context.Context, req *api.PerformAccountCreationRequest, res *api.PerformAccountCreationResponse) error {
|
||||||
|
accounts[req.Localpart] = &api.Account{
|
||||||
|
UserID: req.Localpart,
|
||||||
|
Localpart: req.Localpart,
|
||||||
|
ServerName: serverName,
|
||||||
|
AppServiceID: "ldap",
|
||||||
|
AccountType: 0,
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *fakeAccountDatabase) PerformPasswordUpdate(ctx context.Context, req *api.PerformPasswordUpdateRequest, res *api.PerformPasswordUpdateResponse) error {
|
func (d *fakeAccountDatabase) PerformPasswordUpdate(ctx context.Context, req *api.PerformPasswordUpdateRequest, res *api.PerformPasswordUpdateResponse) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
dn: dc=example,dc=org
|
dn: dc=example,dc=org
|
||||||
objectClass: dcObject
|
objectClass: dcObject
|
||||||
objectClass: organizationalUnit
|
objectClass: organization
|
||||||
|
o: Example, Inc
|
||||||
|
|
||||||
# administrator
|
# administrator
|
||||||
dn: cn=admin,dc=example,dc=org
|
dn: cn=admin,dc=example,dc=org
|
||||||
|
|
@ -31,7 +32,7 @@ cn: user1
|
||||||
sn: 10
|
sn: 10
|
||||||
displayName: user1
|
displayName: user1
|
||||||
description: user1
|
description: user1
|
||||||
userPassword: user1
|
userPassword: password
|
||||||
mail: user1@example.com
|
mail: user1@example.com
|
||||||
|
|
||||||
# regular user
|
# regular user
|
||||||
|
|
@ -48,7 +49,7 @@ cn: user2
|
||||||
sn: 11
|
sn: 11
|
||||||
displayName: user2
|
displayName: user2
|
||||||
description: user2
|
description: user2
|
||||||
userPassword: user2
|
userPassword: password
|
||||||
mail: user2@example.com
|
mail: user2@example.com
|
||||||
|
|
||||||
# Subtree for Groups
|
# Subtree for Groups
|
||||||
|
|
@ -65,4 +66,4 @@ objectClass: top
|
||||||
gidNumber: 1
|
gidNumber: 1
|
||||||
cn: admin
|
cn: admin
|
||||||
description: admin
|
description: admin
|
||||||
memberUid: user1
|
memberUid: user1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue