Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for http bearer-token auth #1058

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions controllers/gitrepository_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,12 @@ func TestGitRepositoryReconciler_reconcileSource_emptyRepository(t *testing.T) {

func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
type options struct {
username string
password string
publicKey []byte
privateKey []byte
ca []byte
username string
password string
publicKey []byte
privateKey []byte
ca []byte
bearerToken []byte
}

tests := []struct {
Expand Down Expand Up @@ -381,9 +382,29 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "foo"),
},
},
// TODO: Add test case for HTTPS with bearer token auth secret. It
// depends on gitkit to have support for bearer token based
// authentication.
{
name: "HTTP with bearer-token secret makes Reconciling=True",
protocol: "http",
server: options{
bearerToken: []byte("ghp_baM3qnEE0O41WluceBL4udt2N0vVZS4R0hMS"),
},
secret: &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "bearer-token",
},
Data: map[string][]byte{
"bearerToken": []byte("ghp_baM3qnEE0O41WluceBL4udt2N0vVZS4R0hMS"),
},
},
beforeFunc: func(obj *sourcev1.GitRepository) {
obj.Spec.SecretRef = &meta.LocalObjectReference{Name: "bearer-token"}
},
want: sreconcile.ResultSuccess,
assertConditions: []metav1.Condition{
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
},
},
{
name: "SSH with private key secret makes Reconciling=True",
protocol: "ssh",
Expand All @@ -405,7 +426,7 @@ func TestGitRepositoryReconciler_reconcileSource_authStrategy(t *testing.T) {
want: sreconcile.ResultSuccess,
assertConditions: []metav1.Condition{
*conditions.TrueCondition(meta.ReconcilingCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>"),
*conditions.UnknownCondition(meta.ReadyCondition, meta.ProgressingReason, "building artifact: new upstream revision 'master@sha1:<commit>'"),
},
},
{
Expand Down