Merge pull request #10319 from briancain/username-prompt-smb
Fixes #9591: Allow for 'default' smb_username if set
This commit is contained in:
commit
9fab454bd5
|
@ -39,19 +39,27 @@ module VagrantPlugins
|
|||
# If we need auth information, then ask the user.
|
||||
have_auth = false
|
||||
folders.each do |id, data|
|
||||
if data[:smb_username] && data[:smb_password]
|
||||
smb_username = data[:smb_username]
|
||||
smb_password = data[:smb_password]
|
||||
smb_username = data[:smb_username] if data[:smb_username]
|
||||
smb_password = data[:smb_password] if data[:smb_password]
|
||||
if smb_username && smb_password
|
||||
have_auth = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
modify_username = false
|
||||
if !have_auth
|
||||
machine.ui.detail(I18n.t("vagrant_sf_smb.warning_password") + "\n ")
|
||||
retries = 0
|
||||
while retries < CREDENTIAL_RETRY_MAX do
|
||||
smb_username = machine.ui.ask("Username: ")
|
||||
if smb_username
|
||||
username = machine.ui.ask("Username (#{smb_username}): ")
|
||||
smb_username = username if username != ""
|
||||
modify_username = true
|
||||
else
|
||||
smb_username = machine.ui.ask("Username: ")
|
||||
end
|
||||
|
||||
smb_password = machine.ui.ask("Password (will be hidden): ", echo: false)
|
||||
auth_success = true
|
||||
|
||||
|
@ -77,7 +85,12 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
folders.each do |id, data|
|
||||
data[:smb_username] ||= smb_username
|
||||
if modify_username
|
||||
# Only override original username if user requests to
|
||||
data[:smb_username] = smb_username
|
||||
else
|
||||
data[:smb_username] ||= smb_username
|
||||
end
|
||||
data[:smb_password] ||= smb_password
|
||||
|
||||
# Register password as sensitive
|
||||
|
|
|
@ -69,6 +69,36 @@ describe VagrantPlugins::SyncedFolderSMB::SyncedFolder do
|
|||
describe ".prepare" do
|
||||
let(:host_caps){ [:smb_start, :smb_prepare] }
|
||||
|
||||
context "with username credentials provided" do
|
||||
let(:folders){ {'/first/path' => {smb_username: 'smbuser'}} }
|
||||
|
||||
it "should prompt for credentials" do
|
||||
expect(machine.env.ui).to receive(:ask).with(/name/, any_args).and_return('username').at_least(1)
|
||||
expect(machine.env.ui).to receive(:ask).with(/word/, any_args).and_return('password').at_least(1)
|
||||
|
||||
subject.prepare(machine, folders, options)
|
||||
end
|
||||
|
||||
it "should set credential information into all folder options and override username" do
|
||||
expect(machine.env.ui).to receive(:ask).with(/name/, any_args).and_return('username').at_least(1)
|
||||
expect(machine.env.ui).to receive(:ask).with(/word/, any_args).and_return('password').at_least(1)
|
||||
|
||||
subject.prepare(machine, folders, options)
|
||||
expect(folders['/first/path'][:smb_username]).to eq('username')
|
||||
expect(folders['/first/path'][:smb_password]).to eq('password')
|
||||
end
|
||||
|
||||
|
||||
it "will use configured default with no input" do
|
||||
expect(machine.env.ui).to receive(:ask).with(/name/, any_args).and_return('').at_least(1)
|
||||
expect(machine.env.ui).to receive(:ask).with(/word/, any_args).and_return('password').at_least(1)
|
||||
|
||||
subject.prepare(machine, folders, options)
|
||||
expect(folders['/first/path'][:smb_username]).to eq('smbuser')
|
||||
expect(folders['/first/path'][:smb_password]).to eq('password')
|
||||
end
|
||||
end
|
||||
|
||||
context "without credentials provided" do
|
||||
before do
|
||||
expect(machine.env.ui).to receive(:ask).with(/name/, any_args).and_return('username').at_least(1)
|
||||
|
|
Loading…
Reference in New Issue