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 method to GitServer to switch auth on #83

Merged
merged 1 commit into from
Feb 11, 2021
Merged

Add method to GitServer to switch auth on #83

merged 1 commit into from
Feb 11, 2021

Conversation

squaremo
Copy link
Member

@squaremo squaremo commented Feb 11, 2021

When testing using gittestserver, it's useful to be able to use
authentication. This is especially true when testing against libgit2,
because it expects authentication over SSH, and will balk if it's not
requested.

This commit adds a method to *GitServer for switching auth on. There's
no way to switch auth on for just SSH -- it will also be required for
HTTP. For that reason, a username and password are needed.

The credentials are included in the URL returned by HTTPAddressWithCredentials(), so
anything using that will transparently work whether auth is on or
not.

EDIT: we changed our idea of whether credentials should go in the URL returned by HTTPAddress().

Comment on lines +190 to +212
u, err := url.Parse(s.httpServer.URL)
if err != nil {
panic(err)
}
if s.password != "" {
u.User = url.UserPassword(s.username, s.password)
} else if s.username != "" {
u.User = url.User(s.username)
}
return u.String()
Copy link
Member

@hiddeco hiddeco Feb 11, 2021

Choose a reason for hiding this comment

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

Doesn't this complicate situations where you want to e.g. mock a GitRepository resource including the Secret required to authenticate, where you do not want to include the credential part of the URL in the mock (as those are defined in the secret)?

If so, maybe it would be wise to add a RepositoryHTTPAddress(repository string) (and maybe also the SSH version) that does not include any credentials for HTTP and only the user for SSH?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeahp, that's the other branch of that decision. Good suggestion -- in fact perhaps I should have HTTPAddressWithCredentials() and adjust my tests to use that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me rework this a little.

When testing using gittestserver, it's useful to be able to use
authentication. This is especially true when testing against libgit2,
because it expects to use authentication over SSH, and will balk if
it's not requested.

This commit adds a method to *GitServer for switching auth on. There's
no way to switch auth on for just SSH -- it will also be required for
HTTP. For that reason, a username and password are needed.

The credentials are included in the URL returned by
HTTPAddressWithCredentials(), so anything using that will
transparently work whether auth is on or not. If you need to test
authentication with HTTP, use `s.HTTPAddress()` and the credentials
you handed to `s.Auth()`.

Signed-off-by: Michael Bridgen <michael@weave.works>
Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

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

Thank you @squaremo 🍎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants