svanoort / pyresttest

Python Rest Testing
Apache License 2.0
1.15k stars 326 forks source link

Enviroment variables for auth_username and auth_password #283

Closed rdejuana closed 9 months ago

rdejuana commented 6 years ago

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!

verdverm commented 5 years ago

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]
roubaeli commented 5 years ago

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?