2018-07-24 18:26:12 +00:00
|
|
|
package gonextcloud
|
|
|
|
|
|
|
|
import (
|
2018-10-16 10:00:11 +00:00
|
|
|
"fmt"
|
2018-07-24 18:26:12 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-10-26 13:35:50 +00:00
|
|
|
"gitlab.bertha.cloud/partitio/Nextcloud-Partitio/gonextcloud/types"
|
2018-07-24 18:26:12 +00:00
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
"io/ioutil"
|
2018-10-16 10:00:11 +00:00
|
|
|
"math/rand"
|
2018-07-25 13:06:31 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2018-07-24 18:26:12 +00:00
|
|
|
"os"
|
2018-10-16 10:00:11 +00:00
|
|
|
"strconv"
|
2018-10-16 09:02:04 +00:00
|
|
|
"strings"
|
2018-07-24 18:26:12 +00:00
|
|
|
"testing"
|
2018-10-16 10:00:11 +00:00
|
|
|
"time"
|
2018-07-24 18:26:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2018-08-08 14:04:06 +00:00
|
|
|
URL string `yaml:"url"`
|
|
|
|
Login string `yaml:"login"`
|
|
|
|
Password string `yaml:"password"`
|
|
|
|
AppName string `yaml:"app-name"`
|
|
|
|
ShareFolder string `yaml:"share-folder"`
|
|
|
|
NotExistingUser string `yaml:"not-existing-user"`
|
|
|
|
NotExistingGroup string `yaml:"not-existing-group"`
|
2018-10-16 09:02:04 +00:00
|
|
|
Email string `yaml:"email"`
|
2018-07-24 18:26:12 +00:00
|
|
|
}
|
|
|
|
|
2018-10-16 07:34:56 +00:00
|
|
|
const password = "somecomplicatedpassword"
|
2018-07-25 13:06:31 +00:00
|
|
|
|
2018-10-16 07:34:56 +00:00
|
|
|
type test = func(t *testing.T)
|
|
|
|
|
|
|
|
var (
|
|
|
|
config = Config{}
|
|
|
|
c *Client
|
|
|
|
groupID = 37
|
|
|
|
provisionningTests = []struct {
|
|
|
|
string
|
|
|
|
test
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"TestLoadConfig",
|
|
|
|
func(t *testing.T) {
|
|
|
|
err := LoadConfig()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"create client",
|
|
|
|
func(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
c, err = NewClient(config.URL)
|
|
|
|
assert.NoError(t, err, "aie")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"login failed",
|
|
|
|
func(t *testing.T) {
|
|
|
|
err := c.Login("", "")
|
|
|
|
assert.Error(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"login",
|
|
|
|
func(t *testing.T) {
|
|
|
|
err := c.Login(config.Login, config.Password)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"user list",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
us, err := c.Users.List()
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, us, config.Login)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"existing user",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
u, err := c.Users.Get(config.Login)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, u)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"empty user",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
u, err := c.Users.Get("")
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Empty(t, u)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"TestNonExistingUser",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
_, err := c.Users.Get(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"TestUserSearch",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
us, err := c.Users.Search(config.Login)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, us, config.Login)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"TestUserCreate",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.Create(config.NotExistingUser, password, nil)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
//{
|
|
|
|
// "TestUserCreateFull",
|
|
|
|
// func(t *testing.T) {
|
|
|
|
// if err := initClient(); err != nil {
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// username := fmt.Sprintf("%s-2", config.NotExistingUser)
|
2018-10-21 12:53:12 +00:00
|
|
|
// user := &types.Users{
|
2018-10-16 07:34:56 +00:00
|
|
|
// ID: username,
|
|
|
|
// Displayname: strings.ToUpper(username),
|
|
|
|
// Email: "some@address.com",
|
|
|
|
// Address: "Main Street, City",
|
|
|
|
// Twitter: "@me",
|
|
|
|
// Phone: "42 42 242 424",
|
|
|
|
// Website: "my.site.com",
|
|
|
|
// }
|
2018-10-21 12:53:12 +00:00
|
|
|
// err := c.Users.Create(username, password, user)
|
2018-10-16 07:34:56 +00:00
|
|
|
// assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
// u, err := c.Users.Get(username)
|
2018-10-16 07:34:56 +00:00
|
|
|
// assert.NoError(t, err)
|
|
|
|
// o := structs.Map(user)
|
|
|
|
// r := structs.Map(u)
|
|
|
|
// for k := range o {
|
|
|
|
// if ignoredUserField(k) {
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
// assert.Equal(t, o[k], r[k])
|
|
|
|
// }
|
|
|
|
// // Clean up
|
2018-10-21 12:53:12 +00:00
|
|
|
// err = c.Users.Delete(u.ID)
|
2018-10-16 07:34:56 +00:00
|
|
|
// assert.NoError(t, err)
|
|
|
|
// },
|
|
|
|
//},
|
|
|
|
//
|
|
|
|
//{
|
|
|
|
// "TestUserUpdate",
|
|
|
|
// func(t *testing.T) {
|
|
|
|
// if err := initClient(); err != nil {
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// username := fmt.Sprintf("%s-2", config.NotExistingUser)
|
2018-10-21 12:53:12 +00:00
|
|
|
// err := c.Users.Create(username, password, nil)
|
2018-10-16 07:34:56 +00:00
|
|
|
// assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
// user := &types.Users{
|
2018-10-16 07:34:56 +00:00
|
|
|
// ID: username,
|
|
|
|
// Displayname: strings.ToUpper(username),
|
|
|
|
// Email: "some@address.com",
|
|
|
|
// Address: "Main Street, City",
|
|
|
|
// Twitter: "@me",
|
|
|
|
// Phone: "42 42 242 424",
|
|
|
|
// Website: "my.site.com",
|
|
|
|
// }
|
2018-10-21 12:53:12 +00:00
|
|
|
// err = c.Users.Update(user)
|
2018-10-16 07:34:56 +00:00
|
|
|
// assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
// u, err := c.Users.Get(username)
|
2018-10-16 07:34:56 +00:00
|
|
|
// assert.NoError(t, err)
|
|
|
|
// o := structs.Map(user)
|
|
|
|
// r := structs.Map(u)
|
|
|
|
// for k := range o {
|
|
|
|
// if ignoredUserField(k) {
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
// assert.Equal(t, o[k], r[k])
|
|
|
|
// }
|
|
|
|
// // Clean up
|
2018-10-21 12:53:12 +00:00
|
|
|
// err = c.Users.Delete(u.ID)
|
2018-10-16 07:34:56 +00:00
|
|
|
// assert.NoError(t, err)
|
|
|
|
// },
|
|
|
|
//},
|
|
|
|
{
|
|
|
|
"TestUserCreateExisting",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.Create(config.Login, password, nil)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"TestGroupList",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
gs, err := c.Groups.List()
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, gs, "admin")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"TestGroupCreate",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Groups.Create(config.NotExistingGroup)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"TestUserUpdateEmail",
|
|
|
|
func(t *testing.T) {
|
|
|
|
email := "my@mail.com"
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.UpdateEmail(config.NotExistingUser, email)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
u, err := c.Users.Get(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.Equal(t, email, u.Email)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"TestUserUpdateDisplayName",
|
|
|
|
func(t *testing.T) {
|
|
|
|
displayName := "Display Name"
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.UpdateDisplayName(config.NotExistingUser, displayName)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
u, err := c.Users.Get(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.Equal(t, displayName, u.Displayname)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"TestUserUpdatePhone",
|
|
|
|
func(t *testing.T) {
|
|
|
|
phone := "+33 42 42 42 42"
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.UpdatePhone(config.NotExistingUser, phone)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
u, err := c.Users.Get(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.Equal(t, phone, u.Phone)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"TestUserUpdateAddress",
|
|
|
|
func(t *testing.T) {
|
|
|
|
address := "Main Street, Galifrey"
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.UpdateAddress(config.NotExistingUser, address)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
u, err := c.Users.Get(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.Equal(t, address, u.Address)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
"TestUserUpdateWebSite",
|
|
|
|
func(t *testing.T) {
|
|
|
|
website := "www.doctor.who"
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.UpdateWebSite(config.NotExistingUser, website)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
u, err := c.Users.Get(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.Equal(t, website, u.Website)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestUserUpdateTwitter",
|
|
|
|
func(t *testing.T) {
|
|
|
|
twitter := "@doctorwho"
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.UpdateTwitter(config.NotExistingUser, twitter)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
u, err := c.Users.Get(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.Equal(t, twitter, u.Twitter)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestUserUpdateQuota",
|
|
|
|
func(t *testing.T) {
|
|
|
|
quota := 1024 * 1024 * 1024
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.UpdateQuota(config.NotExistingUser, quota)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
// TODO : Find better verification : A never connected Users does not have quota available
|
|
|
|
//u, err := c.Users(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
//assert.NoError(t, err)
|
|
|
|
//assert.Equal(t, quota, u.Quota.Quota)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestUserUpdatePassword",
|
|
|
|
func(t *testing.T) {
|
|
|
|
password := "newcomplexpassword"
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.UpdatePassword(config.NotExistingUser, password)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}},
|
|
|
|
{
|
|
|
|
"TestUserGroupAdd",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.GroupAdd(config.NotExistingUser, config.NotExistingGroup)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
gs, err := c.Users.GroupList(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, gs, config.NotExistingGroup)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestUserGroupSubAdminList",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
gs, err := c.Users.GroupSubAdminList(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Empty(t, gs)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestUserGroupPromote",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.GroupPromote(config.NotExistingUser, config.NotExistingGroup)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
gs, err := c.Users.GroupSubAdminList(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, gs, config.NotExistingGroup)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestUserGroupDemote",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.GroupDemote(config.NotExistingUser, config.NotExistingGroup)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
//gs, err := c.UserGroupSubAdminList(config.NotExistingUser)
|
|
|
|
//assert.NoError(t, err)
|
|
|
|
//assert.Empty(t, gs)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestUserDisable",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.Disable(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
u, err := c.Users.Get(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.False(t, u.Enabled)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestUserEnable",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.Enable(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
u, err := c.Users.Get(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
assert.True(t, u.Enabled)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestGroupDelete",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Groups.Delete(config.NotExistingGroup)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestUserDelete",
|
|
|
|
func(t *testing.T) {
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.Delete(config.NotExistingUser)
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestInvalidBaseRequest",
|
|
|
|
func(t *testing.T) {
|
|
|
|
c.baseURL = &url.URL{}
|
|
|
|
_, err := c.baseRequest(http.MethodGet, routes.capabilities, nil, "admin", "invalid")
|
|
|
|
c = nil
|
|
|
|
assert.Error(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestShareList",
|
|
|
|
func(t *testing.T) {
|
|
|
|
if err := initClient(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
2018-10-21 12:53:12 +00:00
|
|
|
s, err := c.Shares.List()
|
2018-10-16 07:34:56 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, s)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestLogout",
|
|
|
|
func(t *testing.T) {
|
|
|
|
err := c.Logout()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Nil(t, c.session.HTTPClient.Jar)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestLoggedIn",
|
|
|
|
func(t *testing.T) {
|
|
|
|
c := &Client{}
|
|
|
|
c.capabilities = &types.Capabilities{}
|
|
|
|
assert.False(t, c.loggedIn())
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestLoginInvalidURL",
|
|
|
|
func(t *testing.T) {
|
|
|
|
c, _ = NewClient("")
|
|
|
|
err := c.Login("", "")
|
|
|
|
assert.Error(t, err)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"TestBaseRequest",
|
|
|
|
func(t *testing.T) {
|
|
|
|
c, _ = NewClient("")
|
|
|
|
_, err := c.baseRequest(http.MethodGet, routes.capabilities, nil, "admin", "invalid")
|
|
|
|
assert.Error(t, err)
|
|
|
|
},
|
|
|
|
},
|
2018-08-08 14:04:06 +00:00
|
|
|
}
|
2018-10-16 07:34:56 +00:00
|
|
|
)
|
2018-09-03 10:17:02 +00:00
|
|
|
|
2018-10-16 07:34:56 +00:00
|
|
|
func TestClient(t *testing.T) {
|
2018-09-03 10:17:02 +00:00
|
|
|
if err := initClient(); err != nil {
|
2018-10-16 07:34:56 +00:00
|
|
|
t.Fatal(err)
|
2018-09-03 10:17:02 +00:00
|
|
|
}
|
2018-10-16 07:34:56 +00:00
|
|
|
for _, tt := range provisionningTests {
|
|
|
|
t.Run(tt.string, tt.test)
|
2018-09-03 10:17:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-16 09:02:04 +00:00
|
|
|
func TestUserCreateWithoutPassword(t *testing.T) {
|
|
|
|
c = nil
|
|
|
|
if err := initClient(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-10-17 09:15:27 +00:00
|
|
|
if c.version.Major < 14 {
|
|
|
|
t.SkipNow()
|
|
|
|
}
|
2018-10-16 10:00:11 +00:00
|
|
|
// Nextcloud does not seems to like recreating a deleted user
|
2018-10-21 12:53:12 +00:00
|
|
|
err := c.Users.CreateWithoutPassword(config.NotExistingUser, config.Email, strings.Title(config.NotExistingUser))
|
2018-10-16 09:02:04 +00:00
|
|
|
assert.NoError(t, err)
|
2018-10-21 12:53:12 +00:00
|
|
|
err = c.Users.Delete(config.NotExistingUser)
|
2018-10-16 09:02:04 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserListDetails(t *testing.T) {
|
|
|
|
c = nil
|
|
|
|
if err := initClient(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-10-21 12:53:12 +00:00
|
|
|
us, err := c.Users.ListDetails()
|
2018-10-16 09:02:04 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Contains(t, us, config.Login)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGroupListDetails(t *testing.T) {
|
|
|
|
c = nil
|
|
|
|
if err := initClient(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-10-21 12:53:12 +00:00
|
|
|
gs, err := c.Groups.ListDetails()
|
2018-10-16 09:02:04 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEmpty(t, gs)
|
|
|
|
}
|
|
|
|
|
2018-10-16 07:34:56 +00:00
|
|
|
// LoadConfig loads the test configuration
|
|
|
|
func LoadConfig() error {
|
|
|
|
f, err := os.Open("./config.yml")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-09-03 10:17:02 +00:00
|
|
|
}
|
2018-10-16 07:34:56 +00:00
|
|
|
b, err := ioutil.ReadAll(f)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-09-03 10:17:02 +00:00
|
|
|
}
|
2018-10-16 09:52:34 +00:00
|
|
|
if err := yaml.Unmarshal(b, &config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// Override with env variables
|
|
|
|
u := os.Getenv("NEXTCLOUD_URL")
|
|
|
|
if u != "" {
|
|
|
|
config.URL = u
|
|
|
|
}
|
|
|
|
p := os.Getenv("NEXTCLOUD_PASSWORD")
|
|
|
|
if p != "" {
|
|
|
|
config.Password = p
|
|
|
|
}
|
|
|
|
e := os.Getenv("NEXTCLOUD_EMAIL")
|
|
|
|
if e != "" {
|
|
|
|
config.Email = e
|
|
|
|
}
|
2018-10-16 13:24:44 +00:00
|
|
|
config.NotExistingUser = fmt.Sprintf("%s-%s", config.NotExistingUser, strconv.Itoa(rand.Int()))
|
2018-10-16 09:52:34 +00:00
|
|
|
return nil
|
2018-09-03 10:17:02 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 13:06:31 +00:00
|
|
|
func initClient() error {
|
|
|
|
if c == nil {
|
2018-10-16 13:24:44 +00:00
|
|
|
rand.Seed(time.Now().Unix())
|
2018-07-25 13:06:31 +00:00
|
|
|
if err := LoadConfig(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var err error
|
|
|
|
c, err = NewClient(config.URL)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err = c.Login(config.Login, config.Password); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
2018-07-24 18:26:12 +00:00
|
|
|
}
|