mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 04:48:26 +08:00
coverage: add failure injection framework
Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
This commit is contained in:
committed by
Ramkumar Chinchani
parent
f47c8222c2
commit
e0a1a82890
@@ -43,6 +43,7 @@ import (
|
||||
"zotregistry.io/zot/pkg/api"
|
||||
"zotregistry.io/zot/pkg/api/config"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/test"
|
||||
. "zotregistry.io/zot/test"
|
||||
)
|
||||
|
||||
@@ -2083,6 +2084,29 @@ func TestAuthorizationWithBasicAuth(t *testing.T) {
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
||||
resp, err = resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + "/v2/" + AuthorizationNamespace + "/tags/list")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
||||
Convey("Hard to reach cases", func() {
|
||||
injected := test.InjectFailure(0)
|
||||
|
||||
// get tags with read access should get 200
|
||||
conf.AccessControl.Repositories[AuthorizationNamespace].Policies[0].Actions =
|
||||
append(conf.AccessControl.Repositories[AuthorizationNamespace].Policies[0].Actions, "read")
|
||||
resp, err = resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + "/v2/" + AuthorizationNamespace + "/tags/list")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
if injected {
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusNotFound)
|
||||
} else {
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
}
|
||||
})
|
||||
|
||||
// head blob should get 200 now
|
||||
resp, err = resty.R().SetBasicAuth(username, passphrase).
|
||||
Head(baseURL + "/v2/" + AuthorizationNamespace + "/blobs/" + digest)
|
||||
@@ -2838,6 +2862,24 @@ func TestParallelRequests(t *testing.T) {
|
||||
assert.Equal(t, err, nil, "Error should be nil")
|
||||
assert.Equal(t, headResponse.StatusCode(), http.StatusNotFound, "response status code should return 404")
|
||||
|
||||
Convey("Hard to reach cases", t, func() {
|
||||
_ = test.InjectFailure(0)
|
||||
|
||||
headResponse, err := client.R().SetBasicAuth(username, passphrase).
|
||||
Head(baseURL + "/v2/" + testcase.destImageName + "/manifests/test:1.0")
|
||||
assert.Equal(t, err, nil, "Error should be nil")
|
||||
assert.Equal(t, headResponse.StatusCode(), http.StatusNotFound, "response status code should return 404")
|
||||
})
|
||||
|
||||
Convey("Hard to reach cases", t, func() {
|
||||
_ = test.InjectFailure(1)
|
||||
|
||||
headResponse, err := client.R().SetBasicAuth(username, passphrase).
|
||||
Head(baseURL + "/v2/" + testcase.destImageName + "/manifests/test:1.0")
|
||||
assert.Equal(t, err, nil, "Error should be nil")
|
||||
assert.Equal(t, headResponse.StatusCode(), http.StatusNotFound, "response status code should return 404")
|
||||
})
|
||||
|
||||
getResponse, err := client.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + "/v2/" + testcase.destImageName + "/manifests/" + manifest)
|
||||
assert.Equal(t, err, nil, "Error should be nil")
|
||||
|
||||
+4
-3
@@ -32,6 +32,7 @@ import (
|
||||
ext "zotregistry.io/zot/pkg/extensions"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/test"
|
||||
|
||||
// as required by swaggo.
|
||||
_ "zotregistry.io/zot/swagger"
|
||||
@@ -165,7 +166,7 @@ func (rh *RouteHandler) ListTags(response http.ResponseWriter, request *http.Req
|
||||
|
||||
name, ok := vars["name"]
|
||||
|
||||
if !ok || name == "" {
|
||||
if !test.Ok(ok) || name == "" {
|
||||
response.WriteHeader(http.StatusNotFound)
|
||||
|
||||
return
|
||||
@@ -287,7 +288,7 @@ func (rh *RouteHandler) CheckManifest(response http.ResponseWriter, request *htt
|
||||
vars := mux.Vars(request)
|
||||
name, ok := vars["name"]
|
||||
|
||||
if !ok || name == "" {
|
||||
if !test.Ok(ok) || name == "" {
|
||||
response.WriteHeader(http.StatusNotFound)
|
||||
|
||||
return
|
||||
@@ -296,7 +297,7 @@ func (rh *RouteHandler) CheckManifest(response http.ResponseWriter, request *htt
|
||||
imgStore := rh.getImageStore(name)
|
||||
|
||||
reference, ok := vars["reference"]
|
||||
if !ok || reference == "" {
|
||||
if !test.Ok(ok) || reference == "" {
|
||||
WriteJSON(response,
|
||||
http.StatusNotFound,
|
||||
NewErrorList(NewError(MANIFEST_INVALID, map[string]string{"reference": reference})))
|
||||
|
||||
Reference in New Issue
Block a user