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

feat(controller): allow GitHub App as authn method for image repos in ghcr #2391

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion internal/credentials/kubernetes/github/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (a *appCredentialHelper) getCredentials(
_ string,
secret *corev1.Secret,
) (*credentials.Credentials, error) {
if credType != credentials.TypeGit || secret == nil {
if (credType != credentials.TypeGit && credType != credentials.TypeImage) || secret == nil {
// This helper can't handle this
return nil, nil
}
Expand Down
20 changes: 19 additions & 1 deletion internal/credentials/kubernetes/github/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,25 @@ func TestAppCredentialHelper(t *testing.T) {
assertions func(*testing.T, *credentials.Credentials, *cache.Cache, error)
}{
{
name: "cred type is not git",
name: "cred type is not supported",
credType: credentials.TypeHelm,
helper: &appCredentialHelper{},
assertions: func(t *testing.T, creds *credentials.Credentials, _ *cache.Cache, err error) {
require.NoError(t, err)
require.Nil(t, creds)
},
},
{
name: "cred type is git",
credType: credentials.TypeGit,
helper: &appCredentialHelper{},
assertions: func(t *testing.T, creds *credentials.Credentials, _ *cache.Cache, err error) {
require.NoError(t, err)
require.Nil(t, creds)
},
},
krancour marked this conversation as resolved.
Show resolved Hide resolved
{
name: "cred type is image",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two new cases are still not needed. I know this may seem counter-intuitive, but remember this is white-box testing...

The previous case (cred type not supported) tests for an early return if the cred type is not supported. Subsequent cases only require the cred type to be a supported one so that we avoid that early return and move on to testing other outcomes. Again, with white-box testing, we have the luxury of knowing the implementation and we know that once we're past that potential early return, the cred type has no further bearing on the results.

credType: credentials.TypeImage,
helper: &appCredentialHelper{},
assertions: func(t *testing.T, creds *credentials.Credentials, _ *cache.Cache, err error) {
Expand Down