Class: Nonnative::InvalidDataSocketPair

Inherits:
SocketPair
  • Object
show all
Defined in:
lib/nonnative/invalid_data_socket_pair.rb

Overview

Socket-pair variant used by the fault-injection proxy to simulate corrupted/incoherent traffic.

When active, client requests still pass through unchanged, but responses flowing back from the upstream socket are corrupted before they reach the client.

This behavior is enabled by calling FaultInjectionProxy#invalid_data.

Constant Summary collapse

LINE_DELIMITERS =
["\r\n", "\n", "\r"].freeze

Instance Method Summary collapse

Methods inherited from SocketPair

#initialize

Constructor Details

This class inherits a constructor from Nonnative::SocketPair

Instance Method Details

#connect(local_socket) ⇒ Object

Track the accepted client socket so we can corrupt only the response path.



18
19
20
21
22
23
24
# File 'lib/nonnative/invalid_data_socket_pair.rb', line 18

def connect(local_socket)
  @local_socket = local_socket

  super
ensure
  @local_socket = nil
end

#write(socket, data) ⇒ Integer

Writes corrupted data to the socket by mutating payload bytes.

Client requests are forwarded unchanged so the upstream service can still parse them. Responses flowing back to the client are corrupted in-place, which keeps line-based clients from hanging while ensuring echoed data does not come back unchanged.

Parameters:

  • socket (IO)

    the socket to write to

  • data (String)

    the original payload

Returns:

  • (Integer)

    number of bytes written



35
36
37
38
39
# File 'lib/nonnative/invalid_data_socket_pair.rb', line 35

def write(socket, data)
  return super unless socket.equal?(@local_socket)

  super(socket, corrupt(data))
end