mirror of
https://github.com/pushbits/server.git
synced 2025-06-03 03:02:14 +02:00
add test for getUser & add readme
This commit is contained in:
parent
46dd19b07d
commit
e6f24c4458
6 changed files with 114 additions and 21 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue