-
Notifications
You must be signed in to change notification settings - Fork 176
Add --registry-authfile to specify a specific auth file for the registry push #3208
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
Changes from 3 commits
3994999
df4fcd7
2f563bf
a3eb497
514d977
ee37f59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -815,6 +815,91 @@ func TestCredentialsHomePermissions(t *testing.T) { | |||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func TestCredentialsFromAuthfile(t *testing.T) { | ||||||||||||||||||
| tests := []struct { | ||||||||||||||||||
| name string | ||||||||||||||||||
| verifyCredentials creds.VerifyCredentialsCallback | ||||||||||||||||||
| authFileContent string | ||||||||||||||||||
| image string | ||||||||||||||||||
| want Credentials | ||||||||||||||||||
| }{ | ||||||||||||||||||
| { | ||||||||||||||||||
| name: "Single registry auth file", | ||||||||||||||||||
| verifyCredentials: correctVerifyCbk, | ||||||||||||||||||
| authFileContent: fmt.Sprintf(` | ||||||||||||||||||
| { | ||||||||||||||||||
| "auths": { | ||||||||||||||||||
| "docker.io": { | ||||||||||||||||||
| "auth": "%s" | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| `, base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", dockerIoUser, dockerIoUserPwd)))), | ||||||||||||||||||
| image: "docker.io/someorg/someimage:sometag", | ||||||||||||||||||
| want: Credentials{Username: dockerIoUser, Password: dockerIoUserPwd}, | ||||||||||||||||||
| }, | ||||||||||||||||||
| { | ||||||||||||||||||
| name: "Auth file with multiple registries", | ||||||||||||||||||
| verifyCredentials: correctVerifyCbk, | ||||||||||||||||||
| authFileContent: fmt.Sprintf(` | ||||||||||||||||||
| { | ||||||||||||||||||
| "auths": { | ||||||||||||||||||
| "docker.io": { | ||||||||||||||||||
| "auth": "%s" | ||||||||||||||||||
| }, | ||||||||||||||||||
| "quay.io": { | ||||||||||||||||||
| "auth": "%s" | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| `, base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", dockerIoUser, dockerIoUserPwd))), | ||||||||||||||||||
| base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", quayIoUser, quayIoUserPwd)))), | ||||||||||||||||||
| image: "quay.io/someorg/someimage:sometag", | ||||||||||||||||||
| want: Credentials{Username: quayIoUser, Password: quayIoUserPwd}, | ||||||||||||||||||
| }, | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // reset HOME to the original value after tests since they may change it | ||||||||||||||||||
| defer func() { | ||||||||||||||||||
| os.Setenv("HOME", homeTempDir) | ||||||||||||||||||
| }() | ||||||||||||||||||
|
|
||||||||||||||||||
| for _, tt := range tests { | ||||||||||||||||||
| t.Run(tt.name, func(t *testing.T) { | ||||||||||||||||||
| resetHomeDir(t) | ||||||||||||||||||
|
|
||||||||||||||||||
| authFile, err := os.CreateTemp("", "test-auth-*.txt") | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| t.Fatalf("failed to create temp auth file: %s", err) | ||||||||||||||||||
| } | ||||||||||||||||||
| t.Cleanup(func() { | ||||||||||||||||||
| os.Remove(authFile.Name()) | ||||||||||||||||||
| }) | ||||||||||||||||||
| if _, err := authFile.Write([]byte(tt.authFileContent)); err != nil { | ||||||||||||||||||
| t.Fatalf("failed to write auth file: %s", err) | ||||||||||||||||||
| } | ||||||||||||||||||
| authFile.Close() | ||||||||||||||||||
|
|
||||||||||||||||||
| credentialsProvider := creds.NewCredentialsProvider( | ||||||||||||||||||
| testConfigPath(t), | ||||||||||||||||||
| creds.WithVerifyCredentials(tt.verifyCredentials), | ||||||||||||||||||
| creds.WithAuthFilePath(authFile.Name()), | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| got, err := credentialsProvider(context.Background(), tt.image) | ||||||||||||||||||
|
|
||||||||||||||||||
| // ASSERT | ||||||||||||||||||
| if err != nil { | ||||||||||||||||||
| t.Errorf("%v", err) | ||||||||||||||||||
| return | ||||||||||||||||||
| } | ||||||||||||||||||
|
||||||||||||||||||
| // ASSERT | |
| if err != nil { | |
| t.Errorf("%v", err) | |
| return | |
| } | |
| if err != nil { | |
| t.Fatalf("unexpected error: %v", err) | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably updated in few more tests in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Updated it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right below that line in 906 is t.TempDir() which probably should be t.Helper(). And the function right below resetHomePermissions is missing the t.Helper() too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use
t.TempDirand create the file there. Then you would not need to cleanup as the temp dir is removed automatically.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Updated it