2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/resource"
|
|
|
|
require "inspec/resources/mssql_session"
|
2017-05-02 14:35:54 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "Inspec::Resources::MssqlSession" do
|
|
|
|
it "verify default mssql_session configuration" do
|
|
|
|
resource = load_resource("mssql_session", user: "sa", password: "yourStrong(!)Password")
|
|
|
|
_(resource.user).must_equal "sa"
|
|
|
|
_(resource.password).must_equal "yourStrong(!)Password"
|
|
|
|
_(resource.host).must_equal "localhost"
|
2018-01-16 22:04:00 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify mssql_session configuration with custom hostname" do
|
|
|
|
resource = load_resource("mssql_session", user: "sa", password: "yourStrong(!)Password", host: "inspec.domain.tld")
|
|
|
|
_(resource.user).must_equal "sa"
|
|
|
|
_(resource.password).must_equal "yourStrong(!)Password"
|
|
|
|
_(resource.host).must_equal "inspec.domain.tld"
|
2018-01-16 22:04:00 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify mssql_session configuration with custom instance" do
|
|
|
|
resource = load_resource("mssql_session", user: "sa", password: "yourStrong(!)Password", instance: "SQL2012INSPEC")
|
|
|
|
_(resource.user).must_equal "sa"
|
|
|
|
_(resource.password).must_equal "yourStrong(!)Password"
|
|
|
|
_(resource.host).must_equal "localhost"
|
|
|
|
_(resource.instance).must_equal "SQL2012INSPEC"
|
2017-06-29 15:01:32 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify mssql_session configuration with custom instance and port" do
|
|
|
|
resource = load_resource("mssql_session", user: "sa", password: "yourStrong(!)Password", instance: "SQL2012INSPEC", port: "1691")
|
|
|
|
_(resource.user).must_equal "sa"
|
|
|
|
_(resource.password).must_equal "yourStrong(!)Password"
|
|
|
|
_(resource.host).must_equal "localhost"
|
|
|
|
_(resource.port).must_equal "1691"
|
|
|
|
_(resource.instance).must_equal "SQL2012INSPEC"
|
2018-05-31 17:47:28 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify mssql_session configuration with custom sqlserver port and user in domain" do
|
|
|
|
resource = load_resource("mssql_session", user: 'DOMAIN\sa', password: "yourStrong(!)Password", host: "localhost", port: "1533")
|
2017-09-18 19:49:20 +00:00
|
|
|
_(resource.user).must_equal 'DOMAIN\sa'
|
2019-06-11 22:24:35 +00:00
|
|
|
_(resource.password).must_equal "yourStrong(!)Password"
|
|
|
|
_(resource.host).must_equal "localhost"
|
|
|
|
_(resource.port).must_equal "1533"
|
2017-09-18 19:49:20 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify mssql_session configuration with port explicitly nil" do
|
|
|
|
resource = load_resource("mssql_session", user: "sa", password: "yourStrong(!)Password", host: "localhost", port: nil)
|
|
|
|
_(resource.user).must_equal "sa"
|
|
|
|
_(resource.password).must_equal "yourStrong(!)Password"
|
|
|
|
_(resource.host).must_equal "localhost"
|
2018-05-31 17:47:28 +00:00
|
|
|
_(resource.port).must_be_nil
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "verify mssql_session configuration with local mode" do
|
|
|
|
resource = load_resource("mssql_session", local_mode: true)
|
2018-05-31 17:47:28 +00:00
|
|
|
_(resource.user).must_be_nil
|
|
|
|
_(resource.password).must_be_nil
|
|
|
|
_(resource.host).must_be_nil
|
|
|
|
_(resource.port).must_be_nil
|
|
|
|
_(resource.local_mode).must_equal true
|
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "run a SQL query" do
|
2021-06-30 11:49:18 +00:00
|
|
|
resource = load_resource("mssql_session", user: "sa", password: "yourStrong(!)Password", host: "localhost", port: "1433")
|
2017-06-29 15:01:32 +00:00
|
|
|
query = resource.query("SELECT SERVERPROPERTY('ProductVersion') as result")
|
|
|
|
_(query.size).must_equal 1
|
2019-06-11 22:24:35 +00:00
|
|
|
_(query.row(0).column("result").value).must_equal "14.0.600.250"
|
2017-05-02 14:35:54 +00:00
|
|
|
end
|
|
|
|
end
|