svanoort / pyresttest

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

auth_username cannot be templated #214

Open klambrec opened 7 years ago

klambrec commented 7 years ago

Hi !

First of all, thank you the effort on this handy little project, This is already the 2nd time it comes in handy while doing REST API development / validation. I seem to have found a limitation however. My API provides a token in the body which I get out using extract_binds. The API then expects this token in other requests as the "username" field of future requests but this field is unfortunately not templateable.

root@aeef312cd6fc:/opt/api# resttest.py --ssl-insecure http://localhost:8000 ../tests/tokens.yaml Traceback (most recent call last): File "/usr/local/bin/resttest.py", line 4, in resttest.command_line_run(sys.argv[1:]) File "/usr/local/lib/python3.4/dist-packages/pyresttest/resttest.py", line 911, in command_line_run main(args) File "/usr/local/lib/python3.4/dist-packages/pyresttest/resttest.py", line 830, in main working_directory=os.path.dirname(test_file), vars=my_vars) File "/usr/local/lib/python3.4/dist-packages/pyresttest/resttest.py", line 252, in parse_testsets mytest = Test.parse_test(base_url, child) File "/usr/local/lib/python3.4/dist-packages/pyresttest/tests.py", line 461, in parse_test if use_config_parser(mytest, configelement, configvalue): File "/usr/local/lib/python3.4/dist-packages/pyresttest/tests.py", line 454, in use_config_parser converted = myparsing0 File "/usr/local/lib/python3.4/dist-packages/pyresttest/tests.py", line 76, in coerce_string_to_ascii raise TypeError("Input {0} is not a string, string expected".format(val)) TypeError: Input {'template': '$token_1'} is not a string, string expected root@aeef312cd6fc:/opt/api# resttest.py --ssl-insecure http://localhost:8000 ../tests/tokens.yaml Traceback (most recent call last): File "/usr/local/bin/resttest.py", line 4, in resttest.command_line_run(sys.argv[1:]) File "/usr/local/lib/python3.4/dist-packages/pyresttest/resttest.py", line 911, in command_line_run main(args) File "/usr/local/lib/python3.4/dist-packages/pyresttest/resttest.py", line 830, in main working_directory=os.path.dirname(test_file), vars=my_vars) File "/usr/local/lib/python3.4/dist-packages/pyresttest/resttest.py", line 252, in parse_testsets mytest = Test.parse_test(base_url, child) File "/usr/local/lib/python3.4/dist-packages/pyresttest/tests.py", line 461, in parse_test if use_config_parser(mytest, configelement, configvalue): File "/usr/local/lib/python3.4/dist-packages/pyresttest/tests.py", line 454, in use_config_parser converted = myparsing0 File "/usr/local/lib/python3.4/dist-packages/pyresttest/tests.py", line 76, in coerce_string_to_ascii raise TypeError("Input {0} is not a string, string expected".format(val)) TypeError: Input {'template': '{$token_1}'} is not a string, string expected

rosskarchner commented 6 years ago

I wanted to note here that I tried to use template credentials today, and like the above, I was disappointed when it didn't work. My work around was to include the credentials in the URL (like https://username:password@host/my/api/v2 -- but that ends up including the password in log messages, which is non-ideal.