<commit_before>require 'webrick'
require 'spec_helper'

describe 'Bugsnag' do
  server = nil
  queue = Queue.new

  before do
    server = WEBrick::HTTPServer.new :Port => 0, :Logger => WEBrick::Log.new("/dev/null"), :AccessLog => []
    server.mount_proc '/' do |req, res|
      queue.push req.body
      res.status = 200
      res.body = "OK\n"
    end
    Thread.new{ server.start }
  end
  after do
    server.stop
  end

  let(:request) { JSON.parse(queue.pop) }

  it 'should send notifications over the wire' do
    Bugsnag.configure do |config|
      config.endpoint = "localhost:#{server.config[:Port]}"
      config.use_ssl = false
    end
    WebMock.allow_net_connect!

    Bugsnag.notify 'yo'

    expect(request['events'][0]['exceptions'][0]['message']).to eq('yo')
  end

  it 'should send deploys over the wire' do
    Bugsnag.configure do |config|
      config.endpoint = "localhost:#{server.config[:Port]}"
      config.use_ssl = false
    end
    WebMock.allow_net_connect!

    Bugsnag::Deploy.notify :app_version => '1.1.1'

    expect(request['appVersion']).to eq('1.1.1')
  end
end<commit_msg>add a better test for proxy support<commit_after>require 'webrick'
require 'spec_helper'

describe 'Bugsnag' do
  server = nil
  queue = Queue.new

  before do
    server = WEBrick::HTTPServer.new :Port => 0, :Logger => WEBrick::Log.new("/dev/null"), :AccessLog => []
    server.mount_proc '/' do |req, res|
      queue.push req.body
      res.status = 200
      res.body = "OK\n"
    end
    Thread.new{ server.start }
  end
  after do
    server.stop
  end

  let(:request) { JSON.parse(queue.pop) }

  it 'should send notifications over the wire' do
    Bugsnag.configure do |config|
      config.endpoint = "localhost:#{server.config[:Port]}"
      config.use_ssl = false
    end
    WebMock.allow_net_connect!

    Bugsnag.notify 'yo'

    expect(request['events'][0]['exceptions'][0]['message']).to eq('yo')
  end

  it 'should send deploys over the wire' do
    Bugsnag.configure do |config|
      config.endpoint = "localhost:#{server.config[:Port]}"
      config.use_ssl = false
    end
    WebMock.allow_net_connect!

    Bugsnag::Deploy.notify :app_version => '1.1.1'

    expect(request['appVersion']).to eq('1.1.1')
  end

  describe 'with a proxy' do
    proxy = nil
    pqueue = Queue.new

    before do
      proxy = WEBrick::HTTPServer.new :Port => 0, :Logger => WEBrick::Log.new("/dev/null"), :AccessLog => []
      proxy.mount_proc '/' do |req, res|
        pqueue.push req
        res.status = 200
        res.body = "OK\n"
      end
      Thread.new{ proxy.start }
    end
    after do
      proxy.stop
    end

    let(:proxied_request) { pqueue.pop }

    it 'should use a proxy when configured' do
      Bugsnag.configure do |config|

        config.endpoint = "localhost:#{server.config[:Port]}"
        config.use_ssl = false

        config.proxy_host = 'localhost'
        config.proxy_port = proxy.config[:Port]
        config.proxy_user = 'conrad'
        config.proxy_password = <PASSWORD>'
      end

      Bugsnag.notify 'oy'

      r = proxied_request

      expect(r.header['proxy-authorization'].first).to eq("Basic Y29ucmFkOiRlY3JldA==")
      expect(r.request_line).to eq("POST http://localhost:#{server.config[:Port]}/ HTTP/1.1\r\n")
    end
  end
end
{'fraction_non_alphanumeric': 0.1382335148215366, 'fraction_numerical': 0.009981851179673321, 'mean_word_length': 2.801149425287356, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4642155', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1112, 'n_words': 252}