Skip to content

(MODULES-4915) Remove forced TCP connection for SQL management #224

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

Merged
merged 1 commit into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/puppet_x/sqlserver/sql_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def get_connection_string(config)
'Provider' => 'SQLOLEDB.1',
'Initial Catalog' => config[:database] || 'master',
'Application Name' => 'Puppet',
'Data Source' => 'localhost'
'Data Source' => '.'
}

admin_user = config[:admin_user] || ''
Expand All @@ -52,7 +52,7 @@ def get_connection_string(config)
end

if config[:instance_name] != nil && config[:instance_name] !~ /^MSSQLSERVER$/
params['Data Source'] = "localhost\\#{config[:instance_name]}"
params['Data Source'] = ".\\#{config[:instance_name]}"
end

params.map { |k, v| "#{k}=#{v}" }.join(';')
Expand Down
12 changes: 6 additions & 6 deletions spec/unit/puppet_x/sql_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def stub_connection
context 'command execution' do
before :each do
stub_connection
@connection.stubs(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=localhost;User ID=sa;Password=Pupp3t1@')
@connection.stubs(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.;User ID=sa;Password=Pupp3t1@')
end
it 'should not raise an error but populate has_errors with message' do
subject.stubs(:execute).raises(Exception.new("SQL Server\n error has happened"))
Expand All @@ -43,7 +43,7 @@ def stub_connection

context 'Use default authentication' do
it 'should defaul to SQL_LOGIN if admin_login_type is not set' do
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=localhost;User ID=sa;Password=Pupp3t1@')
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.;User ID=sa;Password=Pupp3t1@')
subject.open_and_run_command('query', {:admin_user => 'sa', :admin_pass => 'Pupp3t1@' })
end
end
Expand All @@ -66,11 +66,11 @@ def stub_connection
end

it 'should not add the default instance of MSSQLSERVER to connection string' do
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=localhost;User ID=sa;Password=Pupp3t1@')
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.;User ID=sa;Password=Pupp3t1@')
subject.open_and_run_command('query', {:admin_user => 'sa', :admin_pass => 'Pupp3t1@', :instance_name => 'MSSQLSERVER'})
end
it 'should add a non default instance to connection string' do
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=localhost\\LOGGING;User ID=sa;Password=Pupp3t1@')
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.\\LOGGING;User ID=sa;Password=Pupp3t1@')
subject.open_and_run_command('query', {:admin_user => 'sa', :admin_pass => 'Pupp3t1@', :instance_name => 'LOGGING'})
end
end
Expand All @@ -93,12 +93,12 @@ def stub_connection
end

it 'should add integrated security to the connection string if admin and password are empty' do
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=localhost;Integrated Security=SSPI')
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.;Integrated Security=SSPI')
subject.open_and_run_command('query', {:admin_user => '', :admin_pass => '', :admin_login_type => 'WINDOWS_LOGIN'})
end

it 'should add integrated security to the connection string if admin and password are not defined' do
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=localhost;Integrated Security=SSPI')
@connection.expects(:Open).with('Provider=SQLOLEDB.1;Initial Catalog=master;Application Name=Puppet;Data Source=.;Integrated Security=SSPI')
subject.open_and_run_command('query', { :admin_login_type => 'WINDOWS_LOGIN' })
end
end
Expand Down