mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-20 07:37:38 +01:00
Merge branch 'job-service' into new-ui-with-sync-image
This commit is contained in:
commit
88514849dc
@ -29,9 +29,9 @@ env:
|
|||||||
HARBOR_ADMIN_PASSWD: Harbor12345
|
HARBOR_ADMIN_PASSWD: Harbor12345
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- ./tests/hostcfg.sh
|
- sudo ./tests/hostcfg.sh
|
||||||
- cd Deploy
|
- cd Deploy
|
||||||
- ./prepare
|
- sudo ./prepare
|
||||||
- cd ..
|
- cd ..
|
||||||
|
|
||||||
install:
|
install:
|
||||||
@ -58,6 +58,8 @@ install:
|
|||||||
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
|
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
|
||||||
- chmod +x docker-compose
|
- chmod +x docker-compose
|
||||||
- sudo mv docker-compose /usr/local/bin
|
- sudo mv docker-compose /usr/local/bin
|
||||||
|
- sudo sed -i '$a DOCKER_OPTS=\"$DOCKER_OPTS --insecure-registry 127.0.0.1\"' /etc/default/docker
|
||||||
|
- sudo service docker restart
|
||||||
- go get github.com/dghubble/sling
|
- go get github.com/dghubble/sling
|
||||||
- go get github.com/stretchr/testify
|
- go get github.com/stretchr/testify
|
||||||
|
|
||||||
@ -78,4 +80,5 @@ script:
|
|||||||
|
|
||||||
|
|
||||||
# test for API
|
# test for API
|
||||||
|
- sudo ./tests/testprepare.sh
|
||||||
- go test -v ./tests/apitests
|
- go test -v ./tests/apitests
|
||||||
|
@ -18,7 +18,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"unicode"
|
"strings"
|
||||||
|
|
||||||
"github.com/vmware/harbor/dao"
|
"github.com/vmware/harbor/dao"
|
||||||
"github.com/vmware/harbor/models"
|
"github.com/vmware/harbor/models"
|
||||||
@ -294,10 +294,10 @@ func validateProjectReq(req projectReq) error {
|
|||||||
if isContainIllegalChar(req.ProjectName, []string{"~", "-", "$", "\\", "[", "]", "{", "}", "(", ")", "&", "^", "%", "*", "<", ">", "\"", "'", "/", "?", "@"}) {
|
if isContainIllegalChar(req.ProjectName, []string{"~", "-", "$", "\\", "[", "]", "{", "}", "(", ")", "&", "^", "%", "*", "<", ">", "\"", "'", "/", "?", "@"}) {
|
||||||
return fmt.Errorf("project name contains illegal characters")
|
return fmt.Errorf("project name contains illegal characters")
|
||||||
}
|
}
|
||||||
for _, v := range pn {
|
|
||||||
if !unicode.IsLower(v) {
|
if pn != strings.ToLower(pn) {
|
||||||
return fmt.Errorf("project name must be in lower case")
|
return fmt.Errorf("project name must be in lower case")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -59,11 +59,13 @@ func listRoles(userID int, projectID int64) ([]models.Role, error) {
|
|||||||
roles := make([]models.Role, 0, 1)
|
roles := make([]models.Role, 0, 1)
|
||||||
isSysAdmin, err := dao.IsAdminRole(userID)
|
isSysAdmin, err := dao.IsAdminRole(userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("failed to determine whether the user %d is system admin: %v", userID, err)
|
||||||
return roles, err
|
return roles, err
|
||||||
}
|
}
|
||||||
if isSysAdmin {
|
if isSysAdmin {
|
||||||
role, err := dao.GetRoleByID(models.PROJECTADMIN)
|
role, err := dao.GetRoleByID(models.PROJECTADMIN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("failed to get role %d: %v", models.PROJECTADMIN, err)
|
||||||
return roles, err
|
return roles, err
|
||||||
}
|
}
|
||||||
roles = append(roles, *role)
|
roles = append(roles, *role)
|
||||||
@ -72,6 +74,7 @@ func listRoles(userID int, projectID int64) ([]models.Role, error) {
|
|||||||
|
|
||||||
rs, err := dao.GetUserProjectRoles(userID, projectID)
|
rs, err := dao.GetUserProjectRoles(userID, projectID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Errorf("failed to get user %d 's roles for project %d: %v", userID, projectID, err)
|
||||||
return roles, err
|
return roles, err
|
||||||
}
|
}
|
||||||
roles = append(roles, rs...)
|
roles = append(roles, rs...)
|
||||||
|
@ -119,7 +119,7 @@ paths:
|
|||||||
description: Project name already exists.
|
description: Project name already exists.
|
||||||
500:
|
500:
|
||||||
description: Unexpected internal errors.
|
description: Unexpected internal errors.
|
||||||
/projects/{project_id}:
|
/projects/{project_id}/publicity:
|
||||||
put:
|
put:
|
||||||
summary: Update properties for a selected project.
|
summary: Update properties for a selected project.
|
||||||
description: |
|
description: |
|
||||||
|
130
tests/apitests/hbapidelrpo_test.go
Normal file
130
tests/apitests/hbapidelrpo_test.go
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
package HarborAPItest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/vmware/harbor/tests/apitests/apilib"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestRepositoryDelete(t *testing.T) {
|
||||||
|
fmt.Println("Test for Project Delete (ProjectDelete) API\n")
|
||||||
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
//prepare for test
|
||||||
|
adminEr := &HarborAPI.UsrInfo{"admin", "Harbor1234"}
|
||||||
|
admin := &HarborAPI.UsrInfo{"admin", "Harbor12345"}
|
||||||
|
prjUsr := &HarborAPI.UsrInfo{"unknown", "unknown"}
|
||||||
|
|
||||||
|
fmt.Println("Checking repository status...\n")
|
||||||
|
apiTest := HarborAPI.NewHarborAPI()
|
||||||
|
var searchResault HarborAPI.Search
|
||||||
|
searchResault, err := apiTest.SearchGet("library")
|
||||||
|
//fmt.Printf("%+v\n", resault)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Error while search project or repository", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
//assert.Equal(searchResault.Repositories[0].RepoName, "library/docker", "1st repo name should be")
|
||||||
|
if !assert.Equal(searchResault.Repositories[0].RepoName, "library/docker", "1st repo name should be") {
|
||||||
|
t.Error("fail to find repo 'library/docker'", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
fmt.Println("repo 'library/docker' exit\n")
|
||||||
|
}
|
||||||
|
//assert.Equal(searchResault.Repositories[1].RepoName, "library/hello-world", "2nd repo name should be")
|
||||||
|
if !assert.Equal(searchResault.Repositories[1].RepoName, "library/hello-world", "2nd repo name should be") {
|
||||||
|
t.Error("fail to find repo 'library/hello-world'", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
fmt.Println("repo 'library/hello-world' exit\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
//t.Log(resault)
|
||||||
|
}
|
||||||
|
|
||||||
|
//case 1: admin login fail, expect repo delete fail.
|
||||||
|
fmt.Println("case 1: admin login fail, expect repo delete fail.")
|
||||||
|
|
||||||
|
resault, err := apiTest.HarborLogin(*adminEr)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Error while admin login", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
assert.Equal(resault, int(401), "Admin login status should be 401")
|
||||||
|
//t.Log(resault)
|
||||||
|
}
|
||||||
|
if resault != 401 {
|
||||||
|
t.Log(resault)
|
||||||
|
} else {
|
||||||
|
prjUsr = adminEr
|
||||||
|
}
|
||||||
|
|
||||||
|
resault, err = apiTest.RepositoriesDelete(*prjUsr, "library/docker", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Error while delete repository", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
assert.Equal(resault, int(401), "Case 1: Repository delete status should be 401")
|
||||||
|
//t.Log(resault)
|
||||||
|
}
|
||||||
|
|
||||||
|
//case 2: admin successful login, expect repository delete success.
|
||||||
|
fmt.Println("case 2: admin successful login, expect repository delete success.")
|
||||||
|
resault, err = apiTest.HarborLogin(*admin)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Error while admin login", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
assert.Equal(resault, int(200), "Admin login status should be 200")
|
||||||
|
//t.Log(resault)
|
||||||
|
}
|
||||||
|
if resault != 200 {
|
||||||
|
t.Log(resault)
|
||||||
|
} else {
|
||||||
|
prjUsr = admin
|
||||||
|
}
|
||||||
|
|
||||||
|
resault, err = apiTest.RepositoriesDelete(*prjUsr, "library/docker", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Error while delete repository", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
if assert.Equal(resault, int(200), "Case 2: Repository delete status should be 200") {
|
||||||
|
fmt.Println("Repository 'library/docker' delete success.")
|
||||||
|
}
|
||||||
|
//t.Log(resault)
|
||||||
|
}
|
||||||
|
|
||||||
|
resault, err = apiTest.RepositoriesDelete(*prjUsr, "library/hello-world", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Error while delete repository", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
if assert.Equal(resault, int(200), "Case 2: Repository delete status should be 200") {
|
||||||
|
fmt.Println("Repository 'hello-world' delete success.")
|
||||||
|
}
|
||||||
|
//t.Log(resault)
|
||||||
|
}
|
||||||
|
|
||||||
|
//case 3: delete one repo not exit, expect repo delete fail.
|
||||||
|
fmt.Println("case 3: delete one repo not exit, expect repo delete fail.")
|
||||||
|
|
||||||
|
resault, err = apiTest.RepositoriesDelete(*prjUsr, "library/hello-world", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Error while delete repository", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
if assert.Equal(resault, int(404), "Case 3: Repository delete status should be 404") {
|
||||||
|
fmt.Println("Repository 'hello-world' not exit.")
|
||||||
|
}
|
||||||
|
//t.Log(resault)
|
||||||
|
}
|
||||||
|
|
||||||
|
//if resault.Response.StatusCode != 200 {
|
||||||
|
// t.Log(resault.Response)
|
||||||
|
//}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
IP=`ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}'`
|
IP=`ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}'`
|
||||||
#echo $IP
|
#echo $IP
|
||||||
sed "s/reg.mydomain.com/$IP/" -i Deploy/harbor.cfg
|
sudo sed "s/reg.mydomain.org/$IP/" -i Deploy/harbor.cfg
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
IP=`ip addr s eth0 |grep "inet "|awk '{print $2}' |awk -F "/" '{print $1}'`
|
|
||||||
#echo $IP
|
|
||||||
docker pull hello-world
|
docker pull hello-world
|
||||||
docker pull docker
|
docker pull docker
|
||||||
#docker login -u admin -p Harbor12345 $IP
|
docker login -u admin -p Harbor12345 127.0.0.1
|
||||||
|
|
||||||
docker tag hello-world $IP/library/hello-world
|
docker tag hello-world 127.0.0.1/library/hello-world
|
||||||
docker push $IP/library/hello-world
|
docker push 127.0.0.1/library/hello-world
|
||||||
|
|
||||||
|
docker tag docker 127.0.0.1/library/docker
|
||||||
|
docker push 127.0.0.1/library/docker
|
||||||
|
|
||||||
docker tag docker $IP/library/docker
|
|
||||||
docker push $IP/library/docker
|
|
||||||
|
Loading…
Reference in New Issue
Block a user