Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keywords for TRACE and CONNECT HTTP methods #390

Merged
merged 15 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ venv/*
env/*

.vscode/*

# ignore http server log
atests/http_server/http_server.log
5 changes: 5 additions & 0 deletions atests/__init__.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*** Settings ***
Resource res_setup.robot

Suite Setup Setup Flask Http Server
Suite Teardown Teardown Flask Http Server And Sessions
6 changes: 3 additions & 3 deletions atests/http_server/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def view_headers():
return jsonify(get_dict('headers'))


@app.route("/anything", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "TRACE"])
@app.route("/anything", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "TRACE", "HEAD", "CONNECT"])
def view_anything(anything=None):
"""Returns anything passed in request data.
---
Expand Down Expand Up @@ -68,7 +68,7 @@ def view_anything(anything=None):


@app.route(
"/status/<codes>", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "TRACE"]
"/status/<codes>", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "TRACE", "HEAD", "CONNECT"]
)
def view_status_code(codes):
"""Return status code or random status code if more than one are given
Expand Down Expand Up @@ -118,7 +118,7 @@ def view_status_code(codes):
return status_code(code)


@app.route("/redirect-to", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "TRACE"])
@app.route("/redirect-to", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "TRACE", "HEAD", "CONNECT", "OPTIONS"])
def redirect_to():
"""302/3XX Redirects to the given URL.
---
Expand Down
21 changes: 9 additions & 12 deletions atests/issues/17.robot
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
*** Settings ***
Library Collections
Library String
Library RequestsLibrary
Library OperatingSystem
Resource ../res_setup.robot
Library Collections
Library String
Library RequestsLibrary
Library OperatingSystem

Suite Setup Setup Flask Http Server
Suite Teardown Teardown Flask Http Server And Sessions

*** Variables ***
${JSON_DATA} '{"file":{"path":"/logo1.png"},"token":"some-valid-oauth-token"}'
${JSON_DATA} '{"file":{"path":"/logo1.png"},"token":"some-valid-oauth-token"}'


*** Test Cases ***
Delete Request With Data
${headers}= Create Dictionary Content-Type=application/json
${resp}= DELETE On Session ${GLOBAL_SESSION} /anything data=${JSON_DATA} headers=${headers}
Should Be Equal As Strings ${resp.json()}[method] DELETE

${headers}= Create Dictionary Content-Type=application/json
${resp}= DELETE On Session ${GLOBAL_SESSION} /anything data=${JSON_DATA} headers=${headers}
Should Be Equal As Strings ${resp.json()}[method] DELETE
24 changes: 12 additions & 12 deletions atests/issues/18.robot
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
*** Settings ***
Library Collections
Library String
Library RequestsLibrary
Library OperatingSystem
Resource ../res_setup.robot
Library Collections
Library String
Library RequestsLibrary
Library OperatingSystem

Suite Setup Setup Flask Http Server
Suite Teardown Teardown Flask Http Server And Sessions

*** Variables ***
${JSON_DATA} '{"file":{"path":"/logo1.png"},"token":"some-valid-oauth-token"}'
${JSON_DATA} '{"file":{"path":"/logo1.png"},"token":"some-valid-oauth-token"}'


*** Test Cases ***
Encoding Error
${headers}= Create Dictionary Content-Type=application/json
Set Suite Variable ${data} { "elementToken":"token", "matchCriteria":[{"field":"name","dataType":"string","useOr":"false","fieldValue":"Operation check 07", "closeParen": "false", "openParen": "false", "operator": "equalTo"}], "account": { "annualRevenue": "456666", "name": "Account", "numberOfEmployees": "integer", "billingAddress": { "city": "Miami", "country": "US", "countyOrDistrict": "us or fl", "postalCode": "33131", "stateOrProvince": "florida", "street1": "Trade Center", "street2": "North Main rd" }, "number": "432", "industry": "Bank", "type": "string", "shippingAddress": { "city": "denver", "country": "us", "countyOrDistrict": "us or co", "postalCode": "80202", "stateOrProvince": "colorado", "street1": "Main street", "street2": "101 Avenu"}}}
${headers}= Create Dictionary Content-Type=application/json
Set Suite Variable
... ${data}
... { "elementToken":"token", "matchCriteria":[{"field":"name","dataType":"string","useOr":"false","fieldValue":"Operation check 07", "closeParen": "false", "openParen": "false", "operator": "equalTo"}], "account": { "annualRevenue": "456666", "name": "Account", "numberOfEmployees": "integer", "billingAddress": { "city": "Miami", "country": "US", "countyOrDistrict": "us or fl", "postalCode": "33131", "stateOrProvince": "florida", "street1": "Trade Center", "street2": "North Main rd" }, "number": "432", "industry": "Bank", "type": "string", "shippingAddress": { "city": "denver", "country": "us", "countyOrDistrict": "us or co", "postalCode": "80202", "stateOrProvince": "colorado", "street1": "Main street", "street2": "101 Avenu"}}}

${resp}= POST On Session ${GLOBAL_SESSION} /anything data=${data} headers=${headers}
Should Be Equal As Strings ${resp.status_code} 200
${resp}= POST On Session ${GLOBAL_SESSION} /anything data=${data} headers=${headers}
Should Be Equal As Strings ${resp.status_code} 200
15 changes: 6 additions & 9 deletions atests/issues/259.robot
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
*** Settings ***
Library RequestsLibrary
Resource ../res_setup.robot
Library RequestsLibrary

Suite Setup Setup Flask Http Server
Suite Teardown Teardown Flask Http Server And Sessions

*** Test Cases ***
Post Content application/json With Empty Data Should Have No Body
${content-type}= Create Dictionary content-type application/json
${resp}= POST On Session ${GLOBAL_SESSION} /anything data=${EMPTY} headers=${content-type}
Should Be Empty ${resp.json()['data']}
${content-type}= Create Dictionary content-type application/json
${resp}= POST On Session ${GLOBAL_SESSION} /anything data=${EMPTY} headers=${content-type}
Should Be Empty ${resp.json()['data']}

Post Content With Empty Data Should Have No Body
${resp}= POST On Session ${GLOBAL_SESSION} /anything data=${EMPTY}
Should Be Empty ${resp.json()['data']}
${resp}= POST On Session ${GLOBAL_SESSION} /anything data=${EMPTY}
Should Be Empty ${resp.json()['data']}
29 changes: 13 additions & 16 deletions atests/issues/27.robot
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
*** Settings ***
Library Collections
Library String
Library RequestsLibrary
Library OperatingSystem
Resource ../res_setup.robot
Library Collections
Library String
Library RequestsLibrary
Library OperatingSystem

Suite Setup Setup Flask Http Server
Suite Teardown Teardown Flask Http Server And Sessions

*** Test Cases ***
Post Request With XML File
[Tags] post
${file_data}= Get File ${CURDIR}${/}test.xml
${files}= Create Dictionary xml=${file_data}
${headers}= Create Dictionary Authorization=testing-token
Log ${headers}
${resp}= POST On Session ${GLOBAL_SESSION} /anything files=${files} headers=${headers}
[Tags] post
${file_data}= Get File ${CURDIR}${/}test.xml
${files}= Create Dictionary xml=${file_data}
${headers}= Create Dictionary Authorization=testing-token
Log ${headers}
${resp}= POST On Session ${GLOBAL_SESSION} /anything files=${files} headers=${headers}

Log ${resp.json()}
Log ${resp.json()}

Set Test Variable ${req_headers} ${resp.json()['headers']}
Set Test Variable ${req_headers} ${resp.json()['headers']}

Dictionary Should Contain Key ${req_headers} Authorization
Dictionary Should Contain Key ${req_headers} Authorization
12 changes: 9 additions & 3 deletions atests/issues/305.robot
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
*** Settings ***
Library RequestsLibrary
Library RequestsLibrary


*** Test Cases ***
Test NTLM Session without installed library
${auth}= Create List 1 2 3
Run Keyword And Expect Error requests_ntlm module not installed Create Ntlm Session ntlm http://localhost:80 ${auth}
${auth}= Create List 1 2 3
Run Keyword And Expect Error
... requests_ntlm module not installed
... Create Ntlm Session
... ntlm
... http://localhost:80
... ${auth}
20 changes: 7 additions & 13 deletions atests/issues/315.robot
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
*** Settings ***
Library RequestsLibrary
Resource ../res_setup.robot
Library RequestsLibrary

Suite Setup Setup Flask Http Server
Suite Teardown Teardown Flask Http Server And Sessions

*** Test Cases ***
Test On Session Keyword With Verify As Parameter

${resp}= GET On Session ${GLOBAL_SESSION} / verify=${False}
Status Should Be OK ${resp}
${resp}= GET On Session ${GLOBAL_SESSION} / verify=${False}
Status Should Be OK ${resp}

Test On Session Keyword With None Cookies As Parameter

${resp}= GET On Session ${GLOBAL_SESSION} / cookies=${None}
Status Should Be OK ${resp}
${resp}= GET On Session ${GLOBAL_SESSION} / cookies=${None}
Status Should Be OK ${resp}

Test On Session Keyword With Cookies As Parameter

${resp}= GET On Session ${GLOBAL_SESSION} / cookies=${False}
Status Should Be OK ${resp}
${resp}= GET On Session ${GLOBAL_SESSION} / cookies=${False}
Status Should Be OK ${resp}
29 changes: 13 additions & 16 deletions atests/issues/320.robot
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
*** Settings ***
Library Collections
Library RequestsLibrary
Resource ../res_setup.robot
Library Collections
Library RequestsLibrary

Suite Setup Setup Flask Http Server
Suite Teardown Teardown Flask Http Server And Sessions

*** Test Cases ***
Test GET with list of values as params
${values_list}= Create List 1 2 3 4 5
${parameters}= Create Dictionary key ${values_list}
${resp}= GET On Session ${GLOBAL_SESSION} url=/anything params=${parameters}
Should Contain ${resp.json()}[url] ?key=1&key=2&key=3&key=4&key=5
Should Be Equal ${resp.json()}[args] ${parameters}
${values_list}= Create List 1 2 3 4 5
${parameters}= Create Dictionary key ${values_list}
${resp}= GET On Session ${GLOBAL_SESSION} url=/anything params=${parameters}
Should Contain ${resp.json()}[url] ?key=1&key=2&key=3&key=4&key=5
Should Be Equal ${resp.json()}[args] ${parameters}

Test GET with spaces in dictionary as params
${parameters}= Create Dictionary key v a l u e
${resp}= GET On Session ${GLOBAL_SESSION} url=/anything params=${parameters}
Should Be Equal ${resp.json()}[args] ${parameters}
${parameters}= Create Dictionary key v a l u e
${resp}= GET On Session ${GLOBAL_SESSION} url=/anything params=${parameters}
Should Be Equal ${resp.json()}[args] ${parameters}

Test GET with spaces in string as params
${parameters}= Create Dictionary
${resp}= GET On Session ${GLOBAL_SESSION} url=/anything params=key=v a l u e
Should Contain ${resp.json()}[url] v%20a%20l%20u%20e
${parameters}= Create Dictionary
${resp}= GET On Session ${GLOBAL_SESSION} url=/anything params=key=v a l u e
Should Contain ${resp.json()}[url] v%20a%20l%20u%20e
10 changes: 3 additions & 7 deletions atests/issues/334.robot
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
*** Settings ***
Library RequestsLibrary
Resource ../res_setup.robot
Library RequestsLibrary

Suite Setup Setup Flask Http Server
Suite Teardown Teardown Flask Http Server And Sessions

*** Test Cases ***

Test evaluated response is always the one passed
${response_error}= GET On Session ${GLOBAL_SESSION} url=/status/404 expected_status=any
${response_ok}= GET On Session ${GLOBAL_SESSION} url=/status/200 expected_status=any
${response_error}= GET On Session ${GLOBAL_SESSION} url=/status/404 expected_status=any
${response_ok}= GET On Session ${GLOBAL_SESSION} url=/status/200 expected_status=any
Status Should Be 404 ${response_error}
31 changes: 18 additions & 13 deletions atests/res_setup.robot
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*** Settings ***
Library Process
Library RequestsLibrary
Library Process
Library RequestsLibrary


*** Variables ***
Expand All @@ -9,28 +9,33 @@ ${HTTP_LOCAL_SERVER} http://localhost:5010


*** Keywords ***

Setup Test Session
${test_session}= Set Variable test_session
Set Test Variable ${test_session}
Create Session ${test_session} ${HTTP_LOCAL_SERVER}
${test_session}= Set Variable test_session
Set Test Variable ${test_session}
Create Session ${test_session} ${HTTP_LOCAL_SERVER}

Teardown Test Session
Delete All Sessions
# Restore global session
Create Session ${GLOBAL_SESSION} ${HTTP_LOCAL_SERVER}
lucagiove marked this conversation as resolved.
Show resolved Hide resolved

Setup Flask Http Server
${platform}= Evaluate sys.platform sys
${flask_cmd} = Set Variable If
... '${platform}'=='win32' ${CURDIR}/http_server/run.cmd
... ${CURDIR}/http_server/run.sh
${flask_cmd}= Set Variable If
... '${platform}'=='win32' ${CURDIR}/http_server/run.cmd
... ${CURDIR}/http_server/run.sh

Set global variable ${GLOBAL_SESSION} ${GLOBAL_SESSION}
Set global variable ${HTTP_LOCAL_SERVER} ${HTTP_LOCAL_SERVER}

# No way to have the return code or other data on the process since it's in background
Start Process ${flask_cmd} cwd=${CURDIR}/http_server/ alias=flask
Create Session ${GLOBAL_SESSION} ${HTTP_LOCAL_SERVER}
Start Process ${flask_cmd} cwd=${CURDIR}/http_server/ alias=flask stderr=http_server.log stdout=http_server.log
Create Session ${GLOBAL_SESSION} ${HTTP_LOCAL_SERVER}
Wait Until Http Server Is Up And Running

Wait Until Http Server Is Up And Running
Create Session wait-until-up ${HTTP_LOCAL_SERVER} max_retries=10
Get On Session wait-until-up /
Create Session wait-until-up ${HTTP_LOCAL_SERVER} max_retries=10
Get On Session wait-until-up /

Teardown Flask Http Server And Sessions
Delete All Sessions
Expand Down
43 changes: 21 additions & 22 deletions atests/test_authentication.robot
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
*** Settings ***
Library Collections
Library String
Library RequestsLibrary
Library customAuthenticator.py
Resource res_setup.robot
Library RequestsLibrary
Library customAuthenticator.py

Suite Setup Setup Flask Http Server
Suite Teardown Teardown Flask Http Server And Sessions

*** Test Cases ***

Get With Auth
[Tags] get get-cert
${auth}= Create List user passwd
Create Session httpbin https://httpbin.org auth=${auth} verify=${CURDIR}${/}cacert.pem
${resp}= GET On Session httpbin /basic-auth/user/passwd
Should Be Equal As Strings ${resp.status_code} 200
Should Be Equal As Strings ${resp.json()['authenticated']} True
[Tags] get get-cert
${auth}= Create List user passwd
Create Session httpbin https://httpbin.org auth=${auth} verify=${CURDIR}${/}cacert.pem
${resp}= GET On Session httpbin /basic-auth/user/passwd
Should Be Equal As Strings ${resp.status_code} 200
Should Be Equal As Strings ${resp.json()['authenticated']} True

Get With Custom Auth
[Tags] get
${auth}= Get Custom Auth user passwd
Create Custom Session httpbin https://httpbin.org auth=${auth} verify=${CURDIR}${/}cacert.pem
${resp}= GET On Session httpbin /basic-auth/user/passwd
Should Be Equal As Strings ${resp.status_code} 200
Should Be Equal As Strings ${resp.json()['authenticated']} True
[Tags] get
${auth}= Get Custom Auth user passwd
Create Custom Session httpbin https://httpbin.org auth=${auth} verify=${CURDIR}${/}cacert.pem
${resp}= GET On Session httpbin /basic-auth/user/passwd
Should Be Equal As Strings ${resp.status_code} 200
Should Be Equal As Strings ${resp.json()['authenticated']} True

Get With Digest Auth
[Tags] get get-cert
[Tags] get get-cert
${auth}= Create List user pass
Create Digest Session httpbin https://httpbin.org auth=${auth} debug=3 verify=${CURDIR}${/}cacert.pem
Create Digest Session
... httpbin
... https://httpbin.org
... auth=${auth}
... debug=3
... verify=${CURDIR}${/}cacert.pem
${resp}= GET On Session httpbin /digest-auth/auth/user/pass
Should Be Equal As Strings ${resp.status_code} 200
Should Be Equal As Strings ${resp.json()['authenticated']} True
Loading
Loading