getanteon/anteon

Support for Operating System Environment Variables in Config File

fatihbaltaci opened this issue ยท 8 comments

The Ddosify load testing tool currently allows users to start a load test using a JSON configuration file with the -config option. More info. However, there is no functionality to inject operating system environment variables into various fields of the JSON configuration file such as body, URL, header key, header value, basic auth user, and pass.

It would be beneficial to provide support for using operating system environment variables in the config.json file using a specific format like {{$USER}}. Below is an example of how this might be implemented for the USER environment variable from the operating system:

{
    "output": "stdout",
    "duration": 100,
    "load_type": "linear",
    "iteration_count": 10,
    "steps": [
        {
            "id": 1,
            "url": "https://servdown.com",
            "name": "",
            "method": "GET",
            "headers": {
                "os-user": "{{$USER}}"
            },
            "timeout": 10
        }
    ]
}

Expected Behavior:

Ddosify should recognize and replace environment variable placeholders, such as {{$USER}}, with the corresponding values from the operating system. The format is: {{$ANY_OS_VARIABLE}}

This should apply to all relevant fields in the JSON configuration file, including:

  • body
  • URL
  • header key
  • header value
  • basic auth user
  • basic auth pass.

If Ddosify did not find the environment variable in the operating system, it should exit with an error. Example: {{$USER}} is not found in the operating system environment variables

Current Behavior:

There is no support for injecting operating system environment variables into the JSON configuration file. It gave err: ScenarioValidationError {{$USER}} is not defined to use by global and captured environments error.

Hi @fatihbaltaci can I work on this feature?

Hi @KshitijBharde, sure, I assigned the issue to you. Is there any missing part in the proposal? Thanks.

Hi @fatihbaltaci, the proposal seems complete. I will raise a pr for it or update you here if there's any blocker.
Do you have any starter points for me?
Like, which files would require changes, or do I have to use a certain library for achieving this?

You can start with environment.go: https://github.com/ddosify/ddosify/blob/a24fcf98322cac626f4093783b9cfd7e08e3dc04/core/scenario/scripting/injection/environment.go#L217

Before the if block, you should check the os environment.

Hi @fatihbaltaci I have implemented the above feature and I was testing it with the payload parameter of scenario config and I was not able to make an HTTP request with content-type: "application/json", the payload is being sent as a binary file

Raised a PR: #165

#161 (comment)

Could you please share your config file?

@fatihbaltaci nevermind it's my bad, I made a typo with the content type, it's working fine with "content-type": "application/json"

Final config json:

{
    "output": "stdout",
    "duration": 100,
    "load_type": "linear",
    "iteration_count": 10,
    "steps": [
        {
            "id": 1,
            "url": "http://localhost:3002/ping",
            "name": "",
            "method": "POST",
            "headers": {
                "os-user": "kb",
                "content-type": "application/json"
            },
            "payload" : "{\"name\": \"{{$USER}}\"}",
            "timeout": 10
        }
    ]
}