mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-23 17:17:46 +01:00
Merge pull request #8976 from ninjadq/add_auth_for_project_head
Fix: Add authenticate to projects head
This commit is contained in:
commit
f77ce4aa3a
@ -234,6 +234,12 @@ func (p *ProjectAPI) Post() {
|
|||||||
|
|
||||||
// Head ...
|
// Head ...
|
||||||
func (p *ProjectAPI) Head() {
|
func (p *ProjectAPI) Head() {
|
||||||
|
|
||||||
|
if !p.SecurityCtx.IsAuthenticated() {
|
||||||
|
p.SendUnAuthorizedError(errors.New("Unauthorized"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
name := p.GetString("project_name")
|
name := p.GetString("project_name")
|
||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
p.SendBadRequestError(errors.New("project_name is needed"))
|
p.SendBadRequestError(errors.New("project_name is needed"))
|
||||||
|
@ -329,13 +329,13 @@ func TestDeleteProject(t *testing.T) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
func TestProHead(t *testing.T) {
|
func TestProHead(t *testing.T) {
|
||||||
fmt.Println("\nTest for Project HEAD API")
|
t.Log("\nTest for Project HEAD API")
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
apiTest := newHarborAPI()
|
apiTest := newHarborAPI()
|
||||||
|
|
||||||
// ----------------------------case 1 : Response Code=200----------------------------//
|
// ----------------------------case 1 : Response Code=200----------------------------//
|
||||||
fmt.Println("case 1: response code:200")
|
t.Log("case 1: response code:200")
|
||||||
httpStatusCode, err := apiTest.ProjectsHead(*admin, "library")
|
httpStatusCode, err := apiTest.ProjectsHead(*admin, "library")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error while search project by proName", err.Error())
|
t.Error("Error while search project by proName", err.Error())
|
||||||
@ -345,7 +345,7 @@ func TestProHead(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------case 2 : Response Code=404:Project name does not exist.----------------------------//
|
// ----------------------------case 2 : Response Code=404:Project name does not exist.----------------------------//
|
||||||
fmt.Println("case 2: response code:404,Project name does not exist.")
|
t.Log("case 2: response code:404,Project name does not exist.")
|
||||||
httpStatusCode, err = apiTest.ProjectsHead(*admin, "libra")
|
httpStatusCode, err = apiTest.ProjectsHead(*admin, "libra")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("Error while search project by proName", err.Error())
|
t.Error("Error while search project by proName", err.Error())
|
||||||
@ -354,6 +354,24 @@ func TestProHead(t *testing.T) {
|
|||||||
assert.Equal(int(404), httpStatusCode, "httpStatusCode should be 404")
|
assert.Equal(int(404), httpStatusCode, "httpStatusCode should be 404")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Log("case 3: response code:401. Project exist with unauthenticated user")
|
||||||
|
httpStatusCode, err = apiTest.ProjectsHead(*unknownUsr, "library")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Error while search project by proName", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
assert.Equal(int(401), httpStatusCode, "httpStatusCode should be 404")
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log("case 4: response code:401. Project name does not exist with unauthenticated user")
|
||||||
|
httpStatusCode, err = apiTest.ProjectsHead(*unknownUsr, "libra")
|
||||||
|
if err != nil {
|
||||||
|
t.Error("Error while search project by proName", err.Error())
|
||||||
|
t.Log(err)
|
||||||
|
} else {
|
||||||
|
assert.Equal(int(401), httpStatusCode, "httpStatusCode should be 404")
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Printf("\n")
|
fmt.Printf("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,7 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/core/auth"
|
"github.com/goharbor/harbor/src/core/auth"
|
||||||
"github.com/goharbor/harbor/src/core/config"
|
"github.com/goharbor/harbor/src/core/config"
|
||||||
|
"github.com/goharbor/harbor/src/core/filter"
|
||||||
)
|
)
|
||||||
|
|
||||||
const userKey = "user"
|
const userKey = "user"
|
||||||
|
Loading…
Reference in New Issue
Block a user