Merge pull request #117713 from flant/ssr-ga
KEP-3325: Promote SelfSubjectReview to GA
This commit is contained in:
@@ -158,6 +158,7 @@ var (
|
||||
gvr("authentication.k8s.io", "v1beta1", "tokenreviews"): `{"metadata": {"name": "tokenreview"}, "spec": {"token": "token", "audience": ["audience1","audience2"]}}`,
|
||||
gvr("authentication.k8s.io", "v1alpha1", "selfsubjectreviews"): `{"metadata": {"name": "SelfSubjectReview"},"status":{"userInfo":{}}}`,
|
||||
gvr("authentication.k8s.io", "v1beta1", "selfsubjectreviews"): `{"metadata": {"name": "SelfSubjectReview"},"status":{"userInfo":{}}}`,
|
||||
gvr("authentication.k8s.io", "v1", "selfsubjectreviews"): `{"metadata": {"name": "SelfSubjectReview"},"status":{"userInfo":{}}}`,
|
||||
gvr("authorization.k8s.io", "v1", "localsubjectaccessreviews"): `{"metadata": {"name": "", "namespace":"` + testNamespace + `"}, "spec": {"uid": "token", "user": "user1","groups": ["group1","group2"],"resourceAttributes": {"name":"name1","namespace":"` + testNamespace + `"}}}`,
|
||||
gvr("authorization.k8s.io", "v1", "subjectaccessreviews"): `{"metadata": {"name": "", "namespace":""}, "spec": {"user":"user1","resourceAttributes": {"name":"name1", "namespace":"` + testNamespace + `"}}}`,
|
||||
gvr("authorization.k8s.io", "v1", "selfsubjectaccessreviews"): `{"metadata": {"name": "", "namespace":""}, "spec": {"resourceAttributes": {"name":"name1", "namespace":""}}}`,
|
||||
|
@@ -99,6 +99,7 @@ func TestGetsSelfAttributes(t *testing.T) {
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
opts.APIEnablement.RuntimeConfig.Set("authentication.k8s.io/v1alpha1=true")
|
||||
opts.APIEnablement.RuntimeConfig.Set("authentication.k8s.io/v1beta1=true")
|
||||
opts.APIEnablement.RuntimeConfig.Set("authentication.k8s.io/v1=true")
|
||||
opts.Authorization.Modes = []string{"AlwaysAllow"}
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
@@ -172,6 +173,33 @@ func TestGetsSelfAttributes(t *testing.T) {
|
||||
if !reflect.DeepEqual(res2.Status.UserInfo.Extra, tc.expectedExtra) {
|
||||
t.Fatalf("unexpected extra: wanted %v, got %v", tc.expectedExtra, res.Status.UserInfo.Extra)
|
||||
}
|
||||
|
||||
res3, err := kubeClient.AuthenticationV1().
|
||||
SelfSubjectReviews().
|
||||
Create(context.TODO(), &authenticationv1.SelfSubjectReview{}, metav1.CreateOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if res3 == nil {
|
||||
t.Fatalf("empty response")
|
||||
}
|
||||
|
||||
if res3.Status.UserInfo.Username != tc.expectedName {
|
||||
t.Fatalf("unexpected username: wanted %s, got %s", tc.expectedName, res.Status.UserInfo.Username)
|
||||
}
|
||||
|
||||
if res3.Status.UserInfo.UID != tc.expectedUID {
|
||||
t.Fatalf("unexpected uid: wanted %s, got %s", tc.expectedUID, res.Status.UserInfo.UID)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(res3.Status.UserInfo.Groups, tc.expectedGroups) {
|
||||
t.Fatalf("unexpected groups: wanted %v, got %v", tc.expectedGroups, res.Status.UserInfo.Groups)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(res3.Status.UserInfo.Extra, tc.expectedExtra) {
|
||||
t.Fatalf("unexpected extra: wanted %v, got %v", tc.expectedExtra, res.Status.UserInfo.Extra)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -187,6 +215,7 @@ func TestGetsSelfAttributesError(t *testing.T) {
|
||||
ModifyServerRunOptions: func(opts *options.ServerRunOptions) {
|
||||
opts.APIEnablement.RuntimeConfig.Set("authentication.k8s.io/v1alpha1=true")
|
||||
opts.APIEnablement.RuntimeConfig.Set("authentication.k8s.io/v1beta1=true")
|
||||
opts.APIEnablement.RuntimeConfig.Set("authentication.k8s.io/v1=true")
|
||||
opts.Authorization.Modes = []string{"AlwaysAllow"}
|
||||
},
|
||||
ModifyServerConfig: func(config *controlplane.Config) {
|
||||
@@ -240,4 +269,20 @@ func TestGetsSelfAttributesError(t *testing.T) {
|
||||
t.Fatalf("expected error: %v, got %v", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
{ // v1
|
||||
toggle.Store(!toggle.Load().(bool))
|
||||
|
||||
_, err := kubeClient.AuthenticationV1().
|
||||
SelfSubjectReviews().
|
||||
Create(context.TODO(), &authenticationv1.SelfSubjectReview{}, metav1.CreateOptions{})
|
||||
if err == nil {
|
||||
t.Fatalf("expected error: %v, got nil", err)
|
||||
}
|
||||
|
||||
toggle.Store(!toggle.Load().(bool))
|
||||
if expected.Error() != err.Error() {
|
||||
t.Fatalf("expected error: %v, got %v", expected, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user