Sha256: 07c5ff4523dbe2714d216134ad2a97028ca2586a96d78d618d0e8670ce8c8b7b

Contents?: true

Size: 941 Bytes

Versions: 46

Compression:

Stored size: 941 Bytes

Contents

# encoding: utf-8
# author: Christoph Hartmann
# author: Dominik Richter

module Inspec::Resources
  class MssqlSession < Inspec.resource(1)
    name 'mssql_session'
    desc 'Use the mssql_session InSpec audit resource to test SQL commands run against a MS Sql Server database.'
    example "
      sql = mssql_session('myuser','mypassword')
      describe sql.query('select * from sys.databases where name like \'*test*\') do
        its('stdout') {should_not match(/test/) }
      end
    "

    def initialize(user = nil, pass = nil)
      @user = user
      @pass = pass
      skip_resource('user and pass are required for MSSQL tests') if @user.nil? or @pass.nil?
    end

    def query(q)
      escaped_query = q.gsub(/\\/, '\\\\').gsub(/"/, '\\"').gsub(/\$/, '\\$').gsub(/\@/, '`@')
      cmd = inspec.command("sqlcmd -U #{@user} -P #{@pass} -Q \"#{escaped_query}\"")

      cmd
    end

    def to_s
      'MSSQL'
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
inspec-1.23.0 lib/resources/mssql_session.rb
inspec-1.22.0 lib/resources/mssql_session.rb
inspec-1.21.0 lib/resources/mssql_session.rb
inspec-1.20.0 lib/resources/mssql_session.rb
inspec-1.19.2 lib/resources/mssql_session.rb
inspec-1.19.1 lib/resources/mssql_session.rb
inspec-1.19.0 lib/resources/mssql_session.rb
inspec-1.18.0 lib/resources/mssql_session.rb
inspec-1.17.0 lib/resources/mssql_session.rb
inspec-1.16.1 lib/resources/mssql_session.rb
inspec-1.16.0 lib/resources/mssql_session.rb
inspec-1.15.0 lib/resources/mssql_session.rb
inspec-1.14.1 lib/resources/mssql_session.rb
inspec-1.14.0 lib/resources/mssql_session.rb
inspec-1.13.0 lib/resources/mssql_session.rb
inspec-1.12.0 lib/resources/mssql_session.rb
inspec-1.11.0 lib/resources/mssql_session.rb
inspec-1.10.0 lib/resources/mssql_session.rb
inspec-1.9.0 lib/resources/mssql_session.rb
inspec-1.8.0 lib/resources/mssql_session.rb