Added User related tests

This commit is contained in:
Philippe-Adrien Nousse 2018-07-24 20:26:12 +02:00
parent d338b0c67a
commit 40718cb98c
12 changed files with 478 additions and 82 deletions

View File

@ -1 +1,35 @@
package client package client
import (
req "github.com/levigross/grequests"
"github.com/partitio/gonextcloud/client/types"
)
func (c *Client) AppList() ([]string, error) {
if !c.loggedIn() {
return nil, unauthorized
}
u := c.baseURL.ResolveReference(routes.apps)
res, err := c.session.Get(u.String(), nil)
if err != nil {
return nil, err
}
var r types.AppListResponse
res.JSON(&r)
return r.Ocs.Data.Apps, nil
return nil, nil
}
func (c *Client) appsBaseRequest(name string, route string, ro *req.RequestOptions, method string) error {
res, err := c.baseRequest(routes.apps, name, route, ro, method)
if err != nil {
return err
}
var r types.UserResponse
res.JSON(&r)
if r.Ocs.Meta.Statuscode != 100 {
e := types.ErrorFromMeta(r.Ocs.Meta)
return &e
}
return nil
}

View File

@ -18,16 +18,22 @@ func (c *Client) Login(username string, password string) error {
c.session = req.NewSession(&options) c.session = req.NewSession(&options)
// TODO What to do with capabilities ? (other thant connection validation) // TODO What to do with capabilities ? (other thant connection validation)
u := c.baseURL.ResolveReference(routes.capabilities) u := c.baseURL.ResolveReference(routes.capabilities)
r, err := c.session.Get(u.String(), nil) res, err := c.session.Get(u.String(), nil)
if err != nil { if err != nil {
return err return err
} }
var cs types.CapabilitiesResponse var r types.CapabilitiesResponse
r.JSON(&cs) res.JSON(&r)
if cs.Ocs.Meta.Statuscode != 100 { if r.Ocs.Meta.Statuscode != 100 {
return fmt.Errorf("%d : %s", cs.Ocs.Meta.Statuscode, cs.Ocs.Meta.Message) e := types.ErrorFromMeta(r.Ocs.Meta)
return &e
}
c.capabilities = &r.Ocs.Data.Capabilities
// Check if authentication failed
if !c.loggedIn() {
e := types.APIError{Message: "authentication failed"}
return &e
} }
c.capabilities = &cs.Ocs.Data.Capabilities
return nil return nil
} }
@ -37,5 +43,6 @@ func (c *Client) Logout() error {
} }
func (c *Client) loggedIn() bool { func (c *Client) loggedIn() bool {
return c.capabilities != nil // When authentication failed, capabilities doesn't contains core information
return c.capabilities.Core.WebdavRoot != ""
} }

View File

