Skip to content

Commit

Permalink
Add missing responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Colin-b committed Sep 29, 2024
1 parent 82592f2 commit 63079b8
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ async def test_oauth2_authorization_code_flow_is_able_to_reuse_client(
reply_url="http://localhost:5000#code=SplxlOBeZQQYbYS6WxSbIA&state=ce9c755b41b5e3c5b64c70598715d5de271023a53f39a67a70215d265d11d2bfb6ef6e9c701701e998e69cbdbf2cee29fd51d2a950aa05f59a20cf4a646099d5",
)

httpx_mock.add_response(
method="POST",
url="https://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": 10,
"example_parameter": "example_value",
},
match_content=b"grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F&response_type=code&code=SplxlOBeZQQYbYS6WxSbIA",
match_headers={"x-test": "Test value"},
)

httpx_mock.add_response(
url="https://authorized_only",
method="GET",
match_headers={
"Authorization": "Bearer 2YotnFZFEjr1zCsicMWpAA",
},
)
async with httpx.AsyncClient() as client:
await client.get("https://authorized_only", auth=auth)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ def test_oauth2_authorization_code_flow_is_able_to_reuse_client(
opened_url="https://provide_code?response_type=code&state=ce9c755b41b5e3c5b64c70598715d5de271023a53f39a67a70215d265d11d2bfb6ef6e9c701701e998e69cbdbf2cee29fd51d2a950aa05f59a20cf4a646099d5&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F",
reply_url="http://localhost:5000#code=SplxlOBeZQQYbYS6WxSbIA&state=ce9c755b41b5e3c5b64c70598715d5de271023a53f39a67a70215d265d11d2bfb6ef6e9c701701e998e69cbdbf2cee29fd51d2a950aa05f59a20cf4a646099d5",
)
httpx_mock.add_response(
method="POST",
url="https://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": 10,
"example_parameter": "example_value",
},
match_content=b"grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F&response_type=code&code=SplxlOBeZQQYbYS6WxSbIA",
match_headers={"x-test": "Test value"},
)

httpx_mock.add_response(
url="https://authorized_only",
method="GET",
match_headers={
"Authorization": "Bearer 2YotnFZFEjr1zCsicMWpAA",
},
)

with httpx.Client() as client:
client.get("https://authorized_only", auth=auth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,25 @@ async def test_oauth2_pkce_flow_is_able_to_reuse_client(
opened_url="https://provide_code?response_type=code&state=ce9c755b41b5e3c5b64c70598715d5de271023a53f39a67a70215d265d11d2bfb6ef6e9c701701e998e69cbdbf2cee29fd51d2a950aa05f59a20cf4a646099d5&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F&code_challenge=5C_ph_KZ3DstYUc965SiqmKAA-ShvKF4Ut7daKd3fjc&code_challenge_method=S256",
reply_url="http://localhost:5000#code=SplxlOBeZQQYbYS6WxSbIA&state=ce9c755b41b5e3c5b64c70598715d5de271023a53f39a67a70215d265d11d2bfb6ef6e9c701701e998e69cbdbf2cee29fd51d2a950aa05f59a20cf4a646099d5",
)
httpx_mock.add_response(
method="POST",
url="https://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": 10,
"example_parameter": "example_value",
},
match_content=b"code_verifier=MTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEx&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F&response_type=code&code=SplxlOBeZQQYbYS6WxSbIA",
match_headers={"x-test": "Test value"},
)
httpx_mock.add_response(
url="https://authorized_only",
method="GET",
match_headers={
"Authorization": "Bearer 2YotnFZFEjr1zCsicMWpAA",
},
)

async with httpx.AsyncClient() as client:
await client.get("https://authorized_only", auth=auth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ def test_oauth2_pkce_flow_is_able_to_reuse_client(
opened_url="https://provide_code?response_type=code&state=ce9c755b41b5e3c5b64c70598715d5de271023a53f39a67a70215d265d11d2bfb6ef6e9c701701e998e69cbdbf2cee29fd51d2a950aa05f59a20cf4a646099d5&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F&code_challenge=5C_ph_KZ3DstYUc965SiqmKAA-ShvKF4Ut7daKd3fjc&code_challenge_method=S256",
reply_url="http://localhost:5000#code=SplxlOBeZQQYbYS6WxSbIA&state=ce9c755b41b5e3c5b64c70598715d5de271023a53f39a67a70215d265d11d2bfb6ef6e9c701701e998e69cbdbf2cee29fd51d2a950aa05f59a20cf4a646099d5",
)
httpx_mock.add_response(
method="POST",
url="https://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": 10,
"example_parameter": "example_value",
},
match_content=b"code_verifier=MTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTExMTEx&grant_type=authorization_code&redirect_uri=http%3A%2F%2Flocalhost%3A5000%2F&response_type=code&code=SplxlOBeZQQYbYS6WxSbIA",
match_headers={"x-test": "Test value"},
)
httpx_mock.add_response(
url="https://authorized_only",
method="GET",
match_headers={
"Authorization": "Bearer 2YotnFZFEjr1zCsicMWpAA",
},
)

