Merge pull request #127768 from ii/create-serviceaccounttoken-test

Write e2e test for CoreV1 ServiceAccountToken +1 Endpoint
This commit is contained in:
Kubernetes Prow Robot 2024-10-07 20:46:22 +01:00 committed by GitHub
commit 9c610d1082
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -838,6 +838,33 @@ var _ = SIGDescribe("ServiceAccounts", func() {
gomega.Expect(updatedServiceAccount.AutomountServiceAccountToken).To(gomega.Equal(utilptr.Bool(true)), "Failed to set AutomountServiceAccountToken")
framework.Logf("AutomountServiceAccountToken: %v", *updatedServiceAccount.AutomountServiceAccountToken)
})
ginkgo.It("should create a serviceAccountToken and ensure a successful TokenReview", func(ctx context.Context) {
ns := f.Namespace.Name
saClient := f.ClientSet.CoreV1().ServiceAccounts(ns)
saName := "e2e-sa-" + utilrand.String(5)
ginkgo.By(fmt.Sprintf("Creating a Serviceaccount %q in namespace %q", saName, ns))
_, err := f.ClientSet.CoreV1().ServiceAccounts(ns).Create(context.TODO(), &v1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: saName,
},
}, metav1.CreateOptions{})
framework.ExpectNoError(err, "Unable to create serviceaccount %q", saName)
ginkgo.By(fmt.Sprintf("Creating a ServiceaccountToken %q in namespace %q", saName, ns))
request := &authenticationv1.TokenRequest{}
response, err := saClient.CreateToken(context.TODO(), saName, request, metav1.CreateOptions{})
framework.ExpectNoError(err, "Unable to create serviceAccountToken")
gomega.Expect(response.Status.Token).ToNot(gomega.BeEmpty(), "confirm that a Token has been created")
ginkgo.By(fmt.Sprintf("Creating a TokenReview for %q in namespace %q", response.Name, ns))
tokenReview := &authenticationv1.TokenReview{Spec: authenticationv1.TokenReviewSpec{Token: response.Status.Token}}
tokenReview, err = f.ClientSet.AuthenticationV1().TokenReviews().Create(ctx, tokenReview, metav1.CreateOptions{})
framework.ExpectNoError(err, "failed to create a TokenReview")
gomega.Expect(tokenReview.Status.Authenticated).To(gomega.BeTrueBecause("expect that the TokenReview is authenticated"))
gomega.Expect(tokenReview.Status.Error).To(gomega.BeEmpty(), "confirm that there are no TokenReview errors")
})
})
var reportLogsParser = regexp.MustCompile("([a-zA-Z0-9-_]*)=([a-zA-Z0-9-_]*)$")