Skip to content

Commit 47e4e54

Browse files
committed
Add test to show that libgit2 fails with self signed test
Signed-off-by: Philip Laine <[email protected]>
1 parent 6344528 commit 47e4e54

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

controllers/gitrepository_controller_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
})

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ go 1.15
44

55
replace github.com/fluxcd/source-controller/api => ./api
66

7+
replace github.com/fluxcd/pkg/gittestserver => github.com/fluxcd/pkg/gittestserver v0.0.3-0.20201202222244-96033b836a6a
8+
79
require (
810
github.com/Masterminds/semver/v3 v3.1.0
911
github.com/blang/semver/v4 v4.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
224224
github.com/fluxcd/pkg/apis/meta v0.3.0/go.mod h1:wOzQQx8CdtUQCGaLzqGu4QgnNxYkI6/wvdvlovxWhF0=
225225
github.com/fluxcd/pkg/apis/meta v0.4.0 h1:JChqB9GGgorW9HWKxirTVV0rzrcLyzBaVjinmqZ0iHA=
226226
github.com/fluxcd/pkg/apis/meta v0.4.0/go.mod h1:wOzQQx8CdtUQCGaLzqGu4QgnNxYkI6/wvdvlovxWhF0=
227-
github.com/fluxcd/pkg/gittestserver v0.0.2 h1:11aKRVuuHiyeaicdN4wPNSMy/dUarQkrPrg0uUgDcTw=
228-
github.com/fluxcd/pkg/gittestserver v0.0.2/go.mod h1:GW8N9d1o8/+mXWnSzs02qCB5WlArWQHdMpDPf7b/GZg=
227+
github.com/fluxcd/pkg/gittestserver v0.0.3-0.20201202222244-96033b836a6a h1:fmfbt5VrEPUb4X0UI14a0K2FWr0iv/NRUadk8X35byc=
228+
github.com/fluxcd/pkg/gittestserver v0.0.3-0.20201202222244-96033b836a6a/go.mod h1:HWZaoib03fQeSsauCAN2iAFdr6bnjKQ+CFxMFD2mwDY=
229229
github.com/fluxcd/pkg/helmtestserver v0.0.1 h1:8RcLZdg7Zr9ZqyijsIIASjjMXQtF4UWP4Uds4iK2VJM=
230230
github.com/fluxcd/pkg/helmtestserver v0.0.1/go.mod h1:GR8LriiU7PqZSTH4Xe6Cimpig2VVPB29PeUXJjNJYfA=
231231
github.com/fluxcd/pkg/lockedfile v0.0.5 h1:C3T8wfdff1UY1bvplmCkGOLrdMWJHO8Q8+tdlEXJYzQ=

0 commit comments

Comments
 (0)