瀏覽代碼

add a test case for UID/GID limits

Nicola Murino 4 年之前
父節點
當前提交
0e50310a66
共有 2 個文件被更改,包括 16 次插入2 次删除
  1. 2 2
      dataprovider/user.go
  2. 14 0
      httpd/httpd_test.go

+ 2 - 2
dataprovider/user.go

@@ -822,7 +822,7 @@ func (u *User) GetFsConfigAsJSON() ([]byte, error) {
 
 // GetUID returns a validate uid, suitable for use with os.Chown
 func (u *User) GetUID() int {
-	if u.UID <= 0 || u.UID > int(math.Pow(2, 31))-1 {
+	if u.UID <= 0 || u.UID > math.MaxInt32 {
 		return -1
 	}
 	return u.UID
@@ -830,7 +830,7 @@ func (u *User) GetUID() int {
 
 // GetGID returns a validate gid, suitable for use with os.Chown
 func (u *User) GetGID() int {
-	if u.GID <= 0 || u.GID > int(math.Pow(2, 31))-1 {
+	if u.GID <= 0 || u.GID > math.MaxInt32 {
 		return -1
 	}
 	return u.GID

+ 14 - 0
httpd/httpd_test.go

@@ -7,6 +7,7 @@ import (
 	"errors"
 	"fmt"
 	"io"
+	"math"
 	"mime/multipart"
 	"net"
 	"net/http"
@@ -419,6 +420,19 @@ func TestUserStatus(t *testing.T) {
 	assert.NoError(t, err)
 }
 
+func TestUidGidLimits(t *testing.T) {
+	u := getTestUser()
+	u.UID = math.MaxInt32
+	u.GID = math.MaxInt32
+	user, _, err := httpdtest.AddUser(u, http.StatusCreated)
+	assert.NoError(t, err)
+	assert.Equal(t, math.MaxInt32, user.GetUID())
+	assert.Equal(t, math.MaxInt32, user.GetGID())
+
+	_, err = httpdtest.RemoveUser(user, http.StatusOK)
+	assert.NoError(t, err)
+}
+
 func TestAddUserNoCredentials(t *testing.T) {
 	u := getTestUser()
 	u.Password = ""