mirror of
https://github.com/rancher/steve.git
synced 2025-09-15 23:08:26 +00:00
[main&2.10.3] Add schema links and resource methods for resource verb patch (#450)
* Show patch link on the API resource when patch permission is present and add patch ResourceMethod to the schema. * Added tests for new functionality and corrected disallowed method for patch
This commit is contained in:
@@ -634,6 +634,7 @@ func Test_formatterLinks(t *testing.T) {
|
||||
hasGet bool
|
||||
hasUpdate bool
|
||||
hasRemove bool
|
||||
hasPatch bool
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -935,6 +936,81 @@ func Test_formatterLinks(t *testing.T) {
|
||||
"view": "/api/v1/namespaces/example-ns/pods/example-pod",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "patch permissions",
|
||||
hasUser: true,
|
||||
permissions: &permissions{
|
||||
hasPatch: true,
|
||||
},
|
||||
schema: &types.APISchema{
|
||||
Schema: &schemas.Schema{
|
||||
ID: "example",
|
||||
Attributes: map[string]interface{}{
|
||||
"group": "apps",
|
||||
"version": "v1",
|
||||
"resource": "deployments",
|
||||
},
|
||||
},
|
||||
},
|
||||
apiObject: types.APIObject{
|
||||
ID: "example",
|
||||
Object: &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "example-deployment",
|
||||
Namespace: "example-ns",
|
||||
},
|
||||
},
|
||||
},
|
||||
currentLinks: map[string]string{
|
||||
"default": "defaultVal",
|
||||
"patch": "/v1/apps.deployments/example-ns/example-deployment",
|
||||
"view": "/apis/apps/v1/namespaces/example-ns/deployments/example-deployment",
|
||||
},
|
||||
wantLinks: map[string]string{
|
||||
"default": "defaultVal",
|
||||
"patch": "/v1/apps.deployments/example-ns/example-deployment",
|
||||
"view": "/apis/apps/v1/namespaces/example-ns/deployments/example-deployment",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "patch permissions, but blocked",
|
||||
hasUser: true,
|
||||
permissions: &permissions{
|
||||
hasPatch: true,
|
||||
},
|
||||
schema: &types.APISchema{
|
||||
Schema: &schemas.Schema{
|
||||
ID: "example",
|
||||
Attributes: map[string]interface{}{
|
||||
"group": "apps",
|
||||
"version": "v1",
|
||||
"resource": "deployments",
|
||||
"disallowMethods": map[string]bool{
|
||||
http.MethodPatch: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
apiObject: types.APIObject{
|
||||
ID: "example",
|
||||
Object: &v1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "example-deployment",
|
||||
Namespace: "example-ns",
|
||||
},
|
||||
},
|
||||
},
|
||||
currentLinks: map[string]string{
|
||||
"default": "defaultVal",
|
||||
"patch": "/v1/apps.deployments/example-ns/example-deployment",
|
||||
"view": "/apis/apps/v1/namespaces/example-ns/deployments/example-deployment",
|
||||
},
|
||||
wantLinks: map[string]string{
|
||||
"default": "defaultVal",
|
||||
"patch": "blocked",
|
||||
"view": "/apis/apps/v1/namespaces/example-ns/deployments/example-deployment",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -964,6 +1040,12 @@ func Test_formatterLinks(t *testing.T) {
|
||||
ResourceName: meta.GetName(),
|
||||
})
|
||||
}
|
||||
if test.permissions.hasPatch {
|
||||
accessSet.Add("patch", gvr.GroupResource(), accesscontrol.Access{
|
||||
Namespace: meta.GetNamespace(),
|
||||
ResourceName: meta.GetName(),
|
||||
})
|
||||
}
|
||||
asl.EXPECT().AccessFor(&defaultUserInfo).Return(&accessSet)
|
||||
} else {
|
||||
asl.EXPECT().AccessFor(&defaultUserInfo).Return(nil).AnyTimes()
|
||||
|
Reference in New Issue
Block a user