Skip to content

Is an infrastructure simulator to test effortlessy your app in minutes for MQTT, Redis, Amqp, MySQL, Postgres, Http, Https and MongoDB native protocols.

License

Notifications You must be signed in to change notification settings

kendarorg/the-protocol-master

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Protocol Master

"The Protocol Master" is an infrastructure simulator to test effortlessy your app in minutes (with no coding) supporting HTTP, HTTPS, Postgres, MySQL, Redis, Mqtt, RabbitMQ, AMQP 091 ... and all the compatible ones!

  • Simulate wrong scenarios
  • Block troubles before production
  • Simulate whole infrastructure
  • Make untestable apps testable
  • Easy Chaos engineering

Effortlessy and with zero budget

Get Started

Look at "The Protocol Master Samples" repository to create a complete docker environment to have a gimplse of the features

How it works

It's simple it's a multiprotocol proxy on your box (or wetheaver you want) Independent from the stack you are using

Scenarios

  • Simulate what-if without hitting real servers
  • Testing resiliency, errors and wrong data
  • Security analisys (what goes on the wire)
  • Test new APIs easily
  • Understand all consequences of changes

Custom Plugins

You can build your own plugins, just place the Jar into the plugins dir and intercept all it's intercepted by TPM. Add headers, change data, simulate specific needs

Examples

Open a http/s proxy on port 9999 and record everything that goes through

java -jar protocol-runner.jar -protocol http -proxy 9999 \
    -record

Create a local postgres "forward proxy" to a real one and record everything

java -jar protocol-runner.jar -protocol postgres  \
    -connection jdbc:postgresql://REALSERVER:5432  \
    -login REALLOGIN -password REALPWD \
    -record

Open a http/s proxy on port 9999 and return a 503 error, on 50% of calls

java -jar protocol-runner.jar -protocol http -proxy 9999 \
    -showError 503 -errorPercent 40

Features

  • Language independent: use the native protocols without drivers
  • Run on all OSs
    • Windows
    • Linux
    • macOs
  • Native protocol for (and all compatibles):
    • anything that goes through http/https
    • postgres
    • mysql
    • mongoDB
    • redis 3,redis 2
    • mqtt
    • rabbitmq/Amqp 0.9
  • Mocked flow (all)
  • Support gzip,brotli,jacksonSmile,multipart and more (http/s)
  • Mocked error response (http/s)
  • Mocked (optionally parametrized) responses (http/s,mysql,postgres) (nth, and count)
  • Internal rewrite queries and urls (http/s,mysql,postgres)
  • Record/replay activity-Gold standards-Zero infrastructure (all)
  • Handle callback mocks during replay automagically (mqtt,amqp,redis)
  • Custom transparent proxy (all)
  • Translate postgres and MySQL to any Jdbc supported db like Oracle!
  • Plugin-based architecture
  • Custom maven repository on https://maven.kendar.org
  • More than 70% Instructions coverage

The configuration is based on command line parameters or a json properties file for the usage check here

For the api usage here is the swagger: http//localhost:apisPort/swagger-ui/index.html

If you want to go on the specific functions by protocol:

  • Http
    • Support Http and Https as Man In The Middle
    • Custom proxy to intercept without DNS changes
  • PostgresSQL Usable for most db (for hibernate you should set the final db dialect of course)
    • Support for simple and extended query protocol
    • Transactions
    • Simple authentication (could add an "auth provider")
  • MySQL
    • Support for cached queries and stored procedures
    • Simple authentication (could add an "auth provider")
  • MongoDB
    • Basic authentication
  • RabbitMq/AMQP 0.9.1
    • Support for all kind of publish/consume
    • Channels multiplexing
  • Redis
    • Support for subscriptions
    • Support for push parsing
    • RESP2 and RESP3 supported out of the box
  • Mqtt
    • Support QOS 1,2,3
    • Support 3.x and 5.x protocols

Help

The Protocol Master

	un     	unattended	Unattended run (default false)
	cfg    	config    	Load config file
	pld    	pluginsDir	Plugins directory (default plugins)
	dd     	datadir   	Data directory (default data)
	ll     	loglevel  	Log4j loglevel (default ERROR)
	ap     	apis      	The port TPM controllers (default 0, as not active)
	lt     	logType   	The log type (default file)
	h      	help      	Show help
	p      	protocol  	The protocols to start
	       	          	Options: amqp091|mqtt|http|mysql|mongodb|postgres|redis

