mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 14:50:55 +03:00
add groups support
Using groups simplifies the administration of multiple accounts by letting you assign settings once to a group, instead of multiple times to each individual user. Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -450,6 +450,7 @@ func TestInitialization(t *testing.T) {
|
||||
assert.ErrorIs(t, err, os.ErrNotExist)
|
||||
|
||||
err = createTestFile(revokeUserCerts, 10*1024*1024)
|
||||
assert.NoError(t, err)
|
||||
sftpdConf.RevokedUserCertsFile = revokeUserCerts
|
||||
err = sftpdConf.Initialize(configDir)
|
||||
assert.Error(t, err)
|
||||
@@ -606,6 +607,39 @@ func TestBasicSFTPFsHandling(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestGroupSettingsOverride(t *testing.T) {
|
||||
usePubKey := true
|
||||
g := getTestGroup()
|
||||
g.UserSettings.Filters.StartDirectory = "/%username%"
|
||||
group, _, err := httpdtest.AddGroup(g, http.StatusCreated)
|
||||
assert.NoError(t, err)
|
||||
u := getTestUser(usePubKey)
|
||||
u.Groups = []sdk.GroupMapping{
|
||||
{
|
||||
Name: group.Name,
|
||||
Type: sdk.GroupTypePrimary,
|
||||
},
|
||||
}
|
||||
user, _, err := httpdtest.AddUser(u, http.StatusCreated)
|
||||
assert.NoError(t, err)
|
||||
conn, client, err := getSftpClient(user, usePubKey)
|
||||
if assert.NoError(t, err) {
|
||||
defer conn.Close()
|
||||
defer client.Close()
|
||||
|
||||
currentDir, err := client.Getwd()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "/"+user.Username, currentDir)
|
||||
}
|
||||
|
||||
_, err = httpdtest.RemoveUser(user, http.StatusOK)
|
||||
assert.NoError(t, err)
|
||||
err = os.RemoveAll(user.GetHomeDir())
|
||||
assert.NoError(t, err)
|
||||
_, err = httpdtest.RemoveGroup(group, http.StatusOK)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestStartDirectory(t *testing.T) {
|
||||
usePubKey := false
|
||||
startDir := "/st@ rt/dir"
|
||||
@@ -10297,6 +10331,15 @@ func waitTCPListening(address string) {
|
||||
}
|
||||
}
|
||||
|
||||
func getTestGroup() dataprovider.Group {
|
||||
return dataprovider.Group{
|
||||
BaseGroup: sdk.BaseGroup{
|
||||
Name: "test_group",
|
||||
Description: "test group description",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getTestUser(usePubKey bool) dataprovider.User {
|
||||
user := dataprovider.User{
|
||||
BaseUser: sdk.BaseUser{
|
||||
|
||||
Reference in New Issue
Block a user