Sha256: ea178f9a5883ea03fbcc20a8e1355d806a4573c208f927be27effae75a931729

Contents?: true

Size: 1.99 KB

Versions: 2

Compression:

Stored size: 1.99 KB

Contents

# encoding: UTF-8
require 'winrm/winrm_service'
require 'rexml/document'
require 'erb'
require 'base64'

describe 'issue 184', unit: true do
  let(:shell_id)    { 'shell-123' }
  let(:command_id)  { 123 }
  let(:test_data_xml_template) do
    ERB.new(File.read('spec/stubs/responses/get_command_output_response.xml.erb'))
  end
  let(:service) do
    WinRM::WinRMWebService.new(
      'http://dummy/wsman',
      :plaintext,
      user: 'dummy',
      pass: 'dummy')
  end

  describe 'response doc stdout with invalid UTF-8 characters' do
    let(:test_data_stdout) { 'ffff' } # Base64-decodes to '}\xF7\xDF', an invalid sequence
    let(:test_data_stderr) { '' }
    let(:test_data_xml)    { test_data_xml_template.result(binding) }

    before do
      allow(service).to receive(:send_get_output_message).and_return(
        REXML::Document.new(test_data_xml)
      )
    end

    it 'does not raise an ArgumentError: invalid byte sequence in UTF-8' do
      begin
        expect(
          service.get_command_output(shell_id, command_id)
        ).not_to raise_error
      rescue RSpec::Expectations::ExpectationNotMetError => e
        expect(e.message).not_to include 'ArgumentError'
      end
    end

    it 'does not have an empty stdout' do
      expect(
        service.get_command_output(shell_id, command_id)[:data][0][:stdout]
      ).not_to be_empty
    end
  end

  describe 'response doc stdout with valid UTF-8' do
    let(:test_data_raw)    { '✓1234-äöü' }
    let(:test_data_stdout) { Base64.encode64(test_data_raw) }
    let(:test_data_stderr) { '' }
    let(:test_data_xml)    { test_data_xml_template.result(binding) }

    before do
      allow(service).to receive(:send_get_output_message).and_return(
        REXML::Document.new(test_data_xml)
      )
    end

    it 'decodes to match input data' do
      expect(
        service.get_command_output(shell_id, command_id)[:data][0][:stdout]
      ).to eq(test_data_raw)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
winrm-1.7.3 spec/issue_184_spec.rb
winrm-1.7.1 spec/issue_184_spec.rb