From 2548bb06a06354a0ca6931f5773f5f83d989670f Mon Sep 17 00:00:00 2001
From: yhua
Date: Tue, 25 Oct 2016 15:45:55 +0800
Subject: [PATCH 1/3] improve make clean user interactions and fix one dir
issue for golang image build
---
Makefile | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index f82fa43..6cd0054 100644
--- a/Makefile
+++ b/Makefile
@@ -104,8 +104,8 @@ GOIMAGEBUILD=$(GOIMAGEBUILDCMD) build
GOBUILDPATH_UI=$(GOBUILDPATH)/src/ui
GOBUILDPATH_JOBSERVICE=$(GOBUILDPATH)/src/jobservice
GOBUILDMAKEPATH=$(GOBUILDPATH)/make
-GOBUILDMAKEPATH_UI=$(GOBUILDMAKEPATH)/ui
-GOBUILDMAKEPATH_JOBSERVICE=$(GOBUILDMAKEPATH)/jobservice
+GOBUILDMAKEPATH_UI=$(GOBUILDMAKEPATH)/dev/ui
+GOBUILDMAKEPATH_JOBSERVICE=$(GOBUILDMAKEPATH)/dev/jobservice
# binary
UISOURCECODE=$(SRCPATH)/ui
@@ -345,9 +345,18 @@ cleanpackage:
then rm $(BUILDPATH)/harbor-online-installer-$(VERSIONTAG).tgz ; fi
@if [ -f $(BUILDPATH)/harbor-offline-installer-$(VERSIONTAG).tgz ] ; \
then rm $(BUILDPATH)/harbor-offline-installer-$(VERSIONTAG).tgz ; fi
-
-.PHONY: clean
-clean: cleanbinary cleanimage cleandockercomposefile cleanversiontag cleanpackage
+
+.PHONY: cleanall
+cleanall: cleanbinary cleanimage cleandockercomposefile cleanversiontag cleanpackage
+
+clean:
+ @echo " make cleanall: remove binary, Harbor images, specific version docker-compose"
+ @echo " file, specific version tag, online and offline install package"
+ @echo " make cleanbinary: remove ui and jobservice binary"
+ @echo " make cleanimage: remove Harbor images"
+ @echo " make cleandockercomposefile: remove specific version docker-compose"
+ @echo " make cleanversiontag: cleanpackageremove specific version tag"
+ @echo " make cleanpackage: remove online and offline install package"
all: install
From f01c0fd870b1a956830efe7d0f097fdc006b54ee Mon Sep 17 00:00:00 2001
From: yhua
Date: Tue, 25 Oct 2016 16:10:56 +0800
Subject: [PATCH 2/3] fix nginx:1.9.0 remove 0
---
Makefile | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 6cd0054..52b5ffe 100644
--- a/Makefile
+++ b/Makefile
@@ -270,7 +270,7 @@ package_offline: compile build modify_composefile
$(DOCKERIMAGENAME_LOG):$(VERSIONTAG) \
$(DOCKERIMAGENAME_DB):$(VERSIONTAG) \
$(DOCKERIMAGENAME_JOBSERVICE):$(VERSIONTAG) \
- nginx:1.9.0 registry:2.5.0
+ nginx:1.9 registry:2.5.0
@$(TARCMD) -zcvf harbor-offline-installer-$(VERSIONTAG).tgz \
--exclude=$(HARBORPKG)/common/db --exclude=$(HARBORPKG)/ubuntu \
@@ -358,5 +358,4 @@ clean:
@echo " make cleanversiontag: cleanpackageremove specific version tag"
@echo " make cleanpackage: remove online and offline install package"
-all: install
-
+all: install
\ No newline at end of file
From 2924799f781b4f3c7afb7743e69a800fc2d88bca Mon Sep 17 00:00:00 2001
From: wemeya
Date: Mon, 17 Oct 2016 16:57:34 +0800
Subject: [PATCH 3/3] add project role for non-sysadmin user
---
src/common/dao/dao_test.go | 17 +++++++++++--
src/ui/api/dataprepare_test.go | 4 +--
src/ui/api/harborapi_test.go | 14 ++++++++---
src/ui/api/log_test.go | 42 ++++++++++++++++++++++---------
src/ui/api/project.go | 7 ++++++
src/ui/api/project_test.go | 46 ++++++++++++++++++++++++++++++++--
src/ui/api/user_test.go | 2 +-
7 files changed, 110 insertions(+), 22 deletions(-)
diff --git a/src/common/dao/dao_test.go b/src/common/dao/dao_test.go
index ebb03b9..c276f3b 100644
--- a/src/common/dao/dao_test.go
+++ b/src/common/dao/dao_test.go
@@ -428,7 +428,13 @@ func TestResetUserPassword(t *testing.T) {
}
func TestChangeUserPassword(t *testing.T) {
- err := ChangeUserPassword(models.User{UserID: currentUser.UserID, Password: "NewHarborTester12345", Salt: currentUser.Salt})
+ user := models.User{UserID: currentUser.UserID}
+ query, err := GetUser(user)
+ if err != nil {
+ t.Errorf("Error occurred when get user salt")
+ }
+ currentUser.Salt = query.Salt
+ err = ChangeUserPassword(models.User{UserID: currentUser.UserID, Password: "NewHarborTester12345", Salt: currentUser.Salt})
if err != nil {
t.Errorf("Error occurred in ChangeUserPassword: %v", err)
}
@@ -444,7 +450,14 @@ func TestChangeUserPassword(t *testing.T) {
}
func TestChangeUserPasswordWithOldPassword(t *testing.T) {
- err := ChangeUserPassword(models.User{UserID: currentUser.UserID, Password: "NewerHarborTester12345", Salt: currentUser.Salt}, "NewHarborTester12345")
+ user := models.User{UserID: currentUser.UserID}
+ query, err := GetUser(user)
+ if err != nil {
+ t.Errorf("Error occurred when get user salt")
+ }
+ currentUser.Salt = query.Salt
+
+ err = ChangeUserPassword(models.User{UserID: currentUser.UserID, Password: "NewerHarborTester12345", Salt: currentUser.Salt}, "NewHarborTester12345")
if err != nil {
t.Errorf("Error occurred in ChangeUserPassword: %v", err)
}
diff --git a/src/ui/api/dataprepare_test.go b/src/ui/api/dataprepare_test.go
index feb4bbc..928c517 100644
--- a/src/ui/api/dataprepare_test.go
+++ b/src/ui/api/dataprepare_test.go
@@ -34,8 +34,8 @@ func CommonAddUser() {
commonUser := models.User{
Username: TestUserName,
- Email: TestUserPwd,
- Password: TestUserEmail,
+ Password: TestUserPwd,
+ Email: TestUserEmail,
}
_, _ = dao.Register(commonUser)
diff --git a/src/ui/api/harborapi_test.go b/src/ui/api/harborapi_test.go
index a2acecd..5bfb200 100644
--- a/src/ui/api/harborapi_test.go
+++ b/src/ui/api/harborapi_test.go
@@ -12,8 +12,8 @@ import (
"github.com/vmware/harbor/src/common/dao"
"github.com/vmware/harbor/src/common/models"
- "github.com/vmware/harbor/tests/apitests/apilib"
"github.com/vmware/harbor/src/common/utils"
+ "github.com/vmware/harbor/tests/apitests/apilib"
// "strconv"
// "strings"
@@ -285,7 +285,7 @@ func (a testapi) ProjectsGetByPID(projectID string) (int, apilib.Project, error)
}
//Search projects by projectName and isPublic
-func (a testapi) ProjectsGet(projectName string, isPublic int32) (int, []apilib.Project, error) {
+func (a testapi) ProjectsGet(projectName string, isPublic int32, authInfo ...usrInfo) (int, []apilib.Project, error) {
_sling := sling.New().Get(a.basePath)
//create api path
@@ -299,7 +299,15 @@ func (a testapi) ProjectsGet(projectName string, isPublic int32) (int, []apilib.
var successPayload []apilib.Project
- httpStatusCode, body, err := request(_sling, jsonAcceptHeader)
+ var httpStatusCode int
+ var err error
+ var body []byte
+ if len(authInfo) > 0 {
+ httpStatusCode, body, err = request(_sling, jsonAcceptHeader, authInfo[0])
+ } else {
+ httpStatusCode, body, err = request(_sling, jsonAcceptHeader)
+ }
+
if err == nil && httpStatusCode == 200 {
err = json.Unmarshal(body, &successPayload)
}
diff --git a/src/ui/api/log_test.go b/src/ui/api/log_test.go
index 593491b..a7b027a 100644
--- a/src/ui/api/log_test.go
+++ b/src/ui/api/log_test.go
@@ -30,8 +30,7 @@ func TestLogGet(t *testing.T) {
}
logNum := len(result)
- logID := result[0].LogId
- fmt.Println(result)
+ fmt.Println("result", result)
//add the project first.
fmt.Println("add the project first.")
reply, err := apiTest.ProjectsPost(*admin, project)
@@ -48,12 +47,16 @@ func TestLogGet(t *testing.T) {
t.Log(err)
} else {
assert.Equal(logNum+1, len(result), "lines of logs should be equal")
- assert.Equal(int32(logID+1), result[0].LogId, "LogId should be equal")
- assert.Equal("my_project/", result[0].RepoName, "RepoName should be equal")
- assert.Equal("N/A", result[0].RepoTag, "RepoTag should be equal")
- assert.Equal("create", result[0].Operation, "Operation should be equal")
+ num, index := getLog(result)
+ if num != 1 {
+ assert.Equal(1, num, "add my_project log number should be 1")
+ } else {
+ assert.Equal("my_project/", result[index].RepoName, "RepoName should be equal")
+ assert.Equal("N/A", result[index].RepoTag, "RepoTag should be equal")
+ assert.Equal("create", result[index].Operation, "Operation should be equal")
+ }
}
-
+ fmt.Println("log ", result)
//case 2: wrong format of start_time parameter, expect the wrong output
now = fmt.Sprintf("%v", time.Now().Unix())
statusCode, result, err = apiTest.LogGet(*admin, "ss", now, "3")
@@ -103,13 +106,17 @@ func TestLogGet(t *testing.T) {
if logNum+1 >= 10 {
logNum = 10
} else {
- logNum += 1
+ logNum++
}
assert.Equal(logNum, len(result), "lines of logs should be equal")
- assert.Equal(int32(logID+1), result[0].LogId, "LogId should be equal")
- assert.Equal("my_project/", result[0].RepoName, "RepoName should be equal")
- assert.Equal("N/A", result[0].RepoTag, "RepoTag should be equal")
- assert.Equal("create", result[0].Operation, "Operation should be equal")
+ num, index := getLog(result)
+ if num != 1 {
+ assert.Equal(1, num, "add my_project log number should be 1")
+ } else {
+ assert.Equal("my_project/", result[index].RepoName, "RepoName should be equal")
+ assert.Equal("N/A", result[index].RepoTag, "RepoTag should be equal")
+ assert.Equal("create", result[index].Operation, "Operation should be equal")
+ }
}
//get the project
@@ -138,3 +145,14 @@ func TestLogGet(t *testing.T) {
fmt.Printf("\n")
}
+
+func getLog(result []apilib.AccessLog) (int, int) {
+ var num, index int
+ for i := 0; i < len(result); i++ {
+ if result[i].RepoName == "my_project/" {
+ num++
+ index = i
+ }
+ }
+ return num, index
+}
diff --git a/src/ui/api/project.go b/src/ui/api/project.go
index c58941e..e8828e0 100644
--- a/src/ui/api/project.go
+++ b/src/ui/api/project.go
@@ -286,6 +286,13 @@ func (p *ProjectAPI) List() {
if public != 1 {
if isAdmin {
projectList[i].Role = models.PROJECTADMIN
+ } else {
+ roles, err := dao.GetUserProjectRoles(p.userID, projectList[i].ProjectID)
+ if err != nil {
+ log.Errorf("failed to get user's project role: %v", err)
+ p.CustomAbort(http.StatusInternalServerError, "")
+ }
+ projectList[i].Role = roles[0].RoleID
}
if projectList[i].Role == models.PROJECTADMIN {
projectList[i].Togglable = true
diff --git a/src/ui/api/project_test.go b/src/ui/api/project_test.go
index 2b164da..8a43d1d 100644
--- a/src/ui/api/project_test.go
+++ b/src/ui/api/project_test.go
@@ -13,7 +13,7 @@ var addProject *apilib.ProjectReq
var addPID int
func InitAddPro() {
- addProject = &apilib.ProjectReq{"test_project", 1}
+ addProject = &apilib.ProjectReq{"add_project", 1}
}
func TestAddProject(t *testing.T) {
@@ -106,7 +106,49 @@ func TestProGetByName(t *testing.T) {
} else {
assert.Equal(int(401), httpStatusCode, "httpStatusCode should be 200")
}
- fmt.Printf("\n")
+
+ //-------------------case 3 : check admin project role------------------------//
+ httpStatusCode, result, err = apiTest.ProjectsGet(addProject.ProjectName, 0, *admin)
+ if err != nil {
+ t.Error("Error while search project by proName and isPublic", err.Error())
+ t.Log(err)
+ } else {
+ assert.Equal(int(200), httpStatusCode, "httpStatusCode should be 200")
+ assert.Equal(addProject.ProjectName, result[0].ProjectName, "Project name is wrong")
+ assert.Equal(int32(1), result[0].Public, "Public is wrong")
+ assert.Equal(int32(1), result[0].CurrentUserRoleId, "User project role is wrong")
+ }
+
+ //-------------------case 4 : add project member and check his role ------------------------//
+ CommonAddUser()
+ roles := &apilib.RoleParam{[]int32{2}, TestUserName}
+ projectID := strconv.Itoa(addPID)
+ httpStatusCode, err = apiTest.AddProjectMember(*admin, projectID, *roles)
+ if err != nil {
+ t.Error("Error whihle add project role member", err.Error())
+ t.Log(err)
+ } else {
+ assert.Equal(int(200), httpStatusCode, "httpStatusCode should be 200")
+ }
+ httpStatusCode, result, err = apiTest.ProjectsGet(addProject.ProjectName, 0, *testUser)
+ if err != nil {
+ t.Error("Error while search project by proName and isPublic", err.Error())
+ t.Log(err)
+ } else {
+ assert.Equal(int(200), httpStatusCode, "httpStatusCode should be 200")
+ assert.Equal(addProject.ProjectName, result[0].ProjectName, "Project name is wrong")
+ assert.Equal(int32(1), result[0].Public, "Public is wrong")
+ assert.Equal(int32(2), result[0].CurrentUserRoleId, "User project role is wrong")
+ }
+ id := strconv.Itoa(CommonGetUserID())
+ httpStatusCode, err = apiTest.DeleteProjectMember(*admin, projectID, id)
+ if err != nil {
+ t.Error("Error whihle add project role member", err.Error())
+ t.Log(err)
+ } else {
+ assert.Equal(int(200), httpStatusCode, "httpStatusCode should be 200")
+ }
+ CommonDelUser()
}
//Get project by proID
diff --git a/src/ui/api/user_test.go b/src/ui/api/user_test.go
index 7d0caa9..0e00c78 100644
--- a/src/ui/api/user_test.go
+++ b/src/ui/api/user_test.go
@@ -357,7 +357,7 @@ func TestUsersUpdatePassword(t *testing.T) {
//TODO: verify the new password takes effect
}
//case 6: update user2 password setting the new password same as the old
- password.NewPassword = password.OldPassword
+ password.OldPassword = password.NewPassword
code, err = apiTest.UsersUpdatePassword(testUser0002ID, password, *admin)
if err != nil {
t.Error("Error occured while change user profile", err.Error())