@ -1,7 +1,6 @@
package client package client
import ( import (
"fmt"
req "github.com/levigross/grequests" req "github.com/levigross/grequests"
"github.com/partitio/gonextcloud/client/types" "github.com/partitio/gonextcloud/client/types"
"net/http" "net/http"
@ -12,12 +11,13 @@ func (c *Client) GroupList() ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var gr types.GroupListResponse var r types.GroupListResponse
res.JSON(&gr) res.JSON(&r)
if gr.Ocs.Meta.Statuscode != 100 { if r.Ocs.Meta.Statuscode != 100 {
return nil, fmt.Errorf("%d : %s", gr.Ocs.Meta.Statuscode, gr.Ocs.Meta.Message) e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &e
} }
return gr.Ocs.Data.Groups, nil return r.Ocs.Data.Groups, nil
} }
func (c *Client) GroupUsers(name string) ([]string, error) { func (c *Client) GroupUsers(name string) ([]string, error) {
@ -28,7 +28,8 @@ func (c *Client) GroupUsers(name string) ([]string, error) {
var r types.UserListResponse var r types.UserListResponse
res.JSON(&r) res.JSON(&r)
if r.Ocs.Meta.Statuscode != 100 { if r.Ocs.Meta.Statuscode != 100 {
return nil, fmt.Errorf("%d : %s", r.Ocs.Meta.Statuscode, r.Ocs.Meta.Message) e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &e
} }
return r.Ocs.Data.Users, nil return r.Ocs.Data.Users, nil
} }
@ -44,7 +45,8 @@ func (c *Client) GroupSearch(search string) ([]string, error) {
var r types.GroupListResponse var r types.GroupListResponse
res.JSON(&r) res.JSON(&r)
if r.Ocs.Meta.Statuscode != 100 { if r.Ocs.Meta.Statuscode != 100 {
return nil, fmt.Errorf("%d : %s", r.Ocs.Meta.Statuscode, r.Ocs.Meta.Message) e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &e
} }
return r.Ocs.Data.Groups, nil return r.Ocs.Data.Groups, nil
} }
@ -76,7 +78,8 @@ func (c *Client) GroupSubAdminList(name string) ([]string, error) {
var r types.UserListResponse var r types.UserListResponse
res.JSON(&r) res.JSON(&r)
if r.Ocs.Meta.Statuscode != 100 { if r.Ocs.Meta.Statuscode != 100 {
return nil, fmt.Errorf("%d : %s", r.Ocs.Meta.Statuscode, r.Ocs.Meta.Message) e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &e
} }
return r.Ocs.Data.Users, nil return r.Ocs.Data.Users, nil
} }
@ -86,10 +89,11 @@ func (c *Client) groupBaseRequest(name string, route string, ro *req.RequestOpti
if err != nil { if err != nil {
return err return err
} }
var ur types.GroupListResponse var r types.GroupListResponse
res.JSON(&ur) res.JSON(&r)
if ur.Ocs.Meta.Statuscode != 100 { if r.Ocs.Meta.Statuscode != 100 {
return fmt.Errorf("%d : %s", ur.Ocs.Meta.Statuscode, ur.Ocs.Meta.Message) e := types.ErrorFromMeta(r.Ocs.Meta)
return &e
} }
return nil return nil
} }

View File

@ -38,4 +38,9 @@ type BaseClient interface {
GroupCreate(name string) error GroupCreate(name string) error
GroupDelete(name string) error GroupDelete(name string) error
GroupSubAdminList(name string) ([]string, error) GroupSubAdminList(name string) ([]string, error)
AppList() ([]string, error)
App(name string) (types.App, error)
AppEnable(name string) error
AppDisable(name string) error
} }

View File

@ -6,14 +6,17 @@ type Routes struct {
capabilities *url.URL capabilities *url.URL
users *url.URL users *url.URL
groups *url.URL groups *url.URL
apps *url.URL
} }
const badRequest = 998
var ( var (
apiPath = &url.URL{Path: "/ocs/v1.php/cloud"} apiPath = &url.URL{Path: "/ocs/v1.php/cloud"}
routes = Routes{ routes = Routes{
capabilities: &url.URL{Path: apiPath.Path + "/capabilities"}, capabilities: &url.URL{Path: apiPath.Path + "/capabilities"},
users: &url.URL{Path: apiPath.Path + "/users"}, users: &url.URL{Path: apiPath.Path + "/users"},
groups: &url.URL{Path: apiPath.Path + "/groups"}, groups: &url.URL{Path: apiPath.Path + "/groups"},
apps: &url.URL{Path: apiPath.Path + "/apps"},
} }
badRequest = 998
) )

67
client/types/app.go Normal file
View File

@ -0,0 +1,67 @@
package types
type App struct {
ID string `json:"id"`
Ocsid string `json:"ocsid"`
Name string `json:"name"`
Summary string `json:"summary"`
Description string `json:"description"`
Licence string `json:"licence"`
Author string `json:"author"`
Version string `json:"version"`
Namespace string `json:"namespace"`
Types []string `json:"types"`
Documentation struct {
Admin string `json:"admin"`
Developer string `json:"developer"`
User string `json:"user"`
} `json:"documentation"`
Category []string `json:"category"`
Website string `json:"website"`
Bugs string `json:"bugs"`
Repository struct {
Attributes struct {
Type string `json:"type"`
} `json:"@attributes"`
Value string `json:"@value"`
} `json:"repository"`
Screenshot []interface{} `json:"screenshot"`
Dependencies struct {
Owncloud struct {
Attributes struct {
MinVersion string `json:"min-version"`
MaxVersion string `json:"max-version"`
} `json:"@attributes"`
} `json:"owncloud"`
Nextcloud struct {
Attributes struct {
MinVersion string `json:"min-version"`
MaxVersion string `json:"max-version"`
} `json:"@attributes"`
} `json:"nextcloud"`
} `json:"dependencies"`
Settings struct {
Admin []string `json:"admin"`
AdminSection []string `json:"admin-section"`
Personal []interface{} `json:"personal"`
PersonalSection []interface{} `json:"personal-section"`
} `json:"settings"`
Info []interface{} `json:"info"`
Remote []interface{} `json:"remote"`
Public []interface{} `json:"public"`
RepairSteps struct {
Install []interface{} `json:"install"`
PreMigration []interface{} `json:"pre-migration"`
PostMigration []interface{} `json:"post-migration"`
LiveMigration []interface{} `json:"live-migration"`
Uninstall []interface{} `json:"uninstall"`
} `json:"repair-steps"`
BackgroundJobs []interface{} `json:"background-jobs"`
TwoFactorProviders []interface{} `json:"two-factor-providers"`
Commands []interface{} `json:"commands"`
Activity struct {
Filters []interface{} `json:"filters"`
Settings []interface{} `json:"settings"`
Providers []interface{} `json:"providers"`
} `json:"activity"`
}

