github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/tests/remote-secret/utils.go (about) 1 package remotesecret 2 3 import ( 4 image "github.com/konflux-ci/image-controller/api/v1alpha1" 5 . "github.com/onsi/gomega" 6 "github.com/redhat-appstudio/e2e-tests/pkg/framework" 7 "github.com/redhat-appstudio/e2e-tests/pkg/utils/build" 8 rs "github.com/redhat-appstudio/remote-secret/api/v1beta1" 9 ) 10 11 func IsTargetSecretLinkedToRightSA(ns, imageRemoteSecretName, serviceAccountName string, target rs.TargetStatus) { 12 Expect(target.Namespace).To(Equal(ns)) 13 Expect(target.DeployedSecret.Name).To(Equal(imageRemoteSecretName)) 14 Expect(target.ServiceAccountNames).To(HaveLen(1)) 15 Expect(target.ServiceAccountNames[0]).To(Equal(serviceAccountName)) 16 } 17 18 func IsRobotAccountTokenCorrect(secretName, ns, secretType string, image *image.ImageRepository, fw *framework.Framework) { 19 secret, err := fw.AsKubeAdmin.CommonController.GetSecret(ns, secretName) 20 Expect(err).NotTo(HaveOccurred()) 21 22 // get robot account name and token from image secret 23 robotAccountName, robotAccountToken := build.GetRobotAccountInfoFromSecret(secret) 24 25 if image != nil { 26 // get expected robot account name 27 imageRepo, err := fw.AsKubeAdmin.ImageController.GetImageRepositoryCR(image.Name, image.Namespace) 28 Expect(err).NotTo(HaveOccurred()) 29 30 // ensure that image secret points to the expected robot account name 31 expectedRobotAccountName := "" 32 if secretType == "pull" { 33 expectedRobotAccountName = imageRepo.Status.Credentials.PullRobotAccountName 34 } else { 35 expectedRobotAccountName = imageRepo.Status.Credentials.PushRobotAccountName 36 } 37 Expect(robotAccountName).To(Equal(expectedRobotAccountName)) 38 } 39 40 // get expected robot account token 41 expectedRobotAccountToken, err := build.GetRobotAccountToken(robotAccountName) 42 Expect(err).ShouldNot(HaveOccurred()) 43 44 // ensure secret points to the expected robot account token 45 Expect(robotAccountToken).To(Equal(expectedRobotAccountToken)) 46 }