mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 04:05:40 +01:00
fix #895.
This commit is contained in:
parent
fa703e58b5
commit
a7c84cc2c8
@ -16,13 +16,14 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/vmware/harbor/src/common/api"
|
||||||
"github.com/vmware/harbor/src/common/dao"
|
"github.com/vmware/harbor/src/common/dao"
|
||||||
"github.com/vmware/harbor/src/common/models"
|
"github.com/vmware/harbor/src/common/models"
|
||||||
"github.com/vmware/harbor/src/common/utils/log"
|
"github.com/vmware/harbor/src/common/utils/log"
|
||||||
"github.com/vmware/harbor/src/common/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProjectMemberAPI handles request to /api/projects/{}/members/{}
|
// ProjectMemberAPI handles request to /api/projects/{}/members/{}
|
||||||
@ -98,6 +99,11 @@ func (pma *ProjectMemberAPI) Get() {
|
|||||||
log.Errorf("Error occurred in GetUserProjectRoles, error: %v", err)
|
log.Errorf("Error occurred in GetUserProjectRoles, error: %v", err)
|
||||||
pma.CustomAbort(http.StatusInternalServerError, "Internal error.")
|
pma.CustomAbort(http.StatusInternalServerError, "Internal error.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(roleList) == 0 {
|
||||||
|
pma.CustomAbort(http.StatusNotFound, fmt.Sprintf("user %d is not a member of the project", pma.memberID))
|
||||||
|
}
|
||||||
|
|
||||||
//return empty role list to indicate if a user is not a member
|
//return empty role list to indicate if a user is not a member
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]interface{})
|
||||||
user, err := dao.GetUser(models.User{UserID: pma.memberID})
|
user, err := dao.GetUser(models.User{UserID: pma.memberID})
|
||||||
|
@ -4,9 +4,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/vmware/harbor/tests/apitests/apilib"
|
"github.com/vmware/harbor/tests/apitests/apilib"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMemGet(t *testing.T) {
|
func TestMemGet(t *testing.T) {
|
||||||
@ -51,8 +52,19 @@ func TestMemGet(t *testing.T) {
|
|||||||
assert.Equal(int(404), httpStatusCode, "Case 3: Project creation status should be 404")
|
assert.Equal(int(404), httpStatusCode, "Case 3: Project creation status should be 404")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\n")
|
//------------case 4: Response Code=404, member does not exist-----------//
|
||||||
|
fmt.Println("case 4: Response Code=404, member does not exist")
|
||||||
|
projectID = "1"
|
||||||
|
memberID := "10000"
|
||||||
|
httpStatusCode, err = apiTest.GetMemByPIDUID(*admin, projectID, memberID)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to get member %s of project %s: %v", memberID, projectID, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(int(404), httpStatusCode,
|
||||||
|
fmt.Sprintf("response status code should be 404 other than %d", httpStatusCode))
|
||||||
|
|
||||||
|
fmt.Printf("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user