Avoid blanking username if set by user (#1352)

While the username may not be used unless the connection is via ssh,
should avoid forcing to nil by accident when re-parsing from the uri.
This commit is contained in:
Darragh Bailey 2021-09-25 10:24:00 +01:00 committed by GitHub
parent da2674b9af
commit c3e96d149e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -1037,10 +1037,12 @@ module VagrantPlugins
end
end
# Extract host and username values from uri if provided, otherwise nil
# Extract host values from uri if provided, otherwise nil
@host = uri.host
@port = uri.port
@username = uri.user
# only override username if there is a value provided
@username = nil if @username == UNSET_VALUE
@username = uri.user if uri.user
if uri.query
params = CGI.parse(uri.query)
@id_ssh_key_file = params['keyfile'].first if params.has_key?('keyfile')

View File

@ -192,14 +192,14 @@ describe VagrantPlugins::ProviderLibvirt::Config do
],
[ # when username explicitly set without ssh
{:username => 'my_user' },
{:uri => 'qemu:///system'},
{:uri => 'qemu:///system', :username => 'my_user'},
{
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu://session'},
}
],
[ # when username explicitly set with host but without ssh
{:username => 'my_user', :host => 'remote'},
{:uri => 'qemu://remote/system'},
{:uri => 'qemu://remote/system', :username => 'my_user'},
{
:env => {'LIBVIRT_DEFAULT_URI' => 'qemu://session'},
}