Merge pull request #9343 from ywk253100/191009_bug_fix

Check the existence of project before the next action
This commit is contained in:
Wang Yan 2019-10-14 11:27:34 +08:00 committed by GitHub
commit 17ad4aca55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -40,7 +40,7 @@ import (
"github.com/goharbor/harbor/src/core/config"
"github.com/goharbor/harbor/src/core/promgr"
"github.com/goharbor/harbor/src/pkg/scan/whitelist"
"github.com/opencontainers/go-digest"
digest "github.com/opencontainers/go-digest"
)
type contextKey string
@ -346,6 +346,10 @@ func (pc PmsPolicyChecker) ContentTrustEnabled(name string) bool {
log.Errorf("Unexpected error when getting the project, error: %v", err)
return true
}
if project == nil {
log.Debugf("project %s not found", name)
return false
}
return project.ContentTrustEnabled()
}

View File

@ -32,7 +32,7 @@ import (
notarytest "github.com/goharbor/harbor/src/common/utils/notary/test"
testutils "github.com/goharbor/harbor/src/common/utils/test"
"github.com/goharbor/harbor/src/core/config"
"github.com/opencontainers/go-digest"
digest "github.com/opencontainers/go-digest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -187,6 +187,9 @@ func TestPMSPolicyChecker(t *testing.T) {
assert.True(t, projectVulnerableEnabled)
assert.Equal(t, projectVulnerableSeverity, models.SevLow)
assert.Empty(t, wl.Items)
contentTrustFlag = GetPolicyChecker().ContentTrustEnabled("non_exist_project")
assert.False(t, contentTrustFlag)
}
func TestCopyResp(t *testing.T) {