19
client/types/errors.go Normal file
View File

@ -0,0 +1,19 @@
package types
import "fmt"
type APIError struct {
Code int
Message string
}
func ErrorFromMeta(meta Meta) APIError {
return APIError{
meta.Statuscode,
meta.Message,
}
}
func (e *APIError) Error() string {
return fmt.Sprintf("%d : %s", e.Code, e.Message)
}

View File

@ -1,27 +1,23 @@
package types package types
type Meta struct {
Status string `json:"status"`
Statuscode int `json:"statuscode"`
Message string `json:"message"`
Totalitems string `json:"totalitems"`
Itemsperpage string `json:"itemsperpage"`
}
type ErrorResponse struct { type ErrorResponse struct {
Ocs struct { Ocs struct {
Meta struct { Meta Meta `json:"meta"`
Status string `json:"status"`
Statuscode int `json:"statuscode"`
Message string `json:"message"`
Totalitems string `json:"totalitems"`
Itemsperpage string `json:"itemsperpage"`
} `json:"meta"`
Data []interface{} `json:"data"` Data []interface{} `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type UserListResponse struct { type UserListResponse struct {
Ocs struct { Ocs struct {
Meta struct { Meta Meta `json:"meta"`
Status string `json:"status"`
Statuscode int `json:"statuscode"`
Message string `json:"message"`
Totalitems string `json:"totalitems"`
Itemsperpage string `json:"itemsperpage"`
} `json:"meta"`
Data struct { Data struct {
Users []string `json:"users"` Users []string `json:"users"`
} `json:"data"` } `json:"data"`
@ -30,54 +26,46 @@ type UserListResponse struct {
type UserResponse struct { type UserResponse struct {
Ocs struct { Ocs struct {
Meta struct { Meta Meta `json:"meta"`
Status string `json:"status"`
Statuscode int `json:"statuscode"`
Message string `json:"message"`
Totalitems string `json:"totalitems"`
Itemsperpage string `json:"itemsperpage"`
} `json:"meta"`
Data User `json:"data"` Data User `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type BaseResponse struct { type BaseResponse struct {
Ocs struct { Ocs struct {
Meta struct { Meta Meta `json:"meta"`
Status string `json:"status"`
Statuscode int `json:"statuscode"`
Message string `json:"message"`
Totalitems string `json:"totalitems"`
Itemsperpage string `json:"itemsperpage"`
} `json:"meta"`
Data []string `json:"data"` Data []string `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type GroupListResponse struct { type GroupListResponse struct {
Ocs struct { Ocs struct {
Meta struct { Meta Meta `json:"meta"`
Status string `json:"status"`
Statuscode int `json:"statuscode"`
Message string `json:"message"`
Totalitems string `json:"totalitems"`
Itemsperpage string `json:"itemsperpage"`
} `json:"meta"`
Data struct { Data struct {
Groups []string `json:"groups"` Groups []string `json:"groups"`
} `json:"data"` } `json:"data"`
} `json:"ocs"` } `json:"ocs"`
} }
type AppListResponse struct {
Ocs struct {
Meta Meta `json:"meta"`
Data struct {
Apps []string `json:"apps"`
} `json:"data"`
} `json:"ocs"`
}
type AppResponse struct {
Ocs struct {
Meta Meta `json:"meta"`
Data App `json:"data"`
} `json:"ocs"`
}
type CapabilitiesResponse struct { type CapabilitiesResponse struct {
Ocs struct { Ocs struct {
Meta struct { Meta Meta `json:"meta"`
Status string `json:"status"`
Statuscode int `json:"statuscode"`
Message string `json:"message"`
Totalitems string `json:"totalitems"`
Itemsperpage string `json:"itemsperpage"`
} `json:"meta"`
Data struct { Data struct {
Version struct { Version struct {
Major int `json:"major"` Major int `json:"major"`

View File

@ -1,7 +1,7 @@
package types package types
type User struct { type User struct {
Enabled string `json:"enabled"` Enabled bool `json:"enabled"`
ID string `json:"id"` ID string `json:"id"`
Quota struct { Quota struct {
Free int64 `json:"free"` Free int64 `json:"free"`

View File

@ -1,11 +1,12 @@
package client package client
import ( import (
"fmt" "encoding/json"
req "github.com/levigross/grequests" req "github.com/levigross/grequests"
"github.com/partitio/gonextcloud/client/types" "github.com/partitio/gonextcloud/client/types"
"net/http" "net/http"
"path" "path"
"strconv"
) )
func (c *Client) UserList() ([]string, error) { func (c *Client) UserList() ([]string, error) {
@ -17,12 +18,15 @@ func (c *Client) UserList() ([]string, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var ul types.UserListResponse var r types.UserListResponse
res.JSON(&ul) res.JSON(&r)
return ul.Ocs.Data.Users, nil return r.Ocs.Data.Users, nil
} }
func (c *Client) User(name string) (*types.User, error) { func (c *Client) User(name string) (*types.User, error) {
if name == "" {
return nil, &types.APIError{Message: "name cannot be empty"}
}
if !c.loggedIn() { if !c.loggedIn() {
return nil, unauthorized return nil, unauthorized
} }
@ -32,12 +36,18 @@ func (c *Client) User(name string) (*types.User, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var ur types.UserResponse var r types.UserResponse
res.JSON(&ur) js := res.String()
if ur.Ocs.Meta.Statuscode != 100 { // Nextcloud does not encode JSON properly
return nil, fmt.Errorf("%d : %s", ur.Ocs.Meta.Statuscode, ur.Ocs.Meta.Message) js = reformatJSON(js)
if err := json.Unmarshal([]byte(js), &r); err != nil {
return nil, err
} }
return &ur.Ocs.Data, nil if r.Ocs.Meta.Statuscode != 100 {
e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &e
}
return &r.Ocs.Data, nil
} }
func (c *Client) UserSearch(search string) ([]string, error) { func (c *Client) UserSearch(search string) ([]string, error) {
@ -55,7 +65,8 @@ func (c *Client) UserSearch(search string) ([]string, error) {
var r types.UserListResponse var r types.UserListResponse
res.JSON(&r) res.JSON(&r)
if r.Ocs.Meta.Statuscode != 100 { if r.Ocs.Meta.Statuscode != 100 {
return nil, fmt.Errorf("%d : %s", r.Ocs.Meta.Statuscode, r.Ocs.Meta.Message) e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &e
} }
return r.Ocs.Data.Users, nil return r.Ocs.Data.Users, nil
} }
@ -120,8 +131,8 @@ func (c *Client) UserUpdatePassword(name string, password string) error {
return c.userUpdateAttribute(name, "password", password) return c.userUpdateAttribute(name, "password", password)
} }
func (c *Client) UserUpdateQuota(name string, quota string) error { func (c *Client) UserUpdateQuota(name string, quota int) error {
return c.userUpdateAttribute(name, "quota", quota) return c.userUpdateAttribute(name, "quota", strconv.Itoa(quota))
} }
func (c *Client) UserGroupList(name string) ([]string, error) { func (c *Client) UserGroupList(name string) ([]string, error) {
@ -137,7 +148,8 @@ func (c *Client) UserGroupList(name string) ([]string, error) {
var r types.GroupListResponse var r types.GroupListResponse
res.JSON(&r) res.JSON(&r)
if r.Ocs.Meta.Statuscode != 100 { if r.Ocs.Meta.Statuscode != 100 {
return nil, fmt.Errorf("%d : %s", r.Ocs.Meta.Statuscode, r.Ocs.Meta.Message) e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &e
} }
return r.Ocs.Data.Groups, nil return r.Ocs.Data.Groups, nil
} }
@ -191,7 +203,8 @@ func (c *Client) UserGroupSubAdminList(name string) ([]string, error) {
var r types.BaseResponse var r types.BaseResponse
res.JSON(&r) res.JSON(&r)
if r.Ocs.Meta.Statuscode != 100 { if r.Ocs.Meta.Statuscode != 100 {
return nil, fmt.Errorf("%d : %s", r.Ocs.Meta.Statuscode, r.Ocs.Meta.Message) e := types.ErrorFromMeta(r.Ocs.Meta)
return nil, &e
} }
return r.Ocs.Data, nil return r.Ocs.Data, nil
} }
@ -211,10 +224,11 @@ func (c *Client) userBaseRequest(name string, route string, ro *req.RequestOptio
if err != nil { if err != nil {
return err return err
} }
var ur types.UserResponse var r types.UserResponse
res.JSON(&ur) res.JSON(&r)
if ur.Ocs.Meta.Statuscode != 100 { if r.Ocs.Meta.Statuscode != 100 {
return fmt.Errorf("%d : %s", ur.Ocs.Meta.Statuscode, ur.Ocs.Meta.Message) e := types.ErrorFromMeta(r.Ocs.Meta)
return &e
} }
return nil return nil
} }

View File

@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"path" "path"
"strings"
) )
func (c *Client) baseRequest(route *url.URL, name string, subroute string, ro *req.RequestOptions, method string) (*req.Response, error) { func (c *Client) baseRequest(route *url.URL, name string, subroute string, ro *req.RequestOptions, method string) (*req.Response, error) {
@ -36,3 +37,12 @@ func (c *Client) baseRequest(route *url.URL, name string, subroute string, ro *r
} }
return res, nil return res, nil
} }
func reformatJSON(json string) string {
// Nextcloud encode boolean as string
json = strings.Replace(json, "\"true\"", "true", -1)
json = strings.Replace(json, "\"false\"", "false", -1)
// Nextcloud encode quota as an empty array for never connected users
json = strings.Replace(json, "\"quota\":[],", "", -1)
return json
}

245
gonextcloud_test.go Normal file
View File

@ -0,0 +1,245 @@
package gonextcloud
import (
"github.com/partitio/gonextcloud/client"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
"testing"
)
var config = Config{}
var c *client.Client
type Config struct {
URL string `yaml:"url"`
Login string `yaml:"login"`
Password string `yaml:"password"`
AppName string `yaml:"app-name"`
GroupsToCreate []string `yaml:"groups-to-create"`
NotExistingUser string `yaml:"not-existing-user"`
NotExistingGroup string `yaml:"not-existing-group"`
}
func LoadConfig() error {
f, err := os.Open("./config.yml")
if err != nil {
return err
}
b, err := ioutil.ReadAll(f)
if err != nil {
return err
}
if err := yaml.Unmarshal(b, &config); err != nil {
return err
}
return nil
}
func TestTruth(t *testing.T) {
assert.Equal(t, true, true, "seriously ??!")
}
func TestLoadConfig(t *testing.T) {
err := LoadConfig()
assert.Nil(t, err)
}
func TestClient(t *testing.T) {
var err error
c, err = client.NewClient(config.URL)
assert.Nil(t, err, "aie")
}
func TestLoginFail(t *testing.T) {
err := c.Login("", "")
assert.NotNil(t, err)
}
func TestLogin(t *testing.T) {
err := c.Login(config.Login, config.Password)
assert.Nil(t, err)
}
func TestUserList(t *testing.T) {
us, err := c.UserList()
assert.Nil(t, err)
assert.Contains(t, us, config.Login)
}
func TestExistingUser(t *testing.T) {
u, err := c.User(config.Login)
assert.Nil(t, err)
assert.NotNil(t, u)
}
func TestEmptyUser(t *testing.T) {
u, err := c.User("")
assert.NotNil(t, err)
assert.Empty(t, u)
}
func TestNonExistingUser(t *testing.T) {
_, err := c.User(config.NotExistingUser)
assert.NotNil(t, err)
}
func TestUserSearch(t *testing.T) {
us, err := c.UserSearch(config.Login)
assert.Nil(t, err)
assert.Contains(t, us, config.Login)
}
func TestUserCreate(t *testing.T) {
err := c.UserCreate(config.NotExistingUser, "somecomplicatedpassword")
assert.Nil(t, err)
}
func TestUserCreateExisting(t *testing.T) {
err := c.UserCreate(config.NotExistingUser, "somecomplicatedpassword")
assert.NotNil(t, err)
}
func TestGroupList(t *testing.T) {
gs, err := c.GroupList()
assert.Nil(t, err)
assert.Contains(t, gs, "admin")
}
func TestGroupCreate(t *testing.T) {
err := c.GroupCreate(config.NotExistingGroup)
assert.Nil(t, err)
}
func TestUserUpdateEmail(t *testing.T) {
email := "my@mail.com"
err := c.UserUpdateEmail(config.NotExistingUser, email)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.Nil(t, err)
assert.Equal(t, email, u.Email)
}
func TestUserUpdateDisplayName(t *testing.T) {
displayName := "Display Name"
err := c.UserUpdateDisplayName(config.NotExistingUser, displayName)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.Nil(t, err)
assert.Equal(t, displayName, u.Displayname)
}
func TestUserUpdatePhone(t *testing.T) {
phone := "+33 42 42 42 42"
err := c.UserUpdatePhone(config.NotExistingUser, phone)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.Nil(t, err)
assert.Equal(t, phone, u.Phone)
}
func TestUserUpdateAddress(t *testing.T) {
address := "Main Street, Galifrey"
err := c.UserUpdateAddress(config.NotExistingUser, address)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.Nil(t, err)
assert.Equal(t, address, u.Address)
}
func TestUserUpdateWebSite(t *testing.T) {
website := "www.doctor.who"
err := c.UserUpdateWebSite(config.NotExistingUser, website)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.Nil(t, err)
assert.Equal(t, website, u.Website)
}
func TestUserUpdateTwitter(t *testing.T) {
twitter := "@doctorwho"
err := c.UserUpdateTwitter(config.NotExistingUser, twitter)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.Nil(t, err)
assert.Equal(t, twitter, u.Twitter)
}
func TestUserUpdateQuota(t *testing.T) {
quota := 1024 * 1024 * 1024
err := c.UserUpdateQuota(config.NotExistingUser, quota)
assert.Nil(t, err)
// TODO : Find better verification : A never connected User does not have quota available
//u, err := c.User(config.NotExistingUser)
//assert.Nil(t, err)
//assert.Equal(t, quota, u.Quota.Quota)
}
func TestUserUpdatePassword(t *testing.T) {
password := "newcomplexpassword"
err := c.UserUpdatePassword(config.NotExistingUser, password)
assert.Nil(t, err)
}
func TestUserGroupAdd(t *testing.T) {
err := c.UserGroupAdd(config.NotExistingUser, config.NotExistingGroup)
assert.Nil(t, err)
gs, err := c.UserGroupList(config.NotExistingUser)
assert.Nil(t, err)
assert.Contains(t, gs, config.NotExistingGroup)
}
func TestUserGroupSubAdminList(t *testing.T) {
gs, err := c.UserGroupSubAdminList(config.NotExistingUser)
assert.NotNil(t, err)
assert.Empty(t, gs)
}
func TestUserGroupPromote(t *testing.T) {
err := c.UserGroupPromote(config.NotExistingUser, config.NotExistingGroup)
assert.Nil(t, err)
gs, err := c.UserGroupSubAdminList(config.NotExistingUser)
assert.Nil(t, err)
assert.Contains(t, gs, config.NotExistingGroup)
}
func TestUserGroupDemote(t *testing.T) {
err := c.UserGroupDemote(config.NotExistingUser, config.NotExistingGroup)
assert.Nil(t, err)
//gs, err := c.UserGroupSubAdminList(config.NotExistingUser)
//assert.Nil(t, err)
//assert.Empty(t, gs)
}
func TestUserDisable(t *testing.T) {
err := c.UserDisable(config.NotExistingUser)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.Nil(t, err)
assert.False(t, u.Enabled)
}
func TestUserEnable(t *testing.T) {
err := c.UserEnable(config.NotExistingUser)
assert.Nil(t, err)
u, err := c.User(config.NotExistingUser)
assert.Nil(t, err)
assert.True(t, u.Enabled)
}
func TestGroupDelete(t *testing.T) {
err := c.GroupDelete(config.NotExistingGroup)
assert.Nil(t, err)
}
func TestUserDelete(t *testing.T) {
err := c.UserDelete(config.NotExistingUser)
assert.Nil(t, err)
}
func TestLogout(t *testing.T) {
err := c.Logout()
assert.Nil(t, err)
}