usebruno / bruno

Opensource IDE For Exploring and Testing Api's (lightweight alternative to postman/insomnia)
https://www.usebruno.com/
MIT License
27.02k stars 1.24k forks source link

Bruno CLI doesn't seem to be injecting properly #3136

Open jfslin opened 1 month ago

jfslin commented 1 month ago

I have checked the following:

Describe the bug

I've taken a look around and it seems like most of the problems other people had with CLI revolves around injecting secrets, so I think I'm just doing something wrong. Given the following bru file, I am able to set the environment (named 'dev'), which sets sb_name and sb_anonkey (both env vars and not secrets) and run it as expected in the Bruno GUI. My ultimate goal is to use Bruno for CI in Github Actions, hence the CLI interest.

However, the following CLIs (Windows 11, Powershell as well as Command Prompt) doesn't seem to work, giving me a "invalid URL" error, suggesting that sb_name isn't being set properly:

bru.cmd run '.\testing\Patient-Access-Records\Auth.bru' --env dev bru.cmd run '.\testing\Patient-Access-Records\Auth.bru' --env-var sb_name=xxxxx --env-var host=yyyy

Also, is there a way to get the CLI to produce the outbound GET/POST message in the CLI so I can check what it's actually sending (ie the Timeline tab in the Bruno GUI) as oppose to just the runner result?

.bru file to reproduce the bug

meta {
  name: Auth
  type: http
  seq: 1
}

post {
  url: https://{{sb_name}}.supabase.co/auth/v1/token?grant_type=password
  body: json
  auth: none
}

params:query {
  grant_type: password
}

headers {
  apikey: {{sb_anonkey}}
}

body:json {
  {
    "email": "test@example.com",
    "password": "password"
  }
}

vars:post-response {
  jwt_user: res.body.access_token
}

tests {
  test("client can get JWT from supabase", function() {
    const data = res.getBody();
    expect(res.getStatus()).to.equal(200);
  });
}

Screenshots/Live demo link

Working in the GUI:

image

But not in the CLI:

C:\bruno> bru.cmd run '.\testing\Patient-Access-Records\Auth.bru' --env dev
Running Request

.\testing\Patient-Access-Records\Auth (Invalid URL)

Requests:    0 passed, 1 failed, 1 total
Tests:       0 passed, 0 total
Assertions:  0 passed, 0 total
Ran all requests - 0 ms

Requests:    0 passed, 1 failed, 1 total
Tests:       0 passed, 0 total
Assertions:  0 passed, 0 total
mjhcorporate commented 1 month ago

Hmm... the --verbose switch does not seem to work. That's a bug on it's own, I would say.

I'm not on windows, but on Mac, setting the env variables works as expected. Your command seems correct to me. Just to be on the safe side -- what version of the cli are you using (bru --help)?

jfslin commented 1 month ago

@mjhcorporate thank you for the quick response. In case it matters, I have Bruno GUI downloaded via Scoop and Bruno CLI via npm. I have the latest CLI:

C:\bruno> C:\Users\user\AppData\Roaming\npm\bru.cmd --help
Bru CLI 1.29.0
Usage: bru.js <command> [options]

Commands:
  bru.js run [filename]  Run a request

Options:
      --version  Show version number                                   [boolean]
  -h, --help     Show help                                             [boolean]

Documentation: https://docs.usebruno.com (v1.29.0)

I can also confirm that --verbose flag doesn't do anything for me either.

eddimcbenz commented 1 month ago

I'm also encountering the same issues. It seams that on CLI the vars are not injected. e.g. {{domain}}/1.0/service/{{countryCode}}/:supportedChannel On the GUI the request is http://example.com/1.0/service/en/testChannel. But running the CLI in the result the following request is there: http://example.com/1.0/service/en/{{supportedChannel}}

When I directly write the value into the path variable it works, but this takes away the opportunity to be flexible.