Amqp 0.9.1 Protocol

	po     	port      	Listening port (default 5672)
	pc     	connection	Connection (example amqp://localhost:5372)
	pt     	timeout   	Timeout (deafult 30)
	pu     	login     	Remote login
	pw     	password  	Remote password
	record 	          	Record Calls
	replay 	          	Replay calls

Mqtt Protocol

	po     	port      	Listening port (default 1883)
	pc     	connection	Connection (example tcp://localhost:1884)
	pt     	timeout   	Timeout (deafult 30)
	pu     	login     	Remote login
	pw     	password  	Remote password
	record 	          	Record Calls
	replay 	          	Replay calls

http Protocol

	ht     	http      	Http port (default 80
	hs     	https     	Https port (default 443
	prx    	proxy     	Proxy port (default 9999
	cn     	cname     	Cname (default C=US,O=Local Development,CN=local.org
	der    	          	Der file (default resource://certificates/ca.der
	key    	          	Key file (default resource://certificates/ca.key
	rew    	rewrite   	Path of the rewrite queries file
	record 	          	Record Calls
	replay 	          	Replay calls
	errors 	          	Random errors
	latency	          	Random latency

mysql Protocol

	po     	port      	Listening port (default 3306)
	pc     	connection	Connection (example jdbc:mysql://localhost:3306)
	pt     	timeout   	Timeout (deafult 30)
	pu     	login     	Remote login
	pw     	password  	Remote password
	js     	schema    	Force schema name
	rew    	rewrite   	Path of the rewrite queries file
	record 	          	Record Calls
	replay 	          	Replay calls

MongoDb Protocol

	po     	port      	Listening port (default 27018)
	pc     	connection	Connection (example mongodb://localhost:27018)
	pt     	timeout   	Timeout (deafult 30)
	pu     	login     	Remote login
	pw     	password  	Remote password
	record 	          	Record Calls
	replay 	          	Replay calls

postgres Protocol

	po     	port      	Listening port (default 5432)
	pc     	connection	Connection (example jdbc:postgresql://localhost:5432/db?ssl=false)
	pt     	timeout   	Timeout (deafult 30)
	pu     	login     	Remote login
	pw     	password  	Remote password
	js     	schema    	Force schema name
	rew    	rewrite   	Path of the rewrite queries file
	record 	          	Record Calls
	replay 	          	Replay calls

Redis Protocol

	po     	port      	Listening port (default 6379)
	pc     	connection	Connection (example redis://localhost:5372)
	pt     	timeout   	Timeout (deafult 30)
	record 	          	Record Calls
	replay 	          	Replay calls

How it was Born

I had an always missing QA environment and all changes should be checked by legal (it was in Electronic ID field). I needed to simulate APIs, Database calls, and full scenarios, from UI to the DB.

I started developing a series of docker container in PHP to intercept all incoming and outgoing HTTP/S call, with DNS server and certificates, you can find it here.

Becoming the thing too hard to cope with i started the development of a Java integrated version with fancy UI and all integrated service, the HttpAnsweringMachine based on Spring-Boot and leveraging a custom routing system, dns server and so on.

But that was too really hard to interact with. I started developing a JDBC->HTTP->JDBC driver, Janus-Jdbc from scratch, then started creating a similar thing for .NET, thing went rogues in a short time with Janus-Ado. But i started understanding Postgres protocol.

I started then with a command line utility to parse and translate binary protocols and that's how "The Protocol Master" was born. Always with a plugin-based architecture. Then i started adapting all the knowledge of HttpAnsweringMachine inside it to handle HTTP/S.

If you like it Buy me a coffe :)

paypal

The state machine-Behaviour tree

TLDR

The state machine (or better the Behaviour tree fsm) is based on

  • States (extending ProtoState) able to interact with events
  • Events (extending BaseEvent) to invoke action on states
  • Context (extending ProtoContext) it is the memory storage for the current execution (connection) and the current state

Execution

When bytes arrives to the TM they are transformed in a "BytesEvent" and then consumed by the specific connection thread, then all the child states of the current state are verified. They have the responsibility to check if the message is of the correct type and then if the content is matching the signature.

When a state is hit it can send events or response messages. When an execution runs without errors then the "executed incoming buffer" is purged from the received bytes

The events are immediatly executed. If no bytes are present or there are not enough bytes to read, the events queue is seeked for "BytesEvent" and then the execution is retried.