add test for getUser & add readme

This commit is contained in:
Cubicroot 2021-06-19 16:59:30 +02:00
parent 46dd19b07d
commit e6f24c4458
6 changed files with 114 additions and 21 deletions

View file

@ -8,8 +8,8 @@ import (
)
// GetEmptyDatabase returns an empty sqlite database object
func GetEmptyDatabase() (*database.Database, error) {
cm := credentials.CreateManager(false, configuration.CryptoConfig{})
func GetEmptyDatabase(confCrypto configuration.CryptoConfig) (*database.Database, error) {
cm := credentials.CreateManager(false, confCrypto)
return database.Create(cm, "sqlite3", "pushbits-test.db")
}
@ -24,3 +24,29 @@ func AddApplicationsToDb(db *database.Database, apps []*model.Application) error
return nil
}
// AddUsersToDb adds the users to the database and sets their username as a password, returns list of added users
func AddUsersToDb(db *database.Database, users []*model.User) ([]*model.User, error) {
addedUsers := make([]*model.User, 0)
for _, user := range users {
extUser := model.ExternalUser{
ID: user.ID,
Name: user.Name,
IsAdmin: user.IsAdmin,
MatrixID: user.MatrixID,
}
credentials := model.UserCredentials{
Password: user.Name,
}
createUser := model.CreateUser{ExternalUser: extUser, UserCredentials: credentials}
newUser, err := db.CreateUser(createUser)
addedUsers = append(addedUsers, newUser)
if err != nil {
return nil, err
}
}
return addedUsers, nil
}

View file

@ -6,8 +6,8 @@ import (
)
// GetMatrixDispatcher creates and returns a matrix dispatcher
func GetMatrixDispatcher(homeserver, username, password string) (*dispatcher.Dispatcher, error) {
db, err := GetEmptyDatabase()
func GetMatrixDispatcher(homeserver, username, password string, confCrypto configuration.CryptoConfig) (*dispatcher.Dispatcher, error) {
db, err := GetEmptyDatabase(confCrypto)
if err != nil {
return nil, err