with httpx.Client() as client:
client.get("https://authorized_only", auth=auth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ async def test_oauth2_client_credentials_flow_is_able_to_reuse_client(

time.sleep(10)

httpx_mock.add_response(
method="POST",
url="https://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": 10,
"refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter": "example_value",
},
match_headers={"x-test": "Test value"},
match_content=b"grant_type=client_credentials",
)
httpx_mock.add_response(
url="https://authorized_only",
method="GET",
match_headers={
"Authorization": "Bearer 2YotnFZFEjr1zCsicMWpAA",
},
)
async with httpx.AsyncClient() as client:
await client.get("https://authorized_only", auth=auth)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ def test_oauth2_client_credentials_flow_is_able_to_reuse_client(

time.sleep(10)

httpx_mock.add_response(
method="POST",
url="https://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": 10,
"refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter": "example_value",
},
match_headers={"x-test": "Test value"},
match_content=b"grant_type=client_credentials",
)
httpx_mock.add_response(
url="https://authorized_only",
method="GET",
match_headers={
"Authorization": "Bearer 2YotnFZFEjr1zCsicMWpAA",
},
)
with httpx.Client() as client:
client.get("https://authorized_only", auth=auth)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ async def test_oauth2_password_credentials_flow_is_able_to_reuse_client(

time.sleep(10)

httpx_mock.add_response(
method="POST",
url="https://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": 10,
"example_parameter": "example_value",
},
match_content=b"grant_type=password&username=test_user&password=test_pwd",
match_headers={"x-test": "Test value"},
)
httpx_mock.add_response(
url="https://authorized_only",
method="GET",
match_headers={
"Authorization": "Bearer 2YotnFZFEjr1zCsicMWpAA",
},
)
async with httpx.AsyncClient() as client:
await client.get("https://authorized_only", auth=auth)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ def test_oauth2_password_credentials_flow_is_able_to_reuse_client(

time.sleep(10)

httpx_mock.add_response(
method="POST",
url="https://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": 10,
"example_parameter": "example_value",
},
match_content=b"grant_type=password&username=test_user&password=test_pwd",
match_headers={"x-test": "Test value"},
)
httpx_mock.add_response(
url="https://authorized_only",
method="GET",
match_headers={
"Authorization": "Bearer 2YotnFZFEjr1zCsicMWpAA",
},
)
with httpx.Client() as client:
client.get("https://authorized_only", auth=auth)

Expand Down Expand Up @@ -399,6 +418,18 @@ def test_oauth2_password_credentials_flow_refresh_token_invalid(
match_content=b"grant_type=refresh_token&refresh_token=tGzv3JOkF0XG5Qx2TlKWIA",
)

httpx_mock.add_response(
method="POST",
url="https://provide_access_token",
json={
"access_token": "2YotnFZFEjr1zCsicMWpAA",
"token_type": "example",
"expires_in": "0",
"refresh_token": "tGzv3JOkF0XG5Qx2TlKWIA",
"example_parameter": "example_value",
},
match_content=b"grant_type=password&username=test_user&password=test_pwd",
)
httpx_mock.add_response(
url="https://authorized_only",
method="GET",
Expand Down Expand Up @@ -440,6 +471,13 @@ def test_oauth2_password_credentials_flow_refresh_token_access_token_not_expired
with httpx.Client() as client:
client.get("https://authorized_only", auth=auth)

httpx_mock.add_response(
url="https://authorized_only",
method="GET",
match_headers={
"Authorization": "Bearer 2YotnFZFEjr1zCsicMWpAA",
},
)
# expect Bearer token to remain the same
with httpx.Client() as client:
client.get("https://authorized_only", auth=auth)
Expand Down

0 comments on commit 63079b8

Please sign in to comment.