svanoort / pyresttest

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

Issue with Basic Auth or Package Installation #35

Closed wadeaa closed 9 years ago

wadeaa commented 9 years ago

Hi, I installed your package as per your readme instructions and after running through the quickstart I started to play with my own API - a call to a Basic Auth secured function using the following YAML:


Running with the command 'resttest.py http://10.1.1.84:80 apitest2.yaml --log debug --interactive true --print-bodies true' gives the following:

Get /session/

REQUEST: GET http://10.1.1.84:80/api/session/ Press ENTER when ready: DEBUG:Initial Test Result, based on expected response code: False RESPONSE: Unauthorized Access DEBUG:{"test": {"expected_status": [200], "_headers": {}, "group": "Session", "name": "Get /session/", "_url": "http://10.1.1.84:80/api/session/", "templated": {}}, "failures": [{"failure_type": "Invalid HTTP Response Code", "message": "Invalid HTTP response code: response code 401 not in expected codes [[200]]", "validator": null, "details": null}], "response_code": 401, "body": "Unauthorized Access", "passed": false} ERROR:Test Failed: Get /session/ URL=http://10.1.1.84:80/api/session/ Group=Session HTTP Status Code: 401

ERROR:Test Failure, failure type: Invalid HTTP Response Code, Reason: Invalid HTTP response code: response code 401 not in expected codes [[200]]

Test Group Session FAILED: 0/1 Tests Passed!

No sign of the auth info in the data. So I had a look at the code, got confused as it seemed fine then ran the resttest.py script directly in python (after adding the line 'print "AUTH: %s:%s" % (mytest.auth_username, mytest.auth_password)' at line 268 in /pyrestest/resttest.py) to get the following:

Get /session/

REQUEST: GET http://10.1.1.84:80/api/session/ AUTH: wade.a.a@googlemail.com:pass Press ENTER when ready: DEBUG:Initial Test Result, based on expected response code: True DEBUG:no validators found RESPONSE: { "duration": 43200, "friendly_name": "A Wade", "token": "eyJhbGciOiJIUzI1NiIsImV4cCI6MTQyMzg2OTk4NCwiaWF0IjoxNDIzODI2Nzg0fQ.eyJlbWFpbCI6ImFyY2hpZS53YWRlQGFyaWEtbmV0d29ya3MuY29tIn0.NaoVU3gM-JDEy162R1TcBpZgzkpgmsGwqryJTSpm1rI" } DEBUG:{"body": "{\n \"duration\": 43200, \n \"friendly_name\": \"A Wade\", \n \"token\": \"eyJhbGciOiJIUzI1NiIsImV4cCI6MTQyMzg2OTk4NCwiaWF0IjoxNDIzODI2Nzg0fQ.eyJlbWFpbCI6ImFyY2hpZS53YWRlQGFyaWEtbmV0d29ya3MuY29tIn0.NaoVU3gM-JDEy162R1TcBpZgzkpgmsGwqryJTSpm1rI\"\n}", "response_headers": {"content-length": "235", "expires": "Fri, 13 Feb 2015 11:26:23 GMT", "server": "nginx/1.4.6 (Ubuntu)", "connection": "close", "pragma": "no-cache", "cache-control": "no-cache", "date": "Fri, 13 Feb 2015 11:26:24 GMT", "content-type": "application/json"}, "response_code": 200, "passed": true, "test": {"expected_status": [200], "_headers": {}, "group": "Session", "name": "Get /session/", "_url": "http://10.1.1.84:80/api/session/", "templated": {}, "auth_password": "pass", "auth_username": "wade.a.a@googlemail.com"}, "failures": []}

INFO:Test Succeeded: Get /session/ URL=http://10.1.1.84:80/api/session/ Group=Session

Test Group Session SUCCEEDED: 1/1 Tests Passed!

Which is what I expected originally. So why would the Auth work fine on one run through but not the other? I suspect the install is pointing to an older version of the script somehow, but I don't know enough to prove that.

Also, running the test:

Leads to : Traceback (most recent call last): File "resttest.py", line 720, in command_line_run(sys.argv[1:]) File "resttest.py", line 716, in command_line_run main(args) File "resttest.py", line 685, in main failures = run_testsets(tests) File "resttest.py", line 547, in run_testsets result = run_test(test, test_config = myconfig, context=context) File "resttest.py", line 250, in run_test curl = templated_test.configure_curl(timeout=test_config.timeout, context=my_context) File "/home/archie/Projects/APITesting/pyresttest/pyresttest/tests.py", line 264, in configure_curl curl.setopt(curl.READFUNCTION, StringIO(bod).read) TypeError: must be string or buffer, not None

presumably because of (intentional but perhaps misguided) lack of a body in the PUT call.

I really like the package though, it will be very useful in the future, so thank you very much for building it and putting it up here.

Cheers, Wade

svanoort commented 9 years ago

Wade,

Thank you for you very detailed and helpful bug report. First, the issue with the zero-length PUT: good catch, I've written a test locally to catch this, fixed it, and released it, please give it a try. :-)

For the auth header issue: This is a new feature that was merged in but had not been released to PyPi until today. Is it possible you had a PyPi release and a repo clone both on the same system? (This would give different behaviour with different executions.)

Please could you try this with the newest version from PyPi and make sure you're not running with a local install from the project's repo (or within the repo itself)?
The following should only work with a pip install or local easy_install

resttest.py URL test_file.yaml

Thanks, Sam

wadeaa commented 9 years ago

Hi,

Thanks for your response and my apologies. It seems you were absolutely correct and I had an older version of the library installed from PyPi. I've updated and everything works fine now. Thanks again.

Wade

On 13 February 2015 at 13:26, Sam Van Oort notifications@github.com wrote:

Wade,

Thank you for you very detailed and helpful bug report. First, the issue with the zero-length PUT: good catch, I've written a test locally to catch this, fixed it, and released it, please give it a try. :-)

For the auth header issue: This is a new feature that was merged in but had not been released to PyPi until today. Is it possible you had a PyPi release and a repo clone both on the same system? (This would give different behaviour with different executions.)

Please could you try this with the newest version from PyPi and make sure you're not running with a local install from the project's repo (or within the repo itself)?

The following should only work with a pip install or local easy_install

resttest.py URL path should on

Thanks, Sam

— Reply to this email directly or view it on GitHub https://github.com/svanoort/pyresttest/issues/35#issuecomment-74252840.

svanoort commented 9 years ago

Hi Wade, I'm glad that cleared up the issue for you! In the future I'll try to keep code merges and PyPi releases in closer step to avoid this sort of issue.

Thanks, Sam