From a7c84cc2c8fb16b9d14e4ed472a609bb1e18e866 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Thu, 27 Oct 2016 14:16:23 +0800 Subject: [PATCH] fix #895. --- src/ui/api/member.go | 8 +++++++- src/ui/api/member_test.go | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/ui/api/member.go b/src/ui/api/member.go index 63cdc7cde..b528872c5 100644 --- a/src/ui/api/member.go +++ b/src/ui/api/member.go @@ -16,13 +16,14 @@ package api import ( + "fmt" "net/http" "strconv" + "github.com/vmware/harbor/src/common/api" "github.com/vmware/harbor/src/common/dao" "github.com/vmware/harbor/src/common/models" "github.com/vmware/harbor/src/common/utils/log" - "github.com/vmware/harbor/src/common/api" ) // ProjectMemberAPI handles request to /api/projects/{}/members/{} @@ -98,6 +99,11 @@ func (pma *ProjectMemberAPI) Get() { log.Errorf("Error occurred in GetUserProjectRoles, error: %v", err) 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 result := make(map[string]interface{}) user, err := dao.GetUser(models.User{UserID: pma.memberID}) diff --git a/src/ui/api/member_test.go b/src/ui/api/member_test.go index 4b6618e9b..8dbeae8fe 100644 --- a/src/ui/api/member_test.go +++ b/src/ui/api/member_test.go @@ -4,9 +4,10 @@ import ( "fmt" "testing" + "strconv" + "github.com/stretchr/testify/assert" "github.com/vmware/harbor/tests/apitests/apilib" - "strconv" ) 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") } - 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") } /**