Commits

Kaspar Schiess committed 01790b4

Fix: Proxy didn't work

Fixes a broken proxy that wasn't tested properly at the last release.

  • Participants
  • Parent commits 8ea7283

Comments (0)

Files changed (3)

lib/event_shipper/proxy.rb

         # unsupported signal SIGINFO
       end
 
+      main_loop
+    end
+
+    def main_loop
       transport.dispatch { |queue, message| 
-        # puts message }
-        redis.lpush queue, message }
+        handle_message queue, message }
+    end
+    def handle_message queue, message
+      # puts message
+      redis.lpush queue, message
     end
 
     attr_reader :host, :port

lib/event_shipper/udp.rb

       @filters.inject(obj) { |o, f| f.en(o) }
     end
     def decode obj
-      @filters.reverse.inject(obj) { |o, f| f.de(o) }
+      @filters.reverse.inject([obj, {}]) { |o, f| f.de(*o) }
     end
 
     # Sends messages via UDP to a central proxy. Using the queue argument, the
       loop do
         datagram, source_info = @socket.recvfrom(10 * 1024)
 
-        handle_message(datagram)
+        handle_message(datagram, &Proc.new)
       end
     end
   end

spec/lib/event_shipper/proxy_spec.rb

 require 'spec_helper'
 
 require 'event_shipper'
+require 'event_shipper/filters'
 
-describe EventShipper::Proxy do
+describe EventShipper::Proxy, 'with sample configuration' do
   let(:proxy) { described_class.new nil }
+  before(:each) {
+    proxy.configure_with(
+      'listen' => {
+        'host' => '127.0.0.1', 
+        'port' => 5050 }, 
+      'redis' => {
+        'host' => '127.0.0.1', 
+        'port' => '4567' }, 
+      'encrypt' => true, 
+      'users' => [
+        'test/pass/word' ])
+  }
 
   describe "#configure_with" do
-    it "configures all connections" do
-      proxy.configure_with(
-        'listen' => {
-          'host' => '127.0.0.1', 
-          'port' => 80 }, 
-        'redis' => {
-          'host' => '127.0.0.1', 
-          'port' => '4567' }, 
-        'encrypt' => true, 
-        'users' => [
-          'test/pass/word' ])
-
+    it "parses complex passwords correctly" do
       proxy.userdb.should == { 'test' => 'pass/word' }
     end
   end
+
+  describe 'round trip test' do
+    def send_message
+      t = EventShipper::UDP.new('localhost', '5050')
+      t.wrap EventShipper::Filter::Encrypt.new('test', 'pass/word')
+
+      t.send(a: 1)
+    end
+
+    it "receives message and deciphers it" do
+      flexmock(proxy).
+        should_receive(:handle_message).with('queue', {"a"=>1}).once.
+        and_raise('quit!')
+
+      Thread.start do
+        sleep 0.01
+        send_message
+      end.abort_on_exception = true
+
+      expect {
+        proxy.main_loop
+      }.to raise_error('quit!')
+    end
+  end
 end