mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 02:35:17 +01:00
Merge pull request #5751 from wy65701436/fix-gofmt
Fix gofmt check results
This commit is contained in:
commit
925f70a1ac
@ -26,9 +26,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/adminserver/systemcfg"
|
"github.com/goharbor/harbor/src/adminserver/systemcfg"
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeCfgStore struct {
|
type fakeCfgStore struct {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ping monitor the server status
|
// Ping monitor the server status
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
package api
|
package api
|
||||||
import(
|
|
||||||
"testing"
|
import (
|
||||||
"net/http/httptest"
|
|
||||||
"net/http"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPing(t *testing.T) {
|
func TestPing(t *testing.T) {
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
Ping(w, nil)
|
Ping(w, nil)
|
||||||
assert.Equal(t, http.StatusOK, w.Code)
|
assert.Equal(t, http.StatusOK, w.Code)
|
||||||
result, _:= ioutil.ReadAll(w.Body)
|
result, _ := ioutil.ReadAll(w.Body)
|
||||||
assert.Equal(t, "\"Pong\"", string(result))
|
assert.Equal(t, "\"Pong\"", string(result))
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage"
|
"github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeImageStorageDriver struct {
|
type fakeImageStorageDriver struct {
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
commonsecret "github.com/goharbor/harbor/src/common/secret"
|
commonsecret "github.com/goharbor/harbor/src/common/secret"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAuthenticate(t *testing.T) {
|
func TestAuthenticate(t *testing.T) {
|
||||||
|
@ -19,9 +19,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var c Client
|
var c Client
|
||||||
|
@ -18,9 +18,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
gorilla_handlers "github.com/gorilla/handlers"
|
|
||||||
"github.com/goharbor/harbor/src/adminserver/auth"
|
"github.com/goharbor/harbor/src/adminserver/auth"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
gorilla_handlers "github.com/gorilla/handlers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewHandler returns a gorilla router which is wrapped by authenticate handler
|
// NewHandler returns a gorilla router which is wrapped by authenticate handler
|
||||||
@ -32,7 +32,7 @@ func NewHandler() http.Handler {
|
|||||||
"jobserviceSecret": os.Getenv("JOBSERVICE_SECRET"),
|
"jobserviceSecret": os.Getenv("JOBSERVICE_SECRET"),
|
||||||
}
|
}
|
||||||
insecureAPIs := map[string]bool{
|
insecureAPIs := map[string]bool{
|
||||||
"/api/ping":true,
|
"/api/ping": true,
|
||||||
}
|
}
|
||||||
h = newAuthHandler(auth.NewSecretAuthenticator(secrets), h, insecureAPIs)
|
h = newAuthHandler(auth.NewSecretAuthenticator(secrets), h, insecureAPIs)
|
||||||
h = gorilla_handlers.LoggingHandler(os.Stdout, h)
|
h = gorilla_handlers.LoggingHandler(os.Stdout, h)
|
||||||
@ -61,7 +61,7 @@ func (a *authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.insecureAPIs !=nil && a.insecureAPIs[r.URL.Path] {
|
if a.insecureAPIs != nil && a.insecureAPIs[r.URL.Path] {
|
||||||
if a.handler != nil {
|
if a.handler != nil {
|
||||||
a.handler.ServeHTTP(w, r)
|
a.handler.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/adminserver/auth"
|
"github.com/goharbor/harbor/src/adminserver/auth"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeAuthenticator struct {
|
type fakeAuthenticator struct {
|
||||||
@ -50,35 +50,35 @@ func TestNewAuthHandler(t *testing.T) {
|
|||||||
requestURL string
|
requestURL string
|
||||||
}{
|
}{
|
||||||
|
|
||||||
{nil, nil, nil, http.StatusOK,"http://localhost/good"},
|
{nil, nil, nil, http.StatusOK, "http://localhost/good"},
|
||||||
{&fakeAuthenticator{
|
{&fakeAuthenticator{
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
err: nil,
|
err: nil,
|
||||||
}, nil, nil, http.StatusUnauthorized,"http://localhost/hello"},
|
}, nil, nil, http.StatusUnauthorized, "http://localhost/hello"},
|
||||||
{&fakeAuthenticator{
|
{&fakeAuthenticator{
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
err: errors.New("error"),
|
err: errors.New("error"),
|
||||||
}, nil, nil, http.StatusInternalServerError,"http://localhost/hello"},
|
}, nil, nil, http.StatusInternalServerError, "http://localhost/hello"},
|
||||||
{&fakeAuthenticator{
|
{&fakeAuthenticator{
|
||||||
authenticated: true,
|
authenticated: true,
|
||||||
err: nil,
|
err: nil,
|
||||||
}, &fakeHandler{http.StatusNotFound}, nil, http.StatusNotFound,"http://localhost/notexsit"},
|
}, &fakeHandler{http.StatusNotFound}, nil, http.StatusNotFound, "http://localhost/notexsit"},
|
||||||
{&fakeAuthenticator{
|
{&fakeAuthenticator{
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
err: nil,
|
err: nil,
|
||||||
}, &fakeHandler{http.StatusOK},map[string]bool{"/api/ping":true,},http.StatusOK,"http://localhost/api/ping"},
|
}, &fakeHandler{http.StatusOK}, map[string]bool{"/api/ping": true}, http.StatusOK, "http://localhost/api/ping"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
handler := newAuthHandler(c.authenticator, c.handler, c.insecureAPIs)
|
handler := newAuthHandler(c.authenticator, c.handler, c.insecureAPIs)
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
r := httptest.NewRequest("GET",c.requestURL,nil)
|
r := httptest.NewRequest("GET", c.requestURL, nil)
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
assert.Equal(t, c.responseCode, w.Code, "unexpected response code")
|
assert.Equal(t, c.responseCode, w.Code, "unexpected response code")
|
||||||
}
|
}
|
||||||
handler := NewHandler()
|
handler := NewHandler()
|
||||||
w := httptest.NewRecorder()
|
w := httptest.NewRecorder()
|
||||||
r := httptest.NewRequest("GET","http://localhost/api/ping",nil)
|
r := httptest.NewRequest("GET", "http://localhost/api/ping", nil)
|
||||||
handler.ServeHTTP(w,r)
|
handler.ServeHTTP(w, r)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ package handlers
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/goharbor/harbor/src/adminserver/api"
|
"github.com/goharbor/harbor/src/adminserver/api"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newRouter() http.Handler {
|
func newRouter() http.Handler {
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
comcfg "github.com/goharbor/harbor/src/common/config"
|
comcfg "github.com/goharbor/harbor/src/common/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeKeyProvider struct {
|
type fakeKeyProvider struct {
|
||||||
|
@ -3,9 +3,9 @@ package database
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCfgStore_Name(t *testing.T) {
|
func TestCfgStore_Name(t *testing.T) {
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseStringToInt(t *testing.T) {
|
func TestParseStringToInt(t *testing.T) {
|
||||||
|
@ -17,8 +17,8 @@ package filesystem
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
storage "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage"
|
storage "github.com/goharbor/harbor/src/adminserver/systeminfo/imagestorage"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestName(t *testing.T) {
|
func TestName(t *testing.T) {
|
||||||
|
@ -17,9 +17,9 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAddAdminJob(t *testing.T) {
|
func TestAddAdminJob(t *testing.T) {
|
||||||
|
@ -20,12 +20,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func execUpdate(o orm.Ormer, sql string, params ...interface{}) error {
|
func execUpdate(o orm.Ormer, sql string, params ...interface{}) error {
|
||||||
@ -1311,7 +1311,7 @@ func TestImgScanOverview(t *testing.T) {
|
|||||||
comp := &models.ComponentsOverview{
|
comp := &models.ComponentsOverview{
|
||||||
Total: 2,
|
Total: 2,
|
||||||
Summary: []*models.ComponentsOverviewEntry{
|
Summary: []*models.ComponentsOverviewEntry{
|
||||||
&models.ComponentsOverviewEntry{
|
{
|
||||||
Sev: int(models.SevMedium),
|
Sev: int(models.SevMedium),
|
||||||
Count: 2,
|
Count: 2,
|
||||||
},
|
},
|
||||||
|
@ -251,17 +251,17 @@ func TestOnBoardUserGroup(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetGroupDNQueryCondition(t *testing.T) {
|
func TestGetGroupDNQueryCondition(t *testing.T) {
|
||||||
userGroupList := []*models.UserGroup{
|
userGroupList := []*models.UserGroup{
|
||||||
&models.UserGroup{
|
{
|
||||||
GroupName: "sample1",
|
GroupName: "sample1",
|
||||||
GroupType: 1,
|
GroupType: 1,
|
||||||
LdapGroupDN: "cn=sample1_users,ou=groups,dc=example,dc=com",
|
LdapGroupDN: "cn=sample1_users,ou=groups,dc=example,dc=com",
|
||||||
},
|
},
|
||||||
&models.UserGroup{
|
{
|
||||||
GroupName: "sample2",
|
GroupName: "sample2",
|
||||||
GroupType: 1,
|
GroupType: 1,
|
||||||
LdapGroupDN: "cn=sample2_users,ou=groups,dc=example,dc=com",
|
LdapGroupDN: "cn=sample2_users,ou=groups,dc=example,dc=com",
|
||||||
},
|
},
|
||||||
&models.UserGroup{
|
{
|
||||||
GroupName: "sample3",
|
GroupName: "sample3",
|
||||||
GroupType: 0,
|
GroupType: 0,
|
||||||
LdapGroupDN: "cn=sample3_users,ou=groups,dc=example,dc=com",
|
LdapGroupDN: "cn=sample3_users,ou=groups,dc=example,dc=com",
|
||||||
|
@ -23,9 +23,9 @@ import (
|
|||||||
_ "github.com/golang-migrate/migrate/database/postgres" //import pgsql driver for migrator
|
_ "github.com/golang-migrate/migrate/database/postgres" //import pgsql driver for migrator
|
||||||
_ "github.com/golang-migrate/migrate/source/file" // import local file driver for migrator
|
_ "github.com/golang-migrate/migrate/source/file" // import local file driver for migrator
|
||||||
|
|
||||||
_ "github.com/lib/pq" //register pgsql driver
|
|
||||||
"github.com/goharbor/harbor/src/common/utils"
|
"github.com/goharbor/harbor/src/common/utils"
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
|
_ "github.com/lib/pq" //register pgsql driver
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultMigrationPath = "migrations/postgresql/"
|
const defaultMigrationPath = "migrations/postgresql/"
|
||||||
|
@ -17,9 +17,9 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestProMetaDaoMethods(t *testing.T) {
|
func TestProMetaDaoMethods(t *testing.T) {
|
||||||
|
@ -237,7 +237,7 @@ func TestGetProjectMember(t *testing.T) {
|
|||||||
t.Errorf("Error occurred when GetProjectByName: %v", err)
|
t.Errorf("Error occurred when GetProjectByName: %v", err)
|
||||||
}
|
}
|
||||||
var memberList1 = []*models.Member{
|
var memberList1 = []*models.Member{
|
||||||
&models.Member{
|
{
|
||||||
ID: 346,
|
ID: 346,
|
||||||
Entityname: "admin",
|
Entityname: "admin",
|
||||||
Rolename: "projectAdmin",
|
Rolename: "projectAdmin",
|
||||||
@ -246,7 +246,7 @@ func TestGetProjectMember(t *testing.T) {
|
|||||||
EntityType: "u"},
|
EntityType: "u"},
|
||||||
}
|
}
|
||||||
var memberList2 = []*models.Member{
|
var memberList2 = []*models.Member{
|
||||||
&models.Member{
|
{
|
||||||
ID: 398,
|
ID: 398,
|
||||||
Entityname: "test_group_01",
|
Entityname: "test_group_01",
|
||||||
Rolename: "projectAdmin",
|
Rolename: "projectAdmin",
|
||||||
|
@ -18,10 +18,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -17,10 +17,10 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMethodsOfResourceLabel(t *testing.T) {
|
func TestMethodsOfResourceLabel(t *testing.T) {
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDeleteUser(t *testing.T) {
|
func TestDeleteUser(t *testing.T) {
|
||||||
|
@ -17,9 +17,9 @@ package dao
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMethodsOfWatchItem(t *testing.T) {
|
func TestMethodsOfWatchItem(t *testing.T) {
|
||||||
|
@ -17,9 +17,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
commonsecret "github.com/goharbor/harbor/src/common/secret"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
commonsecret "github.com/goharbor/harbor/src/common/secret"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAuthorizeOfSecretAuthorizer(t *testing.T) {
|
func TestAuthorizeOfSecretAuthorizer(t *testing.T) {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package job
|
package job
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/job/models"
|
"github.com/goharbor/harbor/src/common/job/models"
|
||||||
"github.com/goharbor/harbor/src/common/job/test"
|
"github.com/goharbor/harbor/src/common/job/test"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
@ -41,7 +41,7 @@ func TestIsSysAdmin(t *testing.T) {
|
|||||||
func TestGetProjectRoles(t *testing.T) {
|
func TestGetProjectRoles(t *testing.T) {
|
||||||
ctx := &AuthContext{
|
ctx := &AuthContext{
|
||||||
Projects: []*project{
|
Projects: []*project{
|
||||||
&project{
|
{
|
||||||
Name: "project",
|
Name: "project",
|
||||||
Roles: []string{projectAdminRole, developerRole, guestRole},
|
Roles: []string{projectAdminRole, developerRole, guestRole},
|
||||||
Properties: map[string]string{"__projectIndex": "9"},
|
Properties: map[string]string{"__projectIndex": "9"},
|
||||||
@ -61,11 +61,11 @@ func TestGetProjectRoles(t *testing.T) {
|
|||||||
func TestGetMyProjects(t *testing.T) {
|
func TestGetMyProjects(t *testing.T) {
|
||||||
ctx := &AuthContext{
|
ctx := &AuthContext{
|
||||||
Projects: []*project{
|
Projects: []*project{
|
||||||
&project{
|
{
|
||||||
Name: "project1",
|
Name: "project1",
|
||||||
Roles: []string{projectAdminRole},
|
Roles: []string{projectAdminRole},
|
||||||
},
|
},
|
||||||
&project{
|
{
|
||||||
Name: "project2",
|
Name: "project2",
|
||||||
Roles: []string{developerRole},
|
Roles: []string{developerRole},
|
||||||
},
|
},
|
||||||
|
@ -19,8 +19,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/dao/project"
|
"github.com/goharbor/harbor/src/common/dao/project"
|
||||||
@ -28,6 +26,8 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/ui/promgr"
|
"github.com/goharbor/harbor/src/ui/promgr"
|
||||||
"github.com/goharbor/harbor/src/ui/promgr/pmsdriver/local"
|
"github.com/goharbor/harbor/src/ui/promgr/pmsdriver/local"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -283,7 +283,7 @@ func TestHasAllPermWithGroup(t *testing.T) {
|
|||||||
t.Errorf("Error occurred when GetUser: %v", err)
|
t.Errorf("Error occurred when GetUser: %v", err)
|
||||||
}
|
}
|
||||||
developer.GroupList = []*models.UserGroup{
|
developer.GroupList = []*models.UserGroup{
|
||||||
&models.UserGroup{GroupName: "test_group", GroupType: 1, LdapGroupDN: "cn=harbor_user,dc=example,dc=com"},
|
{GroupName: "test_group", GroupType: 1, LdapGroupDN: "cn=harbor_user,dc=example,dc=com"},
|
||||||
}
|
}
|
||||||
ctx := NewSecurityContext(developer, pm)
|
ctx := NewSecurityContext(developer, pm)
|
||||||
assert.False(t, ctx.HasAllPerm(project.Name))
|
assert.False(t, ctx.HasAllPerm(project.Name))
|
||||||
@ -360,7 +360,7 @@ func TestSecurityContext_GetRolesByGroup(t *testing.T) {
|
|||||||
t.Errorf("Error occurred when GetUser: %v", err)
|
t.Errorf("Error occurred when GetUser: %v", err)
|
||||||
}
|
}
|
||||||
developer.GroupList = []*models.UserGroup{
|
developer.GroupList = []*models.UserGroup{
|
||||||
&models.UserGroup{GroupName: "test_group", GroupType: 1, LdapGroupDN: "cn=harbor_user,dc=example,dc=com"},
|
{GroupName: "test_group", GroupType: 1, LdapGroupDN: "cn=harbor_user,dc=example,dc=com"},
|
||||||
}
|
}
|
||||||
type fields struct {
|
type fields struct {
|
||||||
user *models.User
|
user *models.User
|
||||||
|
@ -17,9 +17,9 @@ package secret
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/secret"
|
"github.com/goharbor/harbor/src/common/secret"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIsAuthenticated(t *testing.T) {
|
func TestIsAuthenticated(t *testing.T) {
|
||||||
|
@ -17,9 +17,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/src/common/utils/clair/test"
|
"github.com/goharbor/harbor/src/common/utils/clair/test"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestParseServerity(t *testing.T) {
|
func TestParseServerity(t *testing.T) {
|
||||||
|
@ -304,7 +304,7 @@ func TestSession_SearchGroup(t *testing.T) {
|
|||||||
{"normal search",
|
{"normal search",
|
||||||
fields{ldapConfig: ldapConfig},
|
fields{ldapConfig: ldapConfig},
|
||||||
args{baseDN: "dc=example,dc=com", filter: "objectClass=groupOfNames", groupName: "harbor_users", groupNameAttribute: "cn"},
|
args{baseDN: "dc=example,dc=com", filter: "objectClass=groupOfNames", groupName: "harbor_users", groupNameAttribute: "cn"},
|
||||||
[]models.LdapGroup{models.LdapGroup{GroupName: "harbor_users", GroupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"}}, false},
|
[]models.LdapGroup{{GroupName: "harbor_users", GroupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"}}, false},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
@ -358,7 +358,7 @@ func TestSession_SearchGroupByDN(t *testing.T) {
|
|||||||
{"normal search",
|
{"normal search",
|
||||||
fields{ldapConfig: ldapConfig, ldapGroupConfig: ldapGroupConfig},
|
fields{ldapConfig: ldapConfig, ldapGroupConfig: ldapGroupConfig},
|
||||||
args{groupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"},
|
args{groupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"},
|
||||||
[]models.LdapGroup{models.LdapGroup{GroupName: "harbor_users", GroupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"}}, false},
|
[]models.LdapGroup{{GroupName: "harbor_users", GroupDN: "cn=harbor_users,ou=groups,dc=example,dc=com"}}, false},
|
||||||
{"search non-exist group",
|
{"search non-exist group",
|
||||||
fields{ldapConfig: ldapConfig, ldapGroupConfig: ldapGroupConfig},
|
fields{ldapConfig: ldapConfig, ldapGroupConfig: ldapGroupConfig},
|
||||||
args{groupDN: "cn=harbor_non_users,ou=groups,dc=example,dc=com"},
|
args{groupDN: "cn=harbor_non_users,ou=groups,dc=example,dc=com"},
|
||||||
|
@ -78,7 +78,7 @@ func GetTargets(notaryEndpoint string, username string, fqRepo string) ([]Target
|
|||||||
res := []Target{}
|
res := []Target{}
|
||||||
t, err := tokenutil.MakeToken(username, tokenutil.Notary,
|
t, err := tokenutil.MakeToken(username, tokenutil.Notary,
|
||||||
[]*token.ResourceActions{
|
[]*token.ResourceActions{
|
||||||
&token.ResourceActions{
|
{
|
||||||
Type: "repository",
|
Type: "repository",
|
||||||
Name: fqRepo,
|
Name: fqRepo,
|
||||||
Actions: []string{"pull"},
|
Actions: []string{"pull"},
|
||||||
|
@ -17,11 +17,11 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
notarytest "github.com/goharbor/harbor/src/common/utils/notary/test"
|
notarytest "github.com/goharbor/harbor/src/common/utils/notary/test"
|
||||||
utilstest "github.com/goharbor/harbor/src/common/utils/test"
|
utilstest "github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/ui/config"
|
"github.com/goharbor/harbor/src/ui/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
@ -23,10 +23,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/distribution/registry/auth/token"
|
"github.com/docker/distribution/registry/auth/token"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFilterReq(t *testing.T) {
|
func TestFilterReq(t *testing.T) {
|
||||||
|
@ -50,7 +50,7 @@ var (
|
|||||||
func TestBlobExist(t *testing.T) {
|
func TestBlobExist(t *testing.T) {
|
||||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
dgt := path[strings.LastIndex(path, "/")+1 : len(path)]
|
dgt := path[strings.LastIndex(path, "/")+1:]
|
||||||
if dgt == digest {
|
if dgt == digest {
|
||||||
w.Header().Add(http.CanonicalHeaderKey("Content-Length"), strconv.Itoa(len(blob)))
|
w.Header().Add(http.CanonicalHeaderKey("Content-Length"), strconv.Itoa(len(blob)))
|
||||||
w.Header().Add(http.CanonicalHeaderKey("Docker-Content-Digest"), digest)
|
w.Header().Add(http.CanonicalHeaderKey("Docker-Content-Digest"), digest)
|
||||||
@ -205,7 +205,7 @@ func TestDeleteBlob(t *testing.T) {
|
|||||||
func TestManifestExist(t *testing.T) {
|
func TestManifestExist(t *testing.T) {
|
||||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
tg := path[strings.LastIndex(path, "/")+1 : len(path)]
|
tg := path[strings.LastIndex(path, "/")+1:]
|
||||||
if tg == tag {
|
if tg == tag {
|
||||||
w.Header().Add(http.CanonicalHeaderKey("Docker-Content-Digest"), digest)
|
w.Header().Add(http.CanonicalHeaderKey("Docker-Content-Digest"), digest)
|
||||||
w.Header().Add(http.CanonicalHeaderKey("Content-Type"), mediaType)
|
w.Header().Add(http.CanonicalHeaderKey("Content-Type"), mediaType)
|
||||||
|
@ -2,8 +2,8 @@ package uaa
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/uaa/test"
|
"github.com/goharbor/harbor/src/common/utils/uaa/test"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
"os"
|
||||||
|
@ -59,7 +59,7 @@ func (fc *FakeClient) SearchUser(name string) ([]*SearchUserEntry, error) {
|
|||||||
ExtID: "some-external-id-1",
|
ExtID: "some-external-id-1",
|
||||||
ID: "u-0001",
|
ID: "u-0001",
|
||||||
UserName: "one",
|
UserName: "one",
|
||||||
Emails: []SearchUserEmailEntry{SearchUserEmailEntry{
|
Emails: []SearchUserEmailEntry{{
|
||||||
Primary: false,
|
Primary: false,
|
||||||
Value: "one@email.com",
|
Value: "one@email.com",
|
||||||
}},
|
}},
|
||||||
@ -68,7 +68,7 @@ func (fc *FakeClient) SearchUser(name string) ([]*SearchUserEntry, error) {
|
|||||||
ExtID: "some-external-id-2-a",
|
ExtID: "some-external-id-2-a",
|
||||||
ID: "u-0002a",
|
ID: "u-0002a",
|
||||||
UserName: "two",
|
UserName: "two",
|
||||||
Emails: []SearchUserEmailEntry{SearchUserEmailEntry{
|
Emails: []SearchUserEmailEntry{{
|
||||||
Primary: false,
|
Primary: false,
|
||||||
Value: "two@email.com",
|
Value: "two@email.com",
|
||||||
}},
|
}},
|
||||||
|
@ -424,7 +424,7 @@ func (fc *fakeController) CancelJob(jobID string) error {
|
|||||||
|
|
||||||
func (fc *fakeController) CheckStatus() (models.JobPoolStats, error) {
|
func (fc *fakeController) CheckStatus() (models.JobPoolStats, error) {
|
||||||
return models.JobPoolStats{
|
return models.JobPoolStats{
|
||||||
Pools: []*models.JobPoolStatsData{&models.JobPoolStatsData{
|
Pools: []*models.JobPoolStatsData{{
|
||||||
WorkerPoolID: "fake_pool_ID",
|
WorkerPoolID: "fake_pool_ID",
|
||||||
Status: "running",
|
Status: "running",
|
||||||
StartedAt: time.Now().Unix(),
|
StartedAt: time.Now().Unix(),
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/errs"
|
"github.com/goharbor/harbor/src/jobservice/errs"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -7,13 +7,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/robfig/cron"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/config"
|
"github.com/goharbor/harbor/src/jobservice/config"
|
||||||
"github.com/goharbor/harbor/src/jobservice/errs"
|
"github.com/goharbor/harbor/src/jobservice/errs"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/jobservice/models"
|
"github.com/goharbor/harbor/src/jobservice/models"
|
||||||
"github.com/goharbor/harbor/src/jobservice/pool"
|
"github.com/goharbor/harbor/src/jobservice/pool"
|
||||||
"github.com/goharbor/harbor/src/jobservice/utils"
|
"github.com/goharbor/harbor/src/jobservice/utils"
|
||||||
|
"github.com/robfig/cron"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -254,7 +254,7 @@ func (f *fakePool) PeriodicallyEnqueue(jobName string, params models.Parameters,
|
|||||||
func (f *fakePool) Stats() (models.JobPoolStats, error) {
|
func (f *fakePool) Stats() (models.JobPoolStats, error) {
|
||||||
return models.JobPoolStats{
|
return models.JobPoolStats{
|
||||||
Pools: []*models.JobPoolStatsData{
|
Pools: []*models.JobPoolStatsData{
|
||||||
&models.JobPoolStatsData{
|
{
|
||||||
Status: "running",
|
Status: "running",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -68,7 +68,7 @@ func BuildBlobURL(endpoint, repository, digest string) string {
|
|||||||
func GetTokenForRepo(repository, secret, internalTokenServiceURL string) (string, error) {
|
func GetTokenForRepo(repository, secret, internalTokenServiceURL string) (string, error) {
|
||||||
credential := httpauth.NewSecretAuthorizer(secret)
|
credential := httpauth.NewSecretAuthorizer(secret)
|
||||||
t, err := auth.GetToken(internalTokenServiceURL, true, credential,
|
t, err := auth.GetToken(internalTokenServiceURL, true, credential,
|
||||||
[]*token.ResourceActions{&token.ResourceActions{
|
[]*token.ResourceActions{{
|
||||||
Type: "repository",
|
Type: "repository",
|
||||||
Name: repository,
|
Name: repository,
|
||||||
Actions: []string{"pull"},
|
Actions: []string{"pull"},
|
||||||
|
@ -10,10 +10,10 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gomodule/redigo/redis"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
"github.com/goharbor/harbor/src/jobservice/models"
|
"github.com/goharbor/harbor/src/jobservice/models"
|
||||||
"github.com/goharbor/harbor/src/jobservice/utils"
|
"github.com/goharbor/harbor/src/jobservice/utils"
|
||||||
|
"github.com/gomodule/redigo/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -16,10 +16,10 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/jobservice/errs"
|
"github.com/goharbor/harbor/src/jobservice/errs"
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
|
|
||||||
"github.com/gomodule/redigo/redis"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/jobservice/models"
|
"github.com/goharbor/harbor/src/jobservice/models"
|
||||||
"github.com/goharbor/harbor/src/jobservice/utils"
|
"github.com/goharbor/harbor/src/jobservice/utils"
|
||||||
|
"github.com/gomodule/redigo/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -12,10 +12,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gomodule/redigo/redis"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/jobservice/models"
|
"github.com/goharbor/harbor/src/jobservice/models"
|
||||||
"github.com/goharbor/harbor/src/jobservice/utils"
|
"github.com/goharbor/harbor/src/jobservice/utils"
|
||||||
|
"github.com/gomodule/redigo/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -7,11 +7,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gocraft/work"
|
"github.com/gocraft/work"
|
||||||
"github.com/gomodule/redigo/redis"
|
|
||||||
"github.com/robfig/cron"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
"github.com/goharbor/harbor/src/jobservice/utils"
|
"github.com/goharbor/harbor/src/jobservice/utils"
|
||||||
|
"github.com/gomodule/redigo/redis"
|
||||||
|
"github.com/robfig/cron"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -13,11 +13,11 @@ import (
|
|||||||
|
|
||||||
"github.com/robfig/cron"
|
"github.com/robfig/cron"
|
||||||
|
|
||||||
"github.com/gomodule/redigo/redis"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/env"
|
"github.com/goharbor/harbor/src/jobservice/env"
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
"github.com/goharbor/harbor/src/jobservice/models"
|
"github.com/goharbor/harbor/src/jobservice/models"
|
||||||
"github.com/goharbor/harbor/src/jobservice/utils"
|
"github.com/goharbor/harbor/src/jobservice/utils"
|
||||||
|
"github.com/gomodule/redigo/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -8,9 +8,9 @@ import (
|
|||||||
|
|
||||||
"github.com/gocraft/work"
|
"github.com/gocraft/work"
|
||||||
|
|
||||||
"github.com/gomodule/redigo/redis"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
"github.com/goharbor/harbor/src/jobservice/utils"
|
"github.com/goharbor/harbor/src/jobservice/utils"
|
||||||
|
"github.com/gomodule/redigo/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Sweeper take charge of clearing the outdated data such as scheduled jobs etc..
|
//Sweeper take charge of clearing the outdated data such as scheduled jobs etc..
|
||||||
|
@ -14,9 +14,9 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/jobservice/opm"
|
"github.com/goharbor/harbor/src/jobservice/opm"
|
||||||
"github.com/goharbor/harbor/src/jobservice/period"
|
"github.com/goharbor/harbor/src/jobservice/period"
|
||||||
|
|
||||||
"github.com/gomodule/redigo/redis"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/models"
|
"github.com/goharbor/harbor/src/jobservice/models"
|
||||||
"github.com/goharbor/harbor/src/jobservice/utils"
|
"github.com/goharbor/harbor/src/jobservice/utils"
|
||||||
|
"github.com/gomodule/redigo/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -9,8 +9,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gocraft/work"
|
"github.com/gocraft/work"
|
||||||
"github.com/gomodule/redigo/redis"
|
|
||||||
"github.com/robfig/cron"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/env"
|
"github.com/goharbor/harbor/src/jobservice/env"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"github.com/goharbor/harbor/src/jobservice/job"
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
@ -18,6 +16,8 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/jobservice/opm"
|
"github.com/goharbor/harbor/src/jobservice/opm"
|
||||||
"github.com/goharbor/harbor/src/jobservice/period"
|
"github.com/goharbor/harbor/src/jobservice/period"
|
||||||
"github.com/goharbor/harbor/src/jobservice/utils"
|
"github.com/goharbor/harbor/src/jobservice/utils"
|
||||||
|
"github.com/gomodule/redigo/redis"
|
||||||
|
"github.com/robfig/cron"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gomodule/redigo/redis"
|
|
||||||
"github.com/goharbor/harbor/src/common/job"
|
"github.com/goharbor/harbor/src/common/job"
|
||||||
"github.com/goharbor/harbor/src/jobservice/api"
|
"github.com/goharbor/harbor/src/jobservice/api"
|
||||||
"github.com/goharbor/harbor/src/jobservice/config"
|
"github.com/goharbor/harbor/src/jobservice/config"
|
||||||
@ -23,6 +22,7 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/jobservice/job/impl/scan"
|
"github.com/goharbor/harbor/src/jobservice/job/impl/scan"
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
"github.com/goharbor/harbor/src/jobservice/pool"
|
"github.com/goharbor/harbor/src/jobservice/pool"
|
||||||
|
"github.com/gomodule/redigo/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -18,8 +18,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
commonsecret "github.com/goharbor/harbor/src/common/secret"
|
commonsecret "github.com/goharbor/harbor/src/common/secret"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAuthorizeRequestInvalid(t *testing.T) {
|
func TestAuthorizeRequestInvalid(t *testing.T) {
|
||||||
|
@ -19,8 +19,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var c Client
|
var c Client
|
||||||
|
@ -18,9 +18,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
gorilla_handlers "github.com/gorilla/handlers"
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/log"
|
"github.com/goharbor/harbor/src/common/utils/log"
|
||||||
"github.com/goharbor/harbor/src/registryctl/auth"
|
"github.com/goharbor/harbor/src/registryctl/auth"
|
||||||
|
gorilla_handlers "github.com/gorilla/handlers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewHandlerChain returns a gorilla router which is wrapped by authenticate handler
|
// NewHandlerChain returns a gorilla router which is wrapped by authenticate handler
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/registryctl/auth"
|
"github.com/goharbor/harbor/src/registryctl/auth"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type fakeAuthenticator struct {
|
type fakeAuthenticator struct {
|
||||||
|
@ -17,8 +17,8 @@ package handlers
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"github.com/goharbor/harbor/src/registryctl/api"
|
"github.com/goharbor/harbor/src/registryctl/api"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newRouter() http.Handler {
|
func newRouter() http.Handler {
|
||||||
|
@ -18,13 +18,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
"github.com/goharbor/harbor/src/replication/source"
|
"github.com/goharbor/harbor/src/replication/source"
|
||||||
"github.com/goharbor/harbor/src/replication/target"
|
"github.com/goharbor/harbor/src/replication/target"
|
||||||
"github.com/goharbor/harbor/src/replication/trigger"
|
"github.com/goharbor/harbor/src/replication/trigger"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
@ -81,7 +81,7 @@ func TestGetCandidates(t *testing.T) {
|
|||||||
policy := &models.ReplicationPolicy{
|
policy := &models.ReplicationPolicy{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
Filters: []models.Filter{
|
Filters: []models.Filter{
|
||||||
models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "*",
|
Value: "*",
|
||||||
},
|
},
|
||||||
@ -94,11 +94,11 @@ func TestGetCandidates(t *testing.T) {
|
|||||||
sourcer := source.NewSourcer()
|
sourcer := source.NewSourcer()
|
||||||
|
|
||||||
candidates := []models.FilterItem{
|
candidates := []models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/hello-world:release-1.0",
|
Value: "library/hello-world:release-1.0",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/hello-world:latest",
|
Value: "library/hello-world:latest",
|
||||||
},
|
},
|
||||||
@ -110,7 +110,7 @@ func TestGetCandidates(t *testing.T) {
|
|||||||
assert.Equal(t, 2, len(result))
|
assert.Equal(t, 2, len(result))
|
||||||
|
|
||||||
policy.Filters = []models.Filter{
|
policy.Filters = []models.Filter{
|
||||||
models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "release-*",
|
Value: "release-*",
|
||||||
},
|
},
|
||||||
@ -121,7 +121,7 @@ func TestGetCandidates(t *testing.T) {
|
|||||||
// test label filter
|
// test label filter
|
||||||
test.InitDatabaseFromEnv()
|
test.InitDatabaseFromEnv()
|
||||||
policy.Filters = []models.Filter{
|
policy.Filters = []models.Filter{
|
||||||
models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindLabel,
|
Kind: replication.FilterItemKindLabel,
|
||||||
Value: int64(1),
|
Value: int64(1),
|
||||||
},
|
},
|
||||||
@ -134,17 +134,17 @@ func TestBuildFilterChain(t *testing.T) {
|
|||||||
policy := &models.ReplicationPolicy{
|
policy := &models.ReplicationPolicy{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
Filters: []models.Filter{
|
Filters: []models.Filter{
|
||||||
models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Value: "*",
|
Value: "*",
|
||||||
},
|
},
|
||||||
|
|
||||||
models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "*",
|
Value: "*",
|
||||||
},
|
},
|
||||||
|
|
||||||
models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindLabel,
|
Kind: replication.FilterItemKindLabel,
|
||||||
Value: int64(1),
|
Value: int64(1),
|
||||||
},
|
},
|
||||||
|
@ -17,10 +17,10 @@ package event
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/replication/event/notification"
|
"github.com/goharbor/harbor/src/replication/event/notification"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHandleOfOnDeletionHandler(t *testing.T) {
|
func TestHandleOfOnDeletionHandler(t *testing.T) {
|
||||||
|
@ -17,10 +17,10 @@ package event
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/replication/event/notification"
|
"github.com/goharbor/harbor/src/replication/event/notification"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHandleOfOnPushHandler(t *testing.T) {
|
func TestHandleOfOnPushHandler(t *testing.T) {
|
||||||
|
@ -17,10 +17,10 @@ package event
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/replication/core"
|
"github.com/goharbor/harbor/src/replication/core"
|
||||||
"github.com/goharbor/harbor/src/replication/event/notification"
|
"github.com/goharbor/harbor/src/replication/event/notification"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHandle(t *testing.T) {
|
func TestHandle(t *testing.T) {
|
||||||
|
@ -18,43 +18,43 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/astaxie/beego/validation"
|
"github.com/astaxie/beego/validation"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValid(t *testing.T) {
|
func TestValid(t *testing.T) {
|
||||||
cases := map[*Filter]bool{
|
cases := map[*Filter]bool{
|
||||||
&Filter{}: true,
|
{}: true,
|
||||||
&Filter{
|
{
|
||||||
Kind: "invalid_kind",
|
Kind: "invalid_kind",
|
||||||
}: true,
|
}: true,
|
||||||
&Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
}: true,
|
}: true,
|
||||||
&Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Pattern: "*",
|
Pattern: "*",
|
||||||
}: false,
|
}: false,
|
||||||
&Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Value: "*",
|
Value: "*",
|
||||||
}: false,
|
}: false,
|
||||||
&Filter{
|
{
|
||||||
Kind: replication.FilterItemKindLabel,
|
Kind: replication.FilterItemKindLabel,
|
||||||
}: true,
|
}: true,
|
||||||
&Filter{
|
{
|
||||||
Kind: replication.FilterItemKindLabel,
|
Kind: replication.FilterItemKindLabel,
|
||||||
Value: "",
|
Value: "",
|
||||||
}: true,
|
}: true,
|
||||||
&Filter{
|
{
|
||||||
Kind: replication.FilterItemKindLabel,
|
Kind: replication.FilterItemKindLabel,
|
||||||
Value: 1.2,
|
Value: 1.2,
|
||||||
}: true,
|
}: true,
|
||||||
&Filter{
|
{
|
||||||
Kind: replication.FilterItemKindLabel,
|
Kind: replication.FilterItemKindLabel,
|
||||||
Value: -1,
|
Value: -1,
|
||||||
}: true,
|
}: true,
|
||||||
&Filter{
|
{
|
||||||
Kind: replication.FilterItemKindLabel,
|
Kind: replication.FilterItemKindLabel,
|
||||||
Value: 1,
|
Value: 1,
|
||||||
}: true,
|
}: true,
|
||||||
|
@ -18,20 +18,20 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/astaxie/beego/validation"
|
"github.com/astaxie/beego/validation"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidOfTrigger(t *testing.T) {
|
func TestValidOfTrigger(t *testing.T) {
|
||||||
cases := map[*Trigger]bool{
|
cases := map[*Trigger]bool{
|
||||||
&Trigger{}: true,
|
{}: true,
|
||||||
&Trigger{
|
{
|
||||||
Kind: "invalid_kind",
|
Kind: "invalid_kind",
|
||||||
}: true,
|
}: true,
|
||||||
&Trigger{
|
{
|
||||||
Kind: replication.TriggerKindImmediate,
|
Kind: replication.TriggerKindImmediate,
|
||||||
}: false,
|
}: false,
|
||||||
&Trigger{
|
{
|
||||||
Kind: replication.TriggerKindSchedule,
|
Kind: replication.TriggerKindSchedule,
|
||||||
}: true,
|
}: true,
|
||||||
}
|
}
|
||||||
@ -45,24 +45,24 @@ func TestValidOfTrigger(t *testing.T) {
|
|||||||
|
|
||||||
func TestValidOfScheduleParam(t *testing.T) {
|
func TestValidOfScheduleParam(t *testing.T) {
|
||||||
cases := map[*ScheduleParam]bool{
|
cases := map[*ScheduleParam]bool{
|
||||||
&ScheduleParam{}: true,
|
{}: true,
|
||||||
&ScheduleParam{
|
{
|
||||||
Type: "invalid_type",
|
Type: "invalid_type",
|
||||||
}: true,
|
}: true,
|
||||||
&ScheduleParam{
|
{
|
||||||
Type: replication.TriggerScheduleDaily,
|
Type: replication.TriggerScheduleDaily,
|
||||||
Offtime: 3600*24 + 1,
|
Offtime: 3600*24 + 1,
|
||||||
}: true,
|
}: true,
|
||||||
&ScheduleParam{
|
{
|
||||||
Type: replication.TriggerScheduleDaily,
|
Type: replication.TriggerScheduleDaily,
|
||||||
Offtime: 3600 * 2,
|
Offtime: 3600 * 2,
|
||||||
}: false,
|
}: false,
|
||||||
&ScheduleParam{
|
{
|
||||||
Type: replication.TriggerScheduleWeekly,
|
Type: replication.TriggerScheduleWeekly,
|
||||||
Weekday: 0,
|
Weekday: 0,
|
||||||
Offtime: 3600 * 2,
|
Offtime: 3600 * 2,
|
||||||
}: true,
|
}: true,
|
||||||
&ScheduleParam{
|
{
|
||||||
Type: replication.TriggerScheduleWeekly,
|
Type: replication.TriggerScheduleWeekly,
|
||||||
Weekday: 7,
|
Weekday: 7,
|
||||||
Offtime: 3600 * 2,
|
Offtime: 3600 * 2,
|
||||||
|
@ -18,9 +18,9 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConvertToPersistModel(t *testing.T) {
|
func TestConvertToPersistModel(t *testing.T) {
|
||||||
@ -31,7 +31,7 @@ func TestConvertToPersistModel(t *testing.T) {
|
|||||||
Kind: "trigger_kind",
|
Kind: "trigger_kind",
|
||||||
}
|
}
|
||||||
filters := []models.Filter{
|
filters := []models.Filter{
|
||||||
models.Filter{
|
{
|
||||||
Kind: "filter_kind",
|
Kind: "filter_kind",
|
||||||
Pattern: "filter_pattern",
|
Pattern: "filter_pattern",
|
||||||
},
|
},
|
||||||
|
@ -17,10 +17,10 @@ package source
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuild(t *testing.T) {
|
func TestBuild(t *testing.T) {
|
||||||
@ -41,11 +41,11 @@ func TestDoFilter(t *testing.T) {
|
|||||||
filters := []Filter{projectFilter, repositoryFilter}
|
filters := []Filter{projectFilter, repositoryFilter}
|
||||||
|
|
||||||
items := []models.FilterItem{
|
items := []models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindProject,
|
Kind: replication.FilterItemKindProject,
|
||||||
Value: "library",
|
Value: "library",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindProject,
|
Kind: replication.FilterItemKindProject,
|
||||||
Value: "test",
|
Value: "test",
|
||||||
},
|
},
|
||||||
@ -53,7 +53,7 @@ func TestDoFilter(t *testing.T) {
|
|||||||
chain := NewDefaultFilterChain(filters)
|
chain := NewDefaultFilterChain(filters)
|
||||||
items = chain.DoFilter(items)
|
items = chain.DoFilter(items)
|
||||||
assert.EqualValues(t, []models.FilterItem{
|
assert.EqualValues(t, []models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Value: "library/ubuntu",
|
Value: "library/ubuntu",
|
||||||
},
|
},
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInitOfLabelFilter(t *testing.T) {
|
func TestInitOfLabelFilter(t *testing.T) {
|
||||||
@ -38,7 +38,7 @@ func TestDoFilterOfLabelFilter(t *testing.T) {
|
|||||||
test.InitDatabaseFromEnv()
|
test.InitDatabaseFromEnv()
|
||||||
filter := NewLabelFilter(1)
|
filter := NewLabelFilter(1)
|
||||||
items := []models.FilterItem{
|
items := []models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/hello-world:latest",
|
Value: "library/hello-world:latest",
|
||||||
},
|
},
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
package source
|
package source
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -34,21 +34,21 @@ func TestPatternFilterGetConvertor(t *testing.T) {
|
|||||||
|
|
||||||
func TestPatternFilterDoFilter(t *testing.T) {
|
func TestPatternFilterDoFilter(t *testing.T) {
|
||||||
items := []models.FilterItem{
|
items := []models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindProject,
|
Kind: replication.FilterItemKindProject,
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/ubuntu:release-14.04",
|
Value: "library/ubuntu:release-14.04",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/ubuntu:release-16.04",
|
Value: "library/ubuntu:release-16.04",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/ubuntu:test",
|
Value: "library/ubuntu:test",
|
||||||
},
|
},
|
||||||
|
@ -17,31 +17,31 @@ package source
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepositoryConvert(t *testing.T) {
|
func TestRepositoryConvert(t *testing.T) {
|
||||||
items := []models.FilterItem{
|
items := []models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindProject,
|
Kind: replication.FilterItemKindProject,
|
||||||
Value: "library",
|
Value: "library",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected := []models.FilterItem{
|
expected := []models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Value: "library/ubuntu",
|
Value: "library/ubuntu",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Value: "library/centos",
|
Value: "library/centos",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -66,10 +66,10 @@ func (f *fakeRegistryAdaptor) GetNamespace(name string) models.Namespace {
|
|||||||
|
|
||||||
func (f *fakeRegistryAdaptor) GetRepositories(namespace string) []models.Repository {
|
func (f *fakeRegistryAdaptor) GetRepositories(namespace string) []models.Repository {
|
||||||
return []models.Repository{
|
return []models.Repository{
|
||||||
models.Repository{
|
{
|
||||||
Name: "library/ubuntu",
|
Name: "library/ubuntu",
|
||||||
},
|
},
|
||||||
models.Repository{
|
{
|
||||||
Name: "library/centos",
|
Name: "library/centos",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -81,10 +81,10 @@ func (f *fakeRegistryAdaptor) GetRepository(name string, namespace string) model
|
|||||||
|
|
||||||
func (f *fakeRegistryAdaptor) GetTags(repositoryName string, namespace string) []models.Tag {
|
func (f *fakeRegistryAdaptor) GetTags(repositoryName string, namespace string) []models.Tag {
|
||||||
return []models.Tag{
|
return []models.Tag{
|
||||||
models.Tag{
|
{
|
||||||
Name: "14.04",
|
Name: "14.04",
|
||||||
},
|
},
|
||||||
models.Tag{
|
{
|
||||||
Name: "16.04",
|
Name: "16.04",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,10 @@ package source
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
"github.com/goharbor/harbor/src/replication/registry"
|
"github.com/goharbor/harbor/src/replication/registry"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInitOfRepositoryFilter(t *testing.T) {
|
func TestInitOfRepositoryFilter(t *testing.T) {
|
||||||
@ -37,7 +37,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) {
|
|||||||
// invalid filter item type
|
// invalid filter item type
|
||||||
filter := NewRepositoryFilter("", ®istry.HarborAdaptor{})
|
filter := NewRepositoryFilter("", ®istry.HarborAdaptor{})
|
||||||
items := filter.DoFilter([]models.FilterItem{
|
items := filter.DoFilter([]models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: "invalid_type",
|
Kind: "invalid_type",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -46,7 +46,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) {
|
|||||||
// empty pattern
|
// empty pattern
|
||||||
filter = NewRepositoryFilter("", ®istry.HarborAdaptor{})
|
filter = NewRepositoryFilter("", ®istry.HarborAdaptor{})
|
||||||
items = filter.DoFilter([]models.FilterItem{
|
items = filter.DoFilter([]models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Value: "library/hello-world",
|
Value: "library/hello-world",
|
||||||
},
|
},
|
||||||
@ -56,7 +56,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) {
|
|||||||
// non-empty pattern
|
// non-empty pattern
|
||||||
filter = NewRepositoryFilter("*", ®istry.HarborAdaptor{})
|
filter = NewRepositoryFilter("*", ®istry.HarborAdaptor{})
|
||||||
items = filter.DoFilter([]models.FilterItem{
|
items = filter.DoFilter([]models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/hello-world",
|
Value: "library/hello-world",
|
||||||
},
|
},
|
||||||
@ -66,7 +66,7 @@ func TestDoFilterOfRepositoryFilter(t *testing.T) {
|
|||||||
// non-empty pattern
|
// non-empty pattern
|
||||||
filter = NewRepositoryFilter("*", ®istry.HarborAdaptor{})
|
filter = NewRepositoryFilter("*", ®istry.HarborAdaptor{})
|
||||||
items = filter.DoFilter([]models.FilterItem{
|
items = filter.DoFilter([]models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/hello-world:latest",
|
Value: "library/hello-world:latest",
|
||||||
},
|
},
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
package source
|
package source
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -34,25 +34,25 @@ func TestTagCombinationFilterGetConvertor(t *testing.T) {
|
|||||||
|
|
||||||
func TestTagCombinationFilterDoFilter(t *testing.T) {
|
func TestTagCombinationFilterDoFilter(t *testing.T) {
|
||||||
items := []models.FilterItem{
|
items := []models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindProject,
|
Kind: replication.FilterItemKindProject,
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/ubuntu:invalid_tag:latest",
|
Value: "library/ubuntu:invalid_tag:latest",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/ubuntu:14.04",
|
Value: "library/ubuntu:14.04",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/ubuntu:16.04",
|
Value: "library/ubuntu:16.04",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/centos:7",
|
Value: "library/centos:7",
|
||||||
},
|
},
|
||||||
|
@ -17,31 +17,31 @@ package source
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTagConvert(t *testing.T) {
|
func TestTagConvert(t *testing.T) {
|
||||||
items := []models.FilterItem{
|
items := []models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Value: "library/ubuntu",
|
Value: "library/ubuntu",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindProject,
|
Kind: replication.FilterItemKindProject,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
expected := []models.FilterItem{
|
expected := []models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/ubuntu:14.04",
|
Value: "library/ubuntu:14.04",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/ubuntu:16.04",
|
Value: "library/ubuntu:16.04",
|
||||||
},
|
},
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindProject,
|
Kind: replication.FilterItemKindProject,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,10 @@ package source
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
"github.com/goharbor/harbor/src/replication/registry"
|
"github.com/goharbor/harbor/src/replication/registry"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInitOfTagFilter(t *testing.T) {
|
func TestInitOfTagFilter(t *testing.T) {
|
||||||
@ -37,7 +37,7 @@ func TestDoFilterOfTagFilter(t *testing.T) {
|
|||||||
// invalid filter item type
|
// invalid filter item type
|
||||||
filter := NewTagFilter("", ®istry.HarborAdaptor{})
|
filter := NewTagFilter("", ®istry.HarborAdaptor{})
|
||||||
items := filter.DoFilter([]models.FilterItem{
|
items := filter.DoFilter([]models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: "invalid_type",
|
Kind: "invalid_type",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -46,7 +46,7 @@ func TestDoFilterOfTagFilter(t *testing.T) {
|
|||||||
// empty pattern
|
// empty pattern
|
||||||
filter = NewTagFilter("", ®istry.HarborAdaptor{})
|
filter = NewTagFilter("", ®istry.HarborAdaptor{})
|
||||||
items = filter.DoFilter([]models.FilterItem{
|
items = filter.DoFilter([]models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/hello-world:latest",
|
Value: "library/hello-world:latest",
|
||||||
},
|
},
|
||||||
@ -56,7 +56,7 @@ func TestDoFilterOfTagFilter(t *testing.T) {
|
|||||||
// non-empty pattern
|
// non-empty pattern
|
||||||
filter = NewTagFilter("l*t", ®istry.HarborAdaptor{})
|
filter = NewTagFilter("l*t", ®istry.HarborAdaptor{})
|
||||||
items = filter.DoFilter([]models.FilterItem{
|
items = filter.DoFilter([]models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/hello-world:latest",
|
Value: "library/hello-world:latest",
|
||||||
},
|
},
|
||||||
@ -66,7 +66,7 @@ func TestDoFilterOfTagFilter(t *testing.T) {
|
|||||||
// non-empty pattern
|
// non-empty pattern
|
||||||
filter = NewTagFilter("lates?", ®istry.HarborAdaptor{})
|
filter = NewTagFilter("lates?", ®istry.HarborAdaptor{})
|
||||||
items = filter.DoFilter([]models.FilterItem{
|
items = filter.DoFilter([]models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/hello-world:latest",
|
Value: "library/hello-world:latest",
|
||||||
},
|
},
|
||||||
@ -76,7 +76,7 @@ func TestDoFilterOfTagFilter(t *testing.T) {
|
|||||||
// non-empty pattern
|
// non-empty pattern
|
||||||
filter = NewTagFilter("latest?", ®istry.HarborAdaptor{})
|
filter = NewTagFilter("latest?", ®istry.HarborAdaptor{})
|
||||||
items = filter.DoFilter([]models.FilterItem{
|
items = filter.DoFilter([]models.FilterItem{
|
||||||
models.FilterItem{
|
{
|
||||||
Kind: replication.FilterItemKindTag,
|
Kind: replication.FilterItemKindTag,
|
||||||
Value: "library/hello-world:latest",
|
Value: "library/hello-world:latest",
|
||||||
},
|
},
|
||||||
|
@ -17,11 +17,11 @@ package trigger
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestKindOfImmediateTrigger(t *testing.T) {
|
func TestKindOfImmediateTrigger(t *testing.T) {
|
||||||
|
@ -17,12 +17,12 @@ package trigger
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
"github.com/goharbor/harbor/src/replication/models"
|
"github.com/goharbor/harbor/src/replication/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateTrigger(t *testing.T) {
|
func TestCreateTrigger(t *testing.T) {
|
||||||
|
@ -17,8 +17,8 @@ package trigger
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestKindOfScheduleTrigger(t *testing.T) {
|
func TestKindOfScheduleTrigger(t *testing.T) {
|
||||||
|
@ -17,10 +17,10 @@ package trigger
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMethodsOfWatchList(t *testing.T) {
|
func TestMethodsOfWatchList(t *testing.T) {
|
||||||
|
@ -28,12 +28,12 @@ import (
|
|||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/dghubble/sling"
|
"github.com/dghubble/sling"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/dao/project"
|
"github.com/goharbor/harbor/src/common/dao/project"
|
||||||
common_http "github.com/goharbor/harbor/src/common/http"
|
common_http "github.com/goharbor/harbor/src/common/http"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -228,7 +228,7 @@ func (msc *mockSecurityContext) HasAllPerm(projectIDOrName interface{}) bool {
|
|||||||
|
|
||||||
//Get current user's all project
|
//Get current user's all project
|
||||||
func (msc *mockSecurityContext) GetMyProjects() ([]*models.Project, error) {
|
func (msc *mockSecurityContext) GetMyProjects() ([]*models.Project, error) {
|
||||||
return []*models.Project{&models.Project{ProjectID: 0, Name: "repo1"}}, nil
|
return []*models.Project{{ProjectID: 0, Name: "repo1"}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get user's role in provided project
|
//Get user's role in provided project
|
||||||
|
@ -18,9 +18,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/ui/config"
|
"github.com/goharbor/harbor/src/ui/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetConfig(t *testing.T) {
|
func TestGetConfig(t *testing.T) {
|
||||||
|
@ -20,13 +20,13 @@ import (
|
|||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
rep_models "github.com/goharbor/harbor/src/replication/models"
|
rep_models "github.com/goharbor/harbor/src/replication/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -46,7 +46,7 @@ func TestLabelAPIPost(t *testing.T) {
|
|||||||
|
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -55,7 +55,7 @@ func TestLabelAPIPost(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 400
|
// 400
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -66,7 +66,7 @@ func TestLabelAPIPost(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 403 non-sysadmin try to create global label
|
// 403 non-sysadmin try to create global label
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -80,7 +80,7 @@ func TestLabelAPIPost(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 403 non-member user try to create project label
|
// 403 non-member user try to create project label
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -95,7 +95,7 @@ func TestLabelAPIPost(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 403 developer try to create project label
|
// 403 developer try to create project label
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -110,7 +110,7 @@ func TestLabelAPIPost(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 404 non-exist project
|
// 404 non-exist project
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -125,7 +125,7 @@ func TestLabelAPIPost(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -141,7 +141,7 @@ func TestLabelAPIPost(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 409
|
// 409
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -162,7 +162,7 @@ func TestLabelAPIPost(t *testing.T) {
|
|||||||
func TestLabelAPIGet(t *testing.T) {
|
func TestLabelAPIGet(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 400
|
// 400
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 0),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 0),
|
||||||
@ -171,7 +171,7 @@ func TestLabelAPIGet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 1000),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 1000),
|
||||||
@ -180,7 +180,7 @@ func TestLabelAPIGet(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -194,7 +194,7 @@ func TestLabelAPIGet(t *testing.T) {
|
|||||||
func TestLabelAPIList(t *testing.T) {
|
func TestLabelAPIList(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 400 no scope query string
|
// 400 no scope query string
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -203,7 +203,7 @@ func TestLabelAPIList(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 400 invalid scope
|
// 400 invalid scope
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -217,7 +217,7 @@ func TestLabelAPIList(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 400 invalid project_id
|
// 400 invalid project_id
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: labelAPIBasePath,
|
url: labelAPIBasePath,
|
||||||
@ -272,7 +272,7 @@ func TestLabelAPIList(t *testing.T) {
|
|||||||
func TestLabelAPIPut(t *testing.T) {
|
func TestLabelAPIPut(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -281,7 +281,7 @@ func TestLabelAPIPut(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 400
|
// 400
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 0),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 0),
|
||||||
@ -291,7 +291,7 @@ func TestLabelAPIPut(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 10000),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 10000),
|
||||||
@ -301,7 +301,7 @@ func TestLabelAPIPut(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 403 non-member user
|
// 403 non-member user
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -311,7 +311,7 @@ func TestLabelAPIPut(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 403 developer
|
// 403 developer
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -321,7 +321,7 @@ func TestLabelAPIPut(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 400
|
// 400
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -336,7 +336,7 @@ func TestLabelAPIPut(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -365,7 +365,7 @@ func TestLabelAPIPut(t *testing.T) {
|
|||||||
func TestLabelAPIDelete(t *testing.T) {
|
func TestLabelAPIDelete(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -374,7 +374,7 @@ func TestLabelAPIDelete(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 400
|
// 400
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 0),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 0),
|
||||||
@ -384,7 +384,7 @@ func TestLabelAPIDelete(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 10000),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, 10000),
|
||||||
@ -394,7 +394,7 @@ func TestLabelAPIDelete(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 403 non-member user
|
// 403 non-member user
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -404,7 +404,7 @@ func TestLabelAPIDelete(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 403 developer
|
// 403 developer
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -414,7 +414,7 @@ func TestLabelAPIDelete(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -424,7 +424,7 @@ func TestLabelAPIDelete(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
url: fmt.Sprintf("%s/%d", labelAPIBasePath, labelID),
|
||||||
@ -477,7 +477,7 @@ func TestListResources(t *testing.T) {
|
|||||||
|
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, globalLabelID),
|
url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, globalLabelID),
|
||||||
@ -485,7 +485,7 @@ func TestListResources(t *testing.T) {
|
|||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, 10000),
|
url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, 10000),
|
||||||
@ -494,7 +494,7 @@ func TestListResources(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 403: global level label
|
// 403: global level label
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, globalLabelID),
|
url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, globalLabelID),
|
||||||
@ -503,7 +503,7 @@ func TestListResources(t *testing.T) {
|
|||||||
code: http.StatusForbidden,
|
code: http.StatusForbidden,
|
||||||
},
|
},
|
||||||
// 403: project level label
|
// 403: project level label
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, projectLabelID),
|
url: fmt.Sprintf("%s/%d/resources", labelAPIBasePath, projectLabelID),
|
||||||
|
@ -9,14 +9,14 @@ import (
|
|||||||
|
|
||||||
func TestLDAPPing(t *testing.T) {
|
func TestLDAPPing(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: "/api/ldap/ping",
|
url: "/api/ldap/ping",
|
||||||
},
|
},
|
||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: "/api/ldap/ping",
|
url: "/api/ldap/ping",
|
||||||
@ -24,7 +24,7 @@ func TestLDAPPing(t *testing.T) {
|
|||||||
},
|
},
|
||||||
code: http.StatusOK,
|
code: http.StatusOK,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: "/api/ldap/ping",
|
url: "/api/ldap/ping",
|
||||||
@ -47,14 +47,14 @@ func TestLDAPPing(t *testing.T) {
|
|||||||
|
|
||||||
func TestLDAPUserSearch(t *testing.T) {
|
func TestLDAPUserSearch(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/ldap/users/search?username=mike",
|
url: "/api/ldap/users/search?username=mike",
|
||||||
},
|
},
|
||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/ldap/users/search?username=mike",
|
url: "/api/ldap/users/search?username=mike",
|
||||||
@ -68,14 +68,14 @@ func TestLDAPUserSearch(t *testing.T) {
|
|||||||
|
|
||||||
func TestLDAPGroupSearch(t *testing.T) {
|
func TestLDAPGroupSearch(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/ldap/groups/search?groupname=harbor_users",
|
url: "/api/ldap/groups/search?groupname=harbor_users",
|
||||||
},
|
},
|
||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/ldap/groups/search?groupname=harbor_users",
|
url: "/api/ldap/groups/search?groupname=harbor_users",
|
||||||
@ -89,14 +89,14 @@ func TestLDAPGroupSearch(t *testing.T) {
|
|||||||
|
|
||||||
func TestLDAPGroupSearchWithDN(t *testing.T) {
|
func TestLDAPGroupSearchWithDN(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/ldap/groups/search?groupdn=cn=harbor_users,ou=groups,dc=example,dc=com",
|
url: "/api/ldap/groups/search?groupdn=cn=harbor_users,ou=groups,dc=example,dc=com",
|
||||||
},
|
},
|
||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/ldap/groups/search?groupname=cn=harbor_users,ou=groups,dc=example,dc=com",
|
url: "/api/ldap/groups/search?groupname=cn=harbor_users,ou=groups,dc=example,dc=com",
|
||||||
@ -110,7 +110,7 @@ func TestLDAPGroupSearchWithDN(t *testing.T) {
|
|||||||
|
|
||||||
func TestLDAPImportUser(t *testing.T) {
|
func TestLDAPImportUser(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: "/api/ldap/users/import",
|
url: "/api/ldap/users/import",
|
||||||
@ -120,7 +120,7 @@ func TestLDAPImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: "/api/ldap/users/import",
|
url: "/api/ldap/users/import",
|
||||||
|
@ -19,10 +19,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLogGet(t *testing.T) {
|
func TestLogGet(t *testing.T) {
|
||||||
|
@ -18,9 +18,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestValidateProjectMetadata(t *testing.T) {
|
func TestValidateProjectMetadata(t *testing.T) {
|
||||||
|
@ -24,11 +24,11 @@ import (
|
|||||||
|
|
||||||
"github.com/goharbor/harbor/src/chartserver"
|
"github.com/goharbor/harbor/src/chartserver"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/tests/apitests/apilib"
|
"github.com/goharbor/harbor/tests/apitests/apilib"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var addProject *apilib.ProjectReq
|
var addProject *apilib.ProjectReq
|
||||||
|
@ -27,7 +27,7 @@ import (
|
|||||||
func TestProjectMemberAPI_Get(t *testing.T) {
|
func TestProjectMemberAPI_Get(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/projects/1/members",
|
url: "/api/projects/1/members",
|
||||||
@ -35,7 +35,7 @@ func TestProjectMemberAPI_Get(t *testing.T) {
|
|||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
//200
|
//200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/projects/1/members",
|
url: "/api/projects/1/members",
|
||||||
@ -44,7 +44,7 @@ func TestProjectMemberAPI_Get(t *testing.T) {
|
|||||||
code: http.StatusOK,
|
code: http.StatusOK,
|
||||||
},
|
},
|
||||||
//400
|
//400
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/projects/0/members",
|
url: "/api/projects/0/members",
|
||||||
@ -53,7 +53,7 @@ func TestProjectMemberAPI_Get(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/projects/1/members/121",
|
url: "/api/projects/1/members/121",
|
||||||
@ -62,7 +62,7 @@ func TestProjectMemberAPI_Get(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/projects/99999/members/121",
|
url: "/api/projects/99999/members/121",
|
||||||
@ -87,7 +87,7 @@ func TestProjectMemberAPI_Post(t *testing.T) {
|
|||||||
|
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: "/api/projects/1/members",
|
url: "/api/projects/1/members",
|
||||||
@ -100,7 +100,7 @@ func TestProjectMemberAPI_Post(t *testing.T) {
|
|||||||
},
|
},
|
||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: "/api/projects/1/members",
|
url: "/api/projects/1/members",
|
||||||
@ -114,7 +114,7 @@ func TestProjectMemberAPI_Post(t *testing.T) {
|
|||||||
},
|
},
|
||||||
code: http.StatusCreated,
|
code: http.StatusCreated,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: "/api/projects/1/members",
|
url: "/api/projects/1/members",
|
||||||
@ -128,7 +128,7 @@ func TestProjectMemberAPI_Post(t *testing.T) {
|
|||||||
},
|
},
|
||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: "/api/projects/1/members",
|
url: "/api/projects/1/members",
|
||||||
@ -142,7 +142,7 @@ func TestProjectMemberAPI_Post(t *testing.T) {
|
|||||||
},
|
},
|
||||||
code: http.StatusInternalServerError,
|
code: http.StatusInternalServerError,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/projects/1/members?entityname=restuser",
|
url: "/api/projects/1/members?entityname=restuser",
|
||||||
@ -150,7 +150,7 @@ func TestProjectMemberAPI_Post(t *testing.T) {
|
|||||||
},
|
},
|
||||||
code: http.StatusOK,
|
code: http.StatusOK,
|
||||||
},
|
},
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: "/api/projects/1/members",
|
url: "/api/projects/1/members",
|
||||||
@ -187,7 +187,7 @@ func TestProjectMemberAPI_PutAndDelete(t *testing.T) {
|
|||||||
badURL := fmt.Sprintf("/api/projects/1/members/%v", 0)
|
badURL := fmt.Sprintf("/api/projects/1/members/%v", 0)
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: URL,
|
url: URL,
|
||||||
@ -198,7 +198,7 @@ func TestProjectMemberAPI_PutAndDelete(t *testing.T) {
|
|||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: URL,
|
url: URL,
|
||||||
@ -210,7 +210,7 @@ func TestProjectMemberAPI_PutAndDelete(t *testing.T) {
|
|||||||
code: http.StatusOK,
|
code: http.StatusOK,
|
||||||
},
|
},
|
||||||
// 400
|
// 400
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: badURL,
|
url: badURL,
|
||||||
@ -222,7 +222,7 @@ func TestProjectMemberAPI_PutAndDelete(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 400
|
// 400
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: URL,
|
url: URL,
|
||||||
@ -234,7 +234,7 @@ func TestProjectMemberAPI_PutAndDelete(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: URL,
|
url: URL,
|
||||||
|
@ -3,8 +3,8 @@ package api
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/tests/apitests/apilib"
|
"github.com/goharbor/harbor/tests/apitests/apilib"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var adminJob001 apilib.GCReq
|
var adminJob001 apilib.GCReq
|
||||||
|
@ -21,14 +21,14 @@ import (
|
|||||||
|
|
||||||
"github.com/goharbor/harbor/src/common/dao/project"
|
"github.com/goharbor/harbor/src/common/dao/project"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
rep_models "github.com/goharbor/harbor/src/replication/models"
|
rep_models "github.com/goharbor/harbor/src/replication/models"
|
||||||
api_models "github.com/goharbor/harbor/src/ui/api/models"
|
api_models "github.com/goharbor/harbor/src/ui/api/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -63,7 +63,7 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
|
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
@ -71,7 +71,7 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
// 403
|
// 403
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
@ -81,7 +81,7 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 400, invalid name
|
// 400, invalid name
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
@ -91,7 +91,7 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 400, invalid projects
|
// 400, invalid projects
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
@ -103,14 +103,14 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 400, invalid targets
|
// 400, invalid targets
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
bodyJSON: &api_models.ReplicationPolicy{
|
bodyJSON: &api_models.ReplicationPolicy{
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Projects: []*models.Project{
|
Projects: []*models.Project{
|
||||||
&models.Project{
|
{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -120,24 +120,24 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 400, invalid filters
|
// 400, invalid filters
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
bodyJSON: &api_models.ReplicationPolicy{
|
bodyJSON: &api_models.ReplicationPolicy{
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Projects: []*models.Project{
|
Projects: []*models.Project{
|
||||||
&models.Project{
|
{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: []*models.RepTarget{
|
Targets: []*models.RepTarget{
|
||||||
&models.RepTarget{
|
{
|
||||||
ID: targetID,
|
ID: targetID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Filters: []rep_models.Filter{
|
Filters: []rep_models.Filter{
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: "invalid_filter_kind",
|
Kind: "invalid_filter_kind",
|
||||||
Pattern: "",
|
Pattern: "",
|
||||||
},
|
},
|
||||||
@ -148,24 +148,24 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 400, invalid trigger
|
// 400, invalid trigger
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
bodyJSON: &api_models.ReplicationPolicy{
|
bodyJSON: &api_models.ReplicationPolicy{
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Projects: []*models.Project{
|
Projects: []*models.Project{
|
||||||
&models.Project{
|
{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: []*models.RepTarget{
|
Targets: []*models.RepTarget{
|
||||||
&models.RepTarget{
|
{
|
||||||
ID: targetID,
|
ID: targetID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Filters: []rep_models.Filter{
|
Filters: []rep_models.Filter{
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Pattern: "*",
|
Pattern: "*",
|
||||||
},
|
},
|
||||||
@ -179,24 +179,24 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 404, project not found
|
// 404, project not found
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
bodyJSON: &api_models.ReplicationPolicy{
|
bodyJSON: &api_models.ReplicationPolicy{
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Projects: []*models.Project{
|
Projects: []*models.Project{
|
||||||
&models.Project{
|
{
|
||||||
ProjectID: 10000,
|
ProjectID: 10000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: []*models.RepTarget{
|
Targets: []*models.RepTarget{
|
||||||
&models.RepTarget{
|
{
|
||||||
ID: targetID,
|
ID: targetID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Filters: []rep_models.Filter{
|
Filters: []rep_models.Filter{
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Pattern: "*",
|
Pattern: "*",
|
||||||
},
|
},
|
||||||
@ -210,24 +210,24 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 404, target not found
|
// 404, target not found
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
bodyJSON: &api_models.ReplicationPolicy{
|
bodyJSON: &api_models.ReplicationPolicy{
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Projects: []*models.Project{
|
Projects: []*models.Project{
|
||||||
&models.Project{
|
{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: []*models.RepTarget{
|
Targets: []*models.RepTarget{
|
||||||
&models.RepTarget{
|
{
|
||||||
ID: 10000,
|
ID: 10000,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Filters: []rep_models.Filter{
|
Filters: []rep_models.Filter{
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Pattern: "*",
|
Pattern: "*",
|
||||||
},
|
},
|
||||||
@ -241,28 +241,28 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 404, label not found
|
// 404, label not found
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
bodyJSON: &api_models.ReplicationPolicy{
|
bodyJSON: &api_models.ReplicationPolicy{
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Projects: []*models.Project{
|
Projects: []*models.Project{
|
||||||
&models.Project{
|
{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: []*models.RepTarget{
|
Targets: []*models.RepTarget{
|
||||||
&models.RepTarget{
|
{
|
||||||
ID: targetID,
|
ID: targetID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Filters: []rep_models.Filter{
|
Filters: []rep_models.Filter{
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Pattern: "*",
|
Pattern: "*",
|
||||||
},
|
},
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindLabel,
|
Kind: replication.FilterItemKindLabel,
|
||||||
Value: 10000,
|
Value: 10000,
|
||||||
},
|
},
|
||||||
@ -276,28 +276,28 @@ func TestRepPolicyAPIPost(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 201
|
// 201
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: repPolicyAPIBasePath,
|
url: repPolicyAPIBasePath,
|
||||||
bodyJSON: &api_models.ReplicationPolicy{
|
bodyJSON: &api_models.ReplicationPolicy{
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Projects: []*models.Project{
|
Projects: []*models.Project{
|
||||||
&models.Project{
|
{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: []*models.RepTarget{
|
Targets: []*models.RepTarget{
|
||||||
&models.RepTarget{
|
{
|
||||||
ID: targetID,
|
ID: targetID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Filters: []rep_models.Filter{
|
Filters: []rep_models.Filter{
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Pattern: "*",
|
Pattern: "*",
|
||||||
},
|
},
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindLabel,
|
Kind: replication.FilterItemKindLabel,
|
||||||
Value: labelID2,
|
Value: labelID2,
|
||||||
},
|
},
|
||||||
@ -320,7 +320,7 @@ func TestRepPolicyAPIGet(t *testing.T) {
|
|||||||
|
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, 10000),
|
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, 10000),
|
||||||
@ -329,7 +329,7 @@ func TestRepPolicyAPIGet(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID),
|
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID),
|
||||||
@ -512,7 +512,7 @@ func TestRepPolicyAPIList(t *testing.T) {
|
|||||||
func TestRepPolicyAPIPut(t *testing.T) {
|
func TestRepPolicyAPIPut(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, 10000),
|
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, 10000),
|
||||||
@ -521,24 +521,24 @@ func TestRepPolicyAPIPut(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 400, invalid trigger
|
// 400, invalid trigger
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID),
|
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID),
|
||||||
bodyJSON: &api_models.ReplicationPolicy{
|
bodyJSON: &api_models.ReplicationPolicy{
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Projects: []*models.Project{
|
Projects: []*models.Project{
|
||||||
&models.Project{
|
{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: []*models.RepTarget{
|
Targets: []*models.RepTarget{
|
||||||
&models.RepTarget{
|
{
|
||||||
ID: targetID,
|
ID: targetID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Filters: []rep_models.Filter{
|
Filters: []rep_models.Filter{
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Pattern: "*",
|
Pattern: "*",
|
||||||
},
|
},
|
||||||
@ -552,24 +552,24 @@ func TestRepPolicyAPIPut(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID),
|
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID),
|
||||||
bodyJSON: &api_models.ReplicationPolicy{
|
bodyJSON: &api_models.ReplicationPolicy{
|
||||||
Name: policyName,
|
Name: policyName,
|
||||||
Projects: []*models.Project{
|
Projects: []*models.Project{
|
||||||
&models.Project{
|
{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: []*models.RepTarget{
|
Targets: []*models.RepTarget{
|
||||||
&models.RepTarget{
|
{
|
||||||
ID: targetID,
|
ID: targetID,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Filters: []rep_models.Filter{
|
Filters: []rep_models.Filter{
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: replication.FilterItemKindRepository,
|
Kind: replication.FilterItemKindRepository,
|
||||||
Pattern: "*",
|
Pattern: "*",
|
||||||
},
|
},
|
||||||
@ -590,7 +590,7 @@ func TestRepPolicyAPIPut(t *testing.T) {
|
|||||||
func TestRepPolicyAPIDelete(t *testing.T) {
|
func TestRepPolicyAPIDelete(t *testing.T) {
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, 10000),
|
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, 10000),
|
||||||
@ -599,7 +599,7 @@ func TestRepPolicyAPIDelete(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID),
|
url: fmt.Sprintf("%s/%d", repPolicyAPIBasePath, policyID),
|
||||||
@ -627,7 +627,7 @@ func TestConvertToRepPolicy(t *testing.T) {
|
|||||||
Name: "policy",
|
Name: "policy",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
Filters: []rep_models.Filter{
|
Filters: []rep_models.Filter{
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: "filter_kind_01",
|
Kind: "filter_kind_01",
|
||||||
Pattern: "*",
|
Pattern: "*",
|
||||||
},
|
},
|
||||||
@ -637,13 +637,13 @@ func TestConvertToRepPolicy(t *testing.T) {
|
|||||||
Kind: "trigger_kind_01",
|
Kind: "trigger_kind_01",
|
||||||
},
|
},
|
||||||
Projects: []*models.Project{
|
Projects: []*models.Project{
|
||||||
&models.Project{
|
{
|
||||||
ProjectID: 1,
|
ProjectID: 1,
|
||||||
Name: "library",
|
Name: "library",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Targets: []*models.RepTarget{
|
Targets: []*models.RepTarget{
|
||||||
&models.RepTarget{
|
{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -653,7 +653,7 @@ func TestConvertToRepPolicy(t *testing.T) {
|
|||||||
Name: "policy",
|
Name: "policy",
|
||||||
Description: "description",
|
Description: "description",
|
||||||
Filters: []rep_models.Filter{
|
Filters: []rep_models.Filter{
|
||||||
rep_models.Filter{
|
{
|
||||||
Kind: "filter_kind_01",
|
Kind: "filter_kind_01",
|
||||||
Pattern: "*",
|
Pattern: "*",
|
||||||
},
|
},
|
||||||
|
@ -18,11 +18,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/src/replication"
|
"github.com/goharbor/harbor/src/replication"
|
||||||
api_models "github.com/goharbor/harbor/src/ui/api/models"
|
api_models "github.com/goharbor/harbor/src/ui/api/models"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -52,7 +52,7 @@ func TestReplicationAPIPost(t *testing.T) {
|
|||||||
|
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: replicationAPIBaseURL,
|
url: replicationAPIBaseURL,
|
||||||
@ -63,7 +63,7 @@ func TestReplicationAPIPost(t *testing.T) {
|
|||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: replicationAPIBaseURL,
|
url: replicationAPIBaseURL,
|
||||||
@ -75,7 +75,7 @@ func TestReplicationAPIPost(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: replicationAPIBaseURL,
|
url: replicationAPIBaseURL,
|
||||||
|
@ -19,11 +19,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -60,7 +60,7 @@ func TestAddToImage(t *testing.T) {
|
|||||||
|
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
||||||
repository, tag),
|
repository, tag),
|
||||||
@ -69,7 +69,7 @@ func TestAddToImage(t *testing.T) {
|
|||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
// 403
|
// 403
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
||||||
repository, tag),
|
repository, tag),
|
||||||
@ -79,7 +79,7 @@ func TestAddToImage(t *testing.T) {
|
|||||||
code: http.StatusForbidden,
|
code: http.StatusForbidden,
|
||||||
},
|
},
|
||||||
// 404 repository doesn't exist
|
// 404 repository doesn't exist
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
url: fmt.Sprintf("%s/library/non-exist-repo/tags/%s/labels", resourceLabelAPIBasePath, tag),
|
url: fmt.Sprintf("%s/library/non-exist-repo/tags/%s/labels", resourceLabelAPIBasePath, tag),
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
@ -88,7 +88,7 @@ func TestAddToImage(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 404 image doesn't exist
|
// 404 image doesn't exist
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
url: fmt.Sprintf("%s/%s/tags/non-exist-tag/labels", resourceLabelAPIBasePath, repository),
|
url: fmt.Sprintf("%s/%s/tags/non-exist-tag/labels", resourceLabelAPIBasePath, repository),
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
@ -97,7 +97,7 @@ func TestAddToImage(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 400
|
// 400
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath, repository, tag),
|
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath, repository, tag),
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
@ -106,7 +106,7 @@ func TestAddToImage(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 404 label doesn't exist
|
// 404 label doesn't exist
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
||||||
repository, tag),
|
repository, tag),
|
||||||
@ -121,7 +121,7 @@ func TestAddToImage(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 400 system level label
|
// 400 system level label
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
||||||
repository, tag),
|
repository, tag),
|
||||||
@ -136,7 +136,7 @@ func TestAddToImage(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 400 try to add the label of project1 to the image under project2
|
// 400 try to add the label of project1 to the image under project2
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
||||||
repository, tag),
|
repository, tag),
|
||||||
@ -151,7 +151,7 @@ func TestAddToImage(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
url: fmt.Sprintf("%s/%s/tags/%s/labels", resourceLabelAPIBasePath,
|
||||||
repository, tag),
|
repository, tag),
|
||||||
|
@ -18,11 +18,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/dao/project"
|
"github.com/goharbor/harbor/src/common/dao/project"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetRepos(t *testing.T) {
|
func TestGetRepos(t *testing.T) {
|
||||||
@ -256,7 +256,7 @@ func TestPutOfRepository(t *testing.T) {
|
|||||||
|
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: base + "non_exist_repository",
|
url: base + "non_exist_repository",
|
||||||
@ -265,7 +265,7 @@ func TestPutOfRepository(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: base + "library/hello-world",
|
url: base + "library/hello-world",
|
||||||
@ -274,7 +274,7 @@ func TestPutOfRepository(t *testing.T) {
|
|||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
// 403 non-member
|
// 403 non-member
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: base + "library/hello-world",
|
url: base + "library/hello-world",
|
||||||
@ -284,7 +284,7 @@ func TestPutOfRepository(t *testing.T) {
|
|||||||
code: http.StatusForbidden,
|
code: http.StatusForbidden,
|
||||||
},
|
},
|
||||||
// 403 project guest
|
// 403 project guest
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: base + "library/hello-world",
|
url: base + "library/hello-world",
|
||||||
@ -294,7 +294,7 @@ func TestPutOfRepository(t *testing.T) {
|
|||||||
code: http.StatusForbidden,
|
code: http.StatusForbidden,
|
||||||
},
|
},
|
||||||
// 200 project developer
|
// 200 project developer
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: base + "library/hello-world",
|
url: base + "library/hello-world",
|
||||||
@ -304,7 +304,7 @@ func TestPutOfRepository(t *testing.T) {
|
|||||||
code: http.StatusOK,
|
code: http.StatusOK,
|
||||||
},
|
},
|
||||||
// 200 project admin
|
// 200 project admin
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: base + "library/hello-world",
|
url: base + "library/hello-world",
|
||||||
@ -314,7 +314,7 @@ func TestPutOfRepository(t *testing.T) {
|
|||||||
code: http.StatusOK,
|
code: http.StatusOK,
|
||||||
},
|
},
|
||||||
// 200 system admin
|
// 200 system admin
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: base + "library/hello-world",
|
url: base + "library/hello-world",
|
||||||
|
@ -21,10 +21,10 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
member "github.com/goharbor/harbor/src/common/dao/project"
|
member "github.com/goharbor/harbor/src/common/dao/project"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSearch(t *testing.T) {
|
func TestSearch(t *testing.T) {
|
||||||
|
@ -20,9 +20,9 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/goharbor/harbor/tests/apitests/apilib"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/goharbor/harbor/tests/apitests/apilib"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -18,13 +18,13 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/api"
|
"github.com/goharbor/harbor/src/common/api"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/tests/apitests/apilib"
|
"github.com/goharbor/harbor/tests/apitests/apilib"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
@ -360,7 +360,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
|||||||
|
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// unauthorized
|
// unauthorized
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: buildChangeUserPasswordURL(user01.UserID),
|
url: buildChangeUserPasswordURL(user01.UserID),
|
||||||
@ -368,7 +368,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
|||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
// 404
|
// 404
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: buildChangeUserPasswordURL(10000),
|
url: buildChangeUserPasswordURL(10000),
|
||||||
@ -380,7 +380,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
|||||||
code: http.StatusNotFound,
|
code: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
// 403, a normal user tries to change password of others
|
// 403, a normal user tries to change password of others
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: buildChangeUserPasswordURL(user02.UserID),
|
url: buildChangeUserPasswordURL(user02.UserID),
|
||||||
@ -392,7 +392,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
|||||||
code: http.StatusForbidden,
|
code: http.StatusForbidden,
|
||||||
},
|
},
|
||||||
// 400, empty old password
|
// 400, empty old password
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: buildChangeUserPasswordURL(user01.UserID),
|
url: buildChangeUserPasswordURL(user01.UserID),
|
||||||
@ -405,7 +405,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 400, empty new password
|
// 400, empty new password
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: buildChangeUserPasswordURL(user01.UserID),
|
url: buildChangeUserPasswordURL(user01.UserID),
|
||||||
@ -420,7 +420,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 403, incorrect old password
|
// 403, incorrect old password
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: buildChangeUserPasswordURL(user01.UserID),
|
url: buildChangeUserPasswordURL(user01.UserID),
|
||||||
@ -436,7 +436,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
|||||||
code: http.StatusForbidden,
|
code: http.StatusForbidden,
|
||||||
},
|
},
|
||||||
// 200, normal user change own password
|
// 200, normal user change own password
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: buildChangeUserPasswordURL(user01.UserID),
|
url: buildChangeUserPasswordURL(user01.UserID),
|
||||||
@ -453,7 +453,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
|||||||
},
|
},
|
||||||
// 400, admin user change password of others.
|
// 400, admin user change password of others.
|
||||||
// the new password is same with the old one
|
// the new password is same with the old one
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: buildChangeUserPasswordURL(user01.UserID),
|
url: buildChangeUserPasswordURL(user01.UserID),
|
||||||
@ -465,7 +465,7 @@ func TestUsersUpdatePassword(t *testing.T) {
|
|||||||
code: http.StatusBadRequest,
|
code: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
// 200, admin user change password of others
|
// 200, admin user change password of others
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: buildChangeUserPasswordURL(user01.UserID),
|
url: buildChangeUserPasswordURL(user01.UserID),
|
||||||
|
@ -44,7 +44,7 @@ func TestUserGroupAPI_GetAndDelete(t *testing.T) {
|
|||||||
defer group.DeleteUserGroup(groupID)
|
defer group.DeleteUserGroup(groupID)
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
// 401
|
// 401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: URL,
|
url: URL,
|
||||||
@ -53,7 +53,7 @@ func TestUserGroupAPI_GetAndDelete(t *testing.T) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("/api/usergroups/%d", groupID),
|
url: fmt.Sprintf("/api/usergroups/%d", groupID),
|
||||||
@ -62,7 +62,7 @@ func TestUserGroupAPI_GetAndDelete(t *testing.T) {
|
|||||||
code: http.StatusOK,
|
code: http.StatusOK,
|
||||||
},
|
},
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
url: fmt.Sprintf("/api/usergroups"),
|
url: fmt.Sprintf("/api/usergroups"),
|
||||||
@ -71,7 +71,7 @@ func TestUserGroupAPI_GetAndDelete(t *testing.T) {
|
|||||||
code: http.StatusOK,
|
code: http.StatusOK,
|
||||||
},
|
},
|
||||||
// 200
|
// 200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
url: fmt.Sprintf("/api/usergroups/%d", groupID),
|
url: fmt.Sprintf("/api/usergroups/%d", groupID),
|
||||||
@ -97,7 +97,7 @@ func TestUserGroupAPI_Post(t *testing.T) {
|
|||||||
|
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
//409
|
//409
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
url: "/api/usergroups",
|
url: "/api/usergroups",
|
||||||
@ -127,7 +127,7 @@ func TestUserGroupAPI_Put(t *testing.T) {
|
|||||||
}
|
}
|
||||||
cases := []*codeCheckingCase{
|
cases := []*codeCheckingCase{
|
||||||
//401
|
//401
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("/api/usergroups/%d", groupID),
|
url: fmt.Sprintf("/api/usergroups/%d", groupID),
|
||||||
@ -138,7 +138,7 @@ func TestUserGroupAPI_Put(t *testing.T) {
|
|||||||
code: http.StatusUnauthorized,
|
code: http.StatusUnauthorized,
|
||||||
},
|
},
|
||||||
//200
|
//200
|
||||||
&codeCheckingCase{
|
{
|
||||||
request: &testingRequest{
|
request: &testingRequest{
|
||||||
method: http.MethodPut,
|
method: http.MethodPut,
|
||||||
url: fmt.Sprintf("/api/usergroups/%d", groupID),
|
url: fmt.Sprintf("/api/usergroups/%d", groupID),
|
||||||
|
@ -17,9 +17,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var l = NewUserLock(2 * time.Second)
|
var l = NewUserLock(2 * time.Second)
|
||||||
|
@ -18,13 +18,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
utilstest "github.com/goharbor/harbor/src/common/utils/test"
|
utilstest "github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/common/utils/uaa"
|
"github.com/goharbor/harbor/src/common/utils/uaa"
|
||||||
"github.com/goharbor/harbor/src/ui/config"
|
"github.com/goharbor/harbor/src/ui/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -19,9 +19,9 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
// test functions under package ui/config
|
// test functions under package ui/config
|
||||||
|
@ -26,13 +26,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
"github.com/goharbor/harbor/src/common/utils/test"
|
"github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/ui/config"
|
"github.com/goharbor/harbor/src/ui/config"
|
||||||
"github.com/goharbor/harbor/src/ui/proxy"
|
"github.com/goharbor/harbor/src/ui/proxy"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
//const (
|
//const (
|
||||||
|
@ -20,10 +20,10 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common"
|
"github.com/goharbor/harbor/src/common"
|
||||||
utilstest "github.com/goharbor/harbor/src/common/utils/test"
|
utilstest "github.com/goharbor/harbor/src/common/utils/test"
|
||||||
"github.com/goharbor/harbor/src/ui/config"
|
"github.com/goharbor/harbor/src/ui/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReadonlyFilter(t *testing.T) {
|
func TestReadonlyFilter(t *testing.T) {
|
||||||
|
@ -58,22 +58,22 @@ var (
|
|||||||
// in the slice
|
// in the slice
|
||||||
basicAuthReqPatterns = []*pathMethod{
|
basicAuthReqPatterns = []*pathMethod{
|
||||||
// create project
|
// create project
|
||||||
&pathMethod{
|
{
|
||||||
path: "/api/projects",
|
path: "/api/projects",
|
||||||
method: http.MethodPost,
|
method: http.MethodPost,
|
||||||
},
|
},
|
||||||
// token service
|
// token service
|
||||||
&pathMethod{
|
{
|
||||||
path: "/service/token",
|
path: "/service/token",
|
||||||
method: http.MethodGet,
|
method: http.MethodGet,
|
||||||
},
|
},
|
||||||
// delete repository
|
// delete repository
|
||||||
&pathMethod{
|
{
|
||||||
path: "/api/repositories/" + reference.NameRegexp.String(),
|
path: "/api/repositories/" + reference.NameRegexp.String(),
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
},
|
},
|
||||||
// delete tag
|
// delete tag
|
||||||
&pathMethod{
|
{
|
||||||
path: "/api/repositories/" + reference.NameRegexp.String() + "/tags/" + reference.TagRegexp.String(),
|
path: "/api/repositories/" + reference.NameRegexp.String() + "/tags/" + reference.TagRegexp.String(),
|
||||||
method: http.MethodDelete,
|
method: http.MethodDelete,
|
||||||
},
|
},
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
beegoctx "github.com/astaxie/beego/context"
|
beegoctx "github.com/astaxie/beego/context"
|
||||||
"github.com/astaxie/beego/session"
|
"github.com/astaxie/beego/session"
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/goharbor/harbor/src/common/dao"
|
"github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/common/models"
|
"github.com/goharbor/harbor/src/common/models"
|
||||||
commonsecret "github.com/goharbor/harbor/src/common/secret"
|
commonsecret "github.com/goharbor/harbor/src/common/secret"
|
||||||
@ -40,6 +39,7 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/ui/config"
|
"github.com/goharbor/harbor/src/ui/config"
|
||||||
"github.com/goharbor/harbor/src/ui/promgr"
|
"github.com/goharbor/harbor/src/ui/promgr"
|
||||||
driver_local "github.com/goharbor/harbor/src/ui/promgr/pmsdriver/local"
|
driver_local "github.com/goharbor/harbor/src/ui/promgr/pmsdriver/local"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user