fix format of forbidden messages
Kubernetes-commit: 95738d5a0eeb179325858e52ff83ff86de6fce0b
This commit is contained in:
		
							parent
							
								
									22fed2cada
								
							
						
					
					
						commit
						e69ddb7b01
					
				|  | @ -49,7 +49,7 @@ func Forbidden(ctx request.Context, attributes authorizer.Attributes, w http.Res | |||
| 	if len(reason) == 0 { | ||||
| 		errMsg = fmt.Sprintf("%s", msg) | ||||
| 	} else { | ||||
| 		errMsg = fmt.Sprintf("%s: %q", msg, reason) | ||||
| 		errMsg = fmt.Sprintf("%s: %s", msg, reason) | ||||
| 	} | ||||
| 	gv := schema.GroupVersion{Group: attributes.GetAPIGroup(), Version: attributes.GetAPIVersion()} | ||||
| 	gr := schema.GroupResource{Group: attributes.GetAPIGroup(), Resource: attributes.GetResource()} | ||||
|  | @ -63,7 +63,7 @@ func forbiddenMessage(attributes authorizer.Attributes) string { | |||
| 	} | ||||
| 
 | ||||
| 	if !attributes.IsResourceRequest() { | ||||
| 		return fmt.Sprintf("User %q cannot %s path %q.", username, attributes.GetVerb(), attributes.GetPath()) | ||||
| 		return fmt.Sprintf("User %q cannot %s path %q", username, attributes.GetVerb(), attributes.GetPath()) | ||||
| 	} | ||||
| 
 | ||||
| 	resource := attributes.GetResource() | ||||
|  | @ -75,10 +75,10 @@ func forbiddenMessage(attributes authorizer.Attributes) string { | |||
| 	} | ||||
| 
 | ||||
| 	if ns := attributes.GetNamespace(); len(ns) > 0 { | ||||
| 		return fmt.Sprintf("User %q cannot %s %s in the namespace %q.", username, attributes.GetVerb(), resource, ns) | ||||
| 		return fmt.Sprintf("User %q cannot %s %s in the namespace %q", username, attributes.GetVerb(), resource, ns) | ||||
| 	} | ||||
| 
 | ||||
| 	return fmt.Sprintf("User %q cannot %s %s at the cluster scope.", username, attributes.GetVerb(), resource) | ||||
| 	return fmt.Sprintf("User %q cannot %s %s at the cluster scope", username, attributes.GetVerb(), resource) | ||||
| } | ||||
| 
 | ||||
| // InternalError renders a simple internal error
 | ||||
|  |  | |||
|  | @ -68,15 +68,15 @@ func TestForbidden(t *testing.T) { | |||
| 		reason      string | ||||
| 		contentType string | ||||
| 	}{ | ||||
| 		{`{"metadata":{},"status":"Failure","message":"forbidden: User \"NAME\" cannot GET path \"/whatever\".","reason":"Forbidden","details":{},"code":403} | ||||
| 		{`{"metadata":{},"status":"Failure","message":"forbidden: User \"NAME\" cannot GET path \"/whatever\"","reason":"Forbidden","details":{},"code":403} | ||||
| `, authorizer.AttributesRecord{User: u, Verb: "GET", Path: "/whatever"}, "", "application/json"}, | ||||
| 		{`{"metadata":{},"status":"Failure","message":"forbidden: User \"NAME\" cannot GET path \"/\u0026lt;script\u0026gt;\".","reason":"Forbidden","details":{},"code":403} | ||||
| 		{`{"metadata":{},"status":"Failure","message":"forbidden: User \"NAME\" cannot GET path \"/\u0026lt;script\u0026gt;\"","reason":"Forbidden","details":{},"code":403} | ||||
| `, authorizer.AttributesRecord{User: u, Verb: "GET", Path: "/<script>"}, "", "application/json"}, | ||||
| 		{`{"metadata":{},"status":"Failure","message":"pod is forbidden: User \"NAME\" cannot GET pod at the cluster scope.","reason":"Forbidden","details":{"kind":"pod"},"code":403} | ||||
| 		{`{"metadata":{},"status":"Failure","message":"pod is forbidden: User \"NAME\" cannot GET pod at the cluster scope","reason":"Forbidden","details":{"kind":"pod"},"code":403} | ||||
| `, authorizer.AttributesRecord{User: u, Verb: "GET", Resource: "pod", ResourceRequest: true}, "", "application/json"}, | ||||
| 		{`{"metadata":{},"status":"Failure","message":"pod \"mypod\" is forbidden: User \"NAME\" cannot GET pod at the cluster scope.","reason":"Forbidden","details":{"name":"mypod","kind":"pod"},"code":403} | ||||
| 		{`{"metadata":{},"status":"Failure","message":"pod \"mypod\" is forbidden: User \"NAME\" cannot GET pod at the cluster scope","reason":"Forbidden","details":{"name":"mypod","kind":"pod"},"code":403} | ||||
| `, authorizer.AttributesRecord{User: u, Verb: "GET", Resource: "pod", ResourceRequest: true, Name: "mypod"}, "", "application/json"}, | ||||
| 		{`{"metadata":{},"status":"Failure","message":"pod.v2 is forbidden: User \"NAME\" cannot GET pod.v2/quota in the namespace \"test\".","reason":"Forbidden","details":{"group":"v2","kind":"pod"},"code":403} | ||||
| 		{`{"metadata":{},"status":"Failure","message":"pod.v2 is forbidden: User \"NAME\" cannot GET pod.v2/quota in the namespace \"test\"","reason":"Forbidden","details":{"group":"v2","kind":"pod"},"code":403} | ||||
| `, authorizer.AttributesRecord{User: u, Verb: "GET", Namespace: "test", APIGroup: "v2", Resource: "pod", Subresource: "quota", ResourceRequest: true}, "", "application/json"}, | ||||
| 	} | ||||
| 	for _, test := range cases { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue