Update testcase for scan tag api change

Return 202 after success
scan_summary is in a map struct
This commit is contained in:
stonezdj 2019-11-28 17:50:08 +08:00
parent 41b8e60e6a
commit 6af7d4bdf4
3 changed files with 16 additions and 8 deletions

View File

@ -135,7 +135,7 @@ func (ac *APIClient) Post(url string, data []byte) error {
}
if resp.StatusCode != http.StatusCreated &&
resp.StatusCode != http.StatusOK {
resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted {
if err := getErrorMessage(resp); err != nil {
return fmt.Errorf("%s:%s", resp.Status, err.Error())
}

View File

@ -17,6 +17,11 @@ type ImageUtil struct {
testingClient *client.APIClient
}
const (
// MimeTypeNativeReport defines the mime type for native report
MimeTypeNativeReport = "application/vnd.scanner.adapter.vuln.report.harbor+json; version=1.0"
)
//NewImageUtil : Constructor
func NewImageUtil(rootURI string, httpClient *client.APIClient) *ImageUtil {
if len(strings.TrimSpace(rootURI)) == 0 || httpClient == nil {
@ -76,8 +81,11 @@ func (iu *ImageUtil) ScanTag(repoName string, tagName string) error {
return
}
if tag.ScanOverview != nil && tag.ScanOverview.Status == "finished" {
done <- true
if tag.ScanOverview != nil {
summary, ok := tag.ScanOverview[MimeTypeNativeReport]
if ok && summary.Status == "Success" {
done <- true
}
}
}
}()
@ -86,7 +94,7 @@ func (iu *ImageUtil) ScanTag(repoName string, tagName string) error {
case <-done:
return nil
case <-time.After(20 * time.Second):
return errors.New("Scan timeout after 30 seconds")
return errors.New("Scan timeout after 20 seconds")
}
}

View File

@ -8,10 +8,10 @@ type Repository struct {
//Tag : For /api/repositories/:repo/tags
type Tag struct {
Digest string `json:"digest"`
Name string `json:"name"`
Signature map[string]interface{} `json:"signature, omitempty"`
ScanOverview *ScanOverview `json:"scan_overview, omitempty"`
Digest string `json:"digest"`
Name string `json:"name"`
Signature map[string]interface{} `json:"signature, omitempty"`
ScanOverview map[string]ScanOverview `json:"scan_overview, omitempty"`
}
//ScanOverview : For scanning