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