@@ -86,6 +86,8 @@ var _ = Describe("GitRepositoryReconciler", func() {
8686 expectStatus metav1.ConditionStatus
8787 expectMessage string
8888 expectRevision string
89+
90+ v2 bool
8991 }
9092
9193 DescribeTable ("Git references tests" , func (t refTestCase ) {
@@ -262,5 +264,65 @@ var _ = Describe("GitRepositoryReconciler", func() {
262264 expectMessage : "git commit 'invalid' not found: object not found" ,
263265 }),
264266 )
267+
268+ DescribeTable ("Git self signed cert tests" , func (t refTestCase ) {
269+ err = gitServer .StartHTTPTLS (examplePublicKey , examplePrivateKey , exampleCA , "example.com" )
270+ defer gitServer .StopHTTP ()
271+ Expect (err ).NotTo (HaveOccurred ())
272+
273+ u , err := url .Parse (gitServer .HTTPAddress ())
274+ Expect (err ).NotTo (HaveOccurred ())
275+ u .Path = path .Join (u .Path , fmt .Sprintf ("repository-%s.git" , randStringRunes (5 )))
276+
277+ key := types.NamespacedName {
278+ Name : fmt .Sprintf ("git-ref-test-%s" , randStringRunes (5 )),
279+ Namespace : namespace .Name ,
280+ }
281+ created := & sourcev1.GitRepository {
282+ ObjectMeta : metav1.ObjectMeta {
283+ Name : key .Name ,
284+ Namespace : key .Namespace ,
285+ },
286+ Spec : sourcev1.GitRepositorySpec {
287+ URL : u .String (),
288+ Interval : metav1.Duration {Duration : indexInterval },
289+ Reference : t .reference ,
290+ GitProtocolV2Compatibility : t .v2 ,
291+ },
292+ }
293+ Expect (k8sClient .Create (context .Background (), created )).Should (Succeed ())
294+ defer k8sClient .Delete (context .Background (), created )
295+
296+ got := & sourcev1.GitRepository {}
297+ var cond metav1.Condition
298+ Eventually (func () bool {
299+ _ = k8sClient .Get (context .Background (), key , got )
300+ for _ , c := range got .Status .Conditions {
301+ if c .Reason == t .waitForReason {
302+ cond = c
303+ return true
304+ }
305+ }
306+ return false
307+ }, timeout , interval ).Should (BeTrue ())
308+
309+ Expect (cond .Status ).To (Equal (t .expectStatus ))
310+ Expect (cond .Message ).To (ContainSubstring (t .expectMessage ))
311+ Expect (got .Status .Artifact == nil ).To (Equal (t .expectRevision == "" ))
312+ },
313+ Entry ("self signed v1" , refTestCase {
314+ reference : & sourcev1.GitRepositoryRef {Branch : "main" },
315+ waitForReason : sourcev1 .GitOperationFailedReason ,
316+ expectStatus : metav1 .ConditionFalse ,
317+ expectMessage : "x509: certificate signed by unknown authority" ,
318+ }),
319+ Entry ("self signed v2" , refTestCase {
320+ reference : & sourcev1.GitRepositoryRef {Branch : "main" },
321+ waitForReason : sourcev1 .GitOperationFailedReason ,
322+ expectStatus : metav1 .ConditionFalse ,
323+ expectMessage : "error: user rejected certificate" ,
324+ v2 : true ,
325+ }),
326+ )
265327 })
266328})
0 commit comments