@@ -95,6 +95,75 @@ func Test_UpdateApplication(t *testing.T) {
95
95
assert .Equal (t , 2 , res .NumImagesUpdated )
96
96
})
97
97
98
+ t .Run ("Update app w/ GitHub App creds" , func (t * testing.T ) {
99
+ mockClientFn := func (endpoint * registry.RegistryEndpoint , username , password string ) (registry.RegistryClient , error ) {
100
+ regMock := regmock.RegistryClient {}
101
+ regMock .On ("NewRepository" , mock .Anything ).Return (nil )
102
+ regMock .On ("Tags" , mock .Anything ).Return ([]string {"1.0.2" , "1.0.3" }, nil )
103
+ return & regMock , nil
104
+ }
105
+
106
+ argoClient := argomock.ArgoCD {}
107
+ argoClient .On ("UpdateSpec" , mock .Anything , mock .Anything ).Return (nil , nil )
108
+
109
+ secret := fixture .NewSecret ("argocd-image-updater" , "git-creds" , map [string ][]byte {
110
+ "githubAppID" : []byte ("12345678" ),
111
+ "githubAppInstallationID" : []byte ("87654321" ),
112
+ "githubAppPrivateKey" : []byte ("foo" ),
113
+ })
114
+ kubeClient := kube.KubernetesClient {
115
+ Clientset : fake .NewFakeClientsetWithResources (secret ),
116
+ }
117
+
118
+ annotations := map [string ]string {
119
+ common .ImageUpdaterAnnotation : "foo=gcr.io/jannfis/foobar:>=1.0.1" ,
120
+ common .WriteBackMethodAnnotation : "git:secret:argocd-image-updater/git-creds" ,
121
+ }
122
+ appImages := & ApplicationImages {
123
+ Application : v1alpha1.Application {
124
+ ObjectMeta : v1.ObjectMeta {
125
+ Name : "guestbook" ,
126
+ Namespace : "guestbook" ,
127
+ Annotations : annotations ,
128
+ },
129
+ Spec : v1alpha1.ApplicationSpec {
130
+ Source : & v1alpha1.ApplicationSource {
131
+ RepoURL : "https://example.com/example" ,
132
+ TargetRevision : "main" ,
133
+ Kustomize : & v1alpha1.ApplicationSourceKustomize {
134
+ Images : v1alpha1.KustomizeImages {
135
+ "jannfis/foobar:1.0.1" ,
136
+ },
137
+ },
138
+ },
139
+ },
140
+ Status : v1alpha1.ApplicationStatus {
141
+ SourceType : v1alpha1 .ApplicationSourceTypeKustomize ,
142
+ Summary : v1alpha1.ApplicationSummary {
143
+ Images : []string {
144
+ "gcr.io/jannfis/foobar:1.0.1" ,
145
+ },
146
+ },
147
+ },
148
+ },
149
+ Images : * parseImageList (annotations ),
150
+ }
151
+ res := UpdateApplication (& UpdateConfiguration {
152
+ NewRegFN : mockClientFn ,
153
+ ArgoClient : & argoClient ,
154
+ KubeClient : & kubeClient ,
155
+ UpdateApp : appImages ,
156
+ DryRun : false ,
157
+ }, NewSyncIterationState ())
158
+ assert .Equal (t , v1alpha1 .KustomizeImage ("gcr.io/jannfis/foobar:1.0.3" ), appImages .Application .Spec .Source .Kustomize .Images [0 ])
159
+ assert .Equal (t , 0 , res .NumSkipped )
160
+ assert .Equal (t , 1 , res .NumApplicationsProcessed )
161
+ assert .Equal (t , 1 , res .NumImagesConsidered )
162
+ // configured githubApp creds will take effect and git client will catch the invalid GithubAppPrivateKey "foo":
163
+ // "Could not update application spec: could not parse private key: invalid key: Key must be a PEM encoded PKCS1 or PKCS8 key"
164
+ assert .Equal (t , 1 , res .NumErrors )
165
+ })
166
+
98
167
t .Run ("Test successful update" , func (t * testing.T ) {
99
168
mockClientFn := func (endpoint * registry.RegistryEndpoint , username , password string ) (registry.RegistryClient , error ) {
100
169
regMock := regmock.RegistryClient {}
@@ -2623,6 +2692,38 @@ func Test_GetGitCreds(t *testing.T) {
2623
2692
// Must have HTTPS GitHub App creds
2624
2693
_ , ok := creds .(git.GitHubAppCreds )
2625
2694
require .True (t , ok )
2695
+
2696
+ // invalid secrete data in GitHub App creds
2697
+ invalidSecretEntries := []map [string ][]byte {
2698
+ { // missing githubAppPrivateKey
2699
+ "githubAppID" : []byte ("12345678" ),
2700
+ "githubAppInstallationID" : []byte ("87654321" ),
2701
+ }, { // missing githubAppInstallationID
2702
+ "githubAppID" : []byte ("12345678" ),
2703
+ "githubAppPrivateKey" : []byte ("foo" ),
2704
+ }, { // missing githubAppID
2705
+ "githubAppInstallationID" : []byte ("87654321" ),
2706
+ "githubAppPrivateKey" : []byte ("foo" ),
2707
+ }, { // ID should be a number
2708
+ "githubAppID" : []byte ("NaN" ),
2709
+ "githubAppInstallationID" : []byte ("87654321" ),
2710
+ "githubAppPrivateKey" : []byte ("foo" ),
2711
+ }, {
2712
+ "githubAppID" : []byte ("12345678" ),
2713
+ "githubAppInstallationID" : []byte ("NaN" ),
2714
+ "githubAppPrivateKey" : []byte ("foo" ),
2715
+ },
2716
+ }
2717
+ for _ , secretEntry := range invalidSecretEntries {
2718
+ secret = fixture .NewSecret ("argocd-image-updater" , "git-creds" , secretEntry )
2719
+ kubeClient = kube.KubernetesClient {
2720
+ Clientset : fake .NewFakeClientsetWithResources (secret ),
2721
+ }
2722
+ wbc , err = getWriteBackConfig (& app , & kubeClient , & argoClient )
2723
+ require .NoError (t , err )
2724
+ _ , err = wbc .GetCreds (& app )
2725
+ require .Error (t , err )
2726
+ }
2626
2727
})
2627
2728
2628
2729
t .Run ("SSH creds from a secret" , func (t * testing.T ) {
0 commit comments