pyresttest icon indicating copy to clipboard operation
pyresttest copied to clipboard

Enviroment variables for auth_username and auth_password

Open rdejuana opened this issue 6 years ago • 2 comments

howdy, I've been combing the docs and code, is there a way to use environment variables for basic auth creds? I have something like this. Am I missing something?

- config:
    - generators:
        - 'username': {type: 'env_variable', variable_name: 'BASIC_USER_ID'}
        - 'password': {type: 'env_variable', variable_name: 'BASIC_PASSWORD'}
...

- test:
    - generator_binds: {username: username, password: password}
    - auth_username: $username
    - auth_password: $password
...

thank you!

rdejuana avatar Jul 11 '18 17:07 rdejuana

I got the following to work

---
- config:
    - testset: "Admin app tests"
    - generators:
        - 'apikey': {type: 'env_string', 'string': "$APIKEY"}

- test:
    - name: "Fail without authentication"
    - url: "/admin/users/list"
    - expected_status: [400]

- test:
    - generator_binds: {apikey: apikey}
    - name: "Pass with authentication"
    - url: "/admin/users/list"
    - headers: {template: {"Authorization": "Bearer $apikey"}}
    - expected_status: [200]

verdverm avatar Oct 24 '18 22:10 verdverm

I think it's because of this line in the documentation:

Currently, templating is only supported for the request body, URL, and headers. There are technical challenges adding it everywhere, it's coming as part of a rewrite of framework internals.

Any update on if this is planned to change at least for authentication values any time soon?

roubaeli avatar Nov 27 '18 15:11 roubaeli