Sha256: 4947b4ed0d64272bc420024bf9e919acf021867f6dac0b8b3ad33740e856f888

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'
require 'ronin/formatting/extensions/sql/string'

describe String do
  before(:all) do
    @string = '/etc/passwd'
    @sql_encoded = '0x2f6574632f706173737764'
    @string_with_quotes = %{"O'Brian"}
  end

  it "should provide the #sql_escape method" do
    @string.should respond_to(:sql_escape)
  end

  it "should provide the #sql_encode method" do
    @string.should respond_to(:sql_encode)
  end

  it "should provide the #sql_decode method" do
    @string.should respond_to(:sql_decode)
  end

  describe "SQL escaping" do
    it "should be able to single-quote escape" do
      @string_with_quotes.sql_escape(:single).should == %{'"O''Brian"'}
    end

    it "should be able to double-quote escape" do
      @string_with_quotes.sql_escape(:double).should == %{"""O'Brian"""}
    end
  end

  describe "SQL-hex encoding" do
    it "should be able to be SQL-hex encoded" do
      @string.sql_encode.should == @sql_encoded
    end

    it "should return an empty String if empty" do
      ''.sql_encode.should == ''
    end
  end

  describe "SQL-hex decoding" do
    it "should be able to be SQL-hex decoded" do
      encoded = @string.sql_encode

      encoded.should == @sql_encoded
      encoded.sql_decode.should == @string
    end

    it "should be able to decode SQL comma-escaping" do
      "'Conan O''Brian'".sql_decode.should == "Conan O'Brian"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ronin-support-0.3.0 spec/formatting/sql/string_spec.rb