Skip to content

Commit b74e7aa

Browse files
committed
Add test for http bear-token auth
Signed-off-by: Santosh Kaluskar <[email protected]>
1 parent 7433863 commit b74e7aa

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

controllers/gitrepository_controller_test.go

+30-9
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,12 @@ func TestGitRepositoryReconciler_reconcileSource_emptyRepository(t *testing.T) {
272272

273273
func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
274274
type options struct {
275-
username string
276-
password string
277-
publicKey []byte
278-
privateKey []byte
279-
ca []byte
275+
username string
276+
password string
277+
publicKey []byte
278+
privateKey []byte
279+
ca []byte
280+
bearerToken []byte
280281
}
281282

282283
tests := []struct {
@@ -381,9 +382,29 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
381382
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "foo"),
382383
},
383384
},
384-
// TODO: Add test case for HTTPS with bearer token auth secret. It
385-
// depends on gitkit to have support for bearer token based
386-
// authentication.
385+
{
386+
name: "HTTP with bearer-token secret makes Reconciling=True",
387+
protocol: "http",
388+
server: options{
389+
bearerToken: []byte("ghp_baM3qnEE0O41WluceBL4udt2N0vVZS4R0hMS"),
390+
},
391+
secret: &corev1.Secret{
392+
ObjectMeta: metav1.ObjectMeta{
393+
Name: "bearer-token",
394+
},
395+
Data: map[string][]byte{
396+
"bearerToken": []byte("ghp_baM3qnEE0O41WluceBL4udt2N0vVZS4R0hMS"),
397+
},
398+
},
399+
beforeFunc: func(obj *sourcev1.GitRepository) {
400+
obj.Spec.SecretRef = &meta.LocalObjectReference{Name: "bearer_token-auth"}
401+
},
402+
want: sreconcile.ResultSuccess,
403+
assertConditions: []metav1.Condition{
404+
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
405+
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
406+
},
407+
},
387408
{
388409
name: "SSH with private key secret makes Reconciling=True",
389410
protocol: "ssh",
@@ -405,7 +426,7 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
405426
want: sreconcile.ResultSuccess,
406427
assertConditions: []metav1.Condition{
407428
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
408-
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>"),
429+
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
409430
},
410431
},
411432
{

0 commit comments

Comments
 (0)