-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Improve basic auth handling for canonical ports #15945
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ import ( | |
kapiv1 "k8s.io/kubernetes/pkg/api/v1" | ||
"k8s.io/kubernetes/pkg/credentialprovider" | ||
|
||
"github.com/golang/glog" | ||
_ "github.com/openshift/origin/pkg/api/install" | ||
) | ||
|
||
|
@@ -29,7 +28,7 @@ func TestCredentialsForSecrets(t *testing.T) { | |
for i, secret := range secrets.Items { | ||
err := kapiv1.Convert_api_Secret_To_v1_Secret(&secret, &secretsv1[i], nil) | ||
if err != nil { | ||
glog.V(2).Infof("Unable to make the Docker keyring for %s/%s secret: %v", secret.Name, secret.Namespace, err) | ||
t.Logf("Unable to make the Docker keyring for %s/%s secret: %v", secret.Name, secret.Namespace, err) | ||
continue | ||
} | ||
} | ||
|
@@ -70,3 +69,57 @@ func TestBasicCredentials(t *testing.T) { | |
t.Fatalf("unexpected response: %s %s", u, p) | ||
} | ||
} | ||
|
||
func Test_basicCredentialsFromKeyring(t *testing.T) { | ||
fn := func(host string, entry credentialprovider.DockerConfigEntry) credentialprovider.DockerKeyring { | ||
k := &credentialprovider.BasicDockerKeyring{} | ||
k.Add(map[string]credentialprovider.DockerConfigEntry{host: entry}) | ||
return k | ||
} | ||
def := credentialprovider.DockerConfigEntry{ | ||
Username: "local_user", | ||
Password: "local_pass", | ||
} | ||
type args struct { | ||
keyring credentialprovider.DockerKeyring | ||
target *url.URL | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
user string | ||
password string | ||
}{ | ||
{name: "exact", args: args{keyring: fn("localhost", def), target: &url.URL{Host: "localhost"}}, user: def.Username, password: def.Password}, | ||
{name: "https scheme", args: args{keyring: fn("localhost", def), target: &url.URL{Scheme: "https", Host: "localhost"}}, user: def.Username, password: def.Password}, | ||
{name: "canonical https", args: args{keyring: fn("localhost", def), target: &url.URL{Scheme: "https", Host: "localhost:443"}}, user: def.Username, password: def.Password}, | ||
{name: "only https", args: args{keyring: fn("https://localhost", def), target: &url.URL{Host: "localhost"}}, user: def.Username, password: def.Password}, | ||
{name: "only https scheme", args: args{keyring: fn("https://localhost", def), target: &url.URL{Scheme: "https", Host: "localhost"}}, user: def.Username, password: def.Password}, | ||
{name: "mismatched scheme - http", args: args{keyring: fn("http://localhost", def), target: &url.URL{Scheme: "https", Host: "localhost"}}, user: def.Username, password: def.Password}, | ||
|
||
// this is not allowed by the credential keyring, but should be | ||
{name: "exact http", args: args{keyring: fn("http://localhost", def), target: &url.URL{Scheme: "http", Host: "localhost:80"}}, user: "", password: ""}, | ||
{name: "keyring canonical https", args: args{keyring: fn("localhost:443", def), target: &url.URL{Scheme: "https", Host: "localhost"}}, user: "", password: ""}, | ||
|
||
// these should not be allowed | ||
{name: "host is for port 80 only", args: args{keyring: fn("localhost:80", def), target: &url.URL{Host: "localhost"}}, user: "", password: ""}, | ||
{name: "host is for port 443 only", args: args{keyring: fn("localhost:443", def), target: &url.URL{Host: "localhost"}}, user: "", password: ""}, | ||
{name: "don't assume port 80 in keyring is https", args: args{keyring: fn("localhost:80", def), target: &url.URL{Scheme: "http", Host: "localhost"}}, user: "", password: ""}, | ||
{name: "canonical http", args: args{keyring: fn("localhost", def), target: &url.URL{Scheme: "http", Host: "localhost:80"}}, user: "", password: ""}, | ||
{name: "http scheme", args: args{keyring: fn("localhost", def), target: &url.URL{Scheme: "http", Host: "localhost"}}, user: "", password: ""}, | ||
{name: "https not canonical", args: args{keyring: fn("localhost", def), target: &url.URL{Scheme: "https", Host: "localhost:80"}}, user: "", password: ""}, | ||
{name: "http not canonical", args: args{keyring: fn("localhost", def), target: &url.URL{Scheme: "http", Host: "localhost:443"}}, user: "", password: ""}, | ||
{name: "mismatched scheme", args: args{keyring: fn("https://localhost", def), target: &url.URL{Scheme: "http", Host: "localhost"}}, user: "", password: ""}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat! Didn't know about this. |
||
user, password := basicCredentialsFromKeyring(tt.args.keyring, tt.args.target) | ||
if user != tt.user { | ||
t.Errorf("basicCredentialsFromKeyring() user = %v, actual = %v", user, tt.user) | ||
} | ||
if password != tt.password { | ||
t.Errorf("basicCredentialsFromKeyring() password = %v, actual = %v", password, tt.password) | ||
} | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Test cases with default and non-default ports in the keyring would be nice.