@@ -838,6 +838,33 @@ var _ = SIGDescribe("ServiceAccounts", func() {
838
838
gomega .Expect (updatedServiceAccount .AutomountServiceAccountToken ).To (gomega .Equal (utilptr .Bool (true )), "Failed to set AutomountServiceAccountToken" )
839
839
framework .Logf ("AutomountServiceAccountToken: %v" , * updatedServiceAccount .AutomountServiceAccountToken )
840
840
})
841
+
842
+ ginkgo .It ("should create a serviceAccountToken and ensure a successful TokenReview" , func (ctx context.Context ) {
843
+ ns := f .Namespace .Name
844
+ saClient := f .ClientSet .CoreV1 ().ServiceAccounts (ns )
845
+ saName := "e2e-sa-" + utilrand .String (5 )
846
+
847
+ ginkgo .By (fmt .Sprintf ("Creating a Serviceaccount %q in namespace %q" , saName , ns ))
848
+ _ , err := f .ClientSet .CoreV1 ().ServiceAccounts (ns ).Create (context .TODO (), & v1.ServiceAccount {
849
+ ObjectMeta : metav1.ObjectMeta {
850
+ Name : saName ,
851
+ },
852
+ }, metav1.CreateOptions {})
853
+ framework .ExpectNoError (err , "Unable to create serviceaccount %q" , saName )
854
+
855
+ ginkgo .By (fmt .Sprintf ("Creating a ServiceaccountToken %q in namespace %q" , saName , ns ))
856
+ request := & authenticationv1.TokenRequest {}
857
+ response , err := saClient .CreateToken (context .TODO (), saName , request , metav1.CreateOptions {})
858
+ framework .ExpectNoError (err , "Unable to create serviceAccountToken" )
859
+ gomega .Expect (response .Status .Token ).ToNot (gomega .BeEmpty (), "confirm that a Token has been created" )
860
+
861
+ ginkgo .By (fmt .Sprintf ("Creating a TokenReview for %q in namespace %q" , response .Name , ns ))
862
+ tokenReview := & authenticationv1.TokenReview {Spec : authenticationv1.TokenReviewSpec {Token : response .Status .Token }}
863
+ tokenReview , err = f .ClientSet .AuthenticationV1 ().TokenReviews ().Create (ctx , tokenReview , metav1.CreateOptions {})
864
+ framework .ExpectNoError (err , "failed to create a TokenReview" )
865
+ gomega .Expect (tokenReview .Status .Authenticated ).To (gomega .BeTrueBecause ("expect that the TokenReview is authenticated" ))
866
+ gomega .Expect (tokenReview .Status .Error ).To (gomega .BeEmpty (), "confirm that there are no TokenReview errors" )
867
+ })
841
868
})
842
869
843
870
var reportLogsParser = regexp .MustCompile ("([a-zA-Z0-9-_]*)=([a-zA-Z0-9-_]*)$" )
0 commit comments