Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def fetch_saml_response(self: "BrowserAzureCredentialsProvider", token):
if missing_padding:
saml_assertion += "=" * missing_padding

return str(base64.urlsafe_b64decode(saml_assertion))
return base64.urlsafe_b64decode(saml_assertion).decode("utf-8")

# SAML Response is required to be sent to base class. We need to provide a minimum of:
# samlp:Response XML tag with xmlns:samlp protocol value
Expand All @@ -189,10 +189,10 @@ def wrap_and_encode_assertion(self: "BrowserAzureCredentialsProvider", saml_asse
'<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/>'
"</samlp:Status>"
"{saml_assertion}"
"</samlp:Response>".format(saml_assertion=saml_assertion[2:-1])
"</samlp:Response>".format(saml_assertion=saml_assertion)
)

return str(base64.b64encode(saml_response.encode("utf-8")))[2:-1]
return base64.b64encode(saml_response.encode("utf-8")).decode("utf-8")

def run_server(
self: "BrowserAzureCredentialsProvider", listen_socket: socket.socket, idp_response_timeout: int, state: str
Expand Down
4 changes: 2 additions & 2 deletions test/unit/plugin/data/browser_azure_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
)


saml_response = b"my_access_token"
saml_response = b"\"my_access_token\"".decode("utf-8")

valid_json_response: dict = {
"token_type": "Bearer",
"expires_in": "3599",
"ext_expires_in": "3599",
"expires_on": "1602782647",
"resource": "spn:1234567891011121314151617181920",
"access_token": "bXlfYWNjZXNzX3Rva2Vu", # base64.urlsafe_64encode(saml_response)
"access_token": "Im15X2FjY2Vzc190b2tlbiI=", # base64.urlsafe_64encode(saml_response)
"issued_token_type": "urn:ietf:params:oauth:token-type:saml2",
"refresh_token": "my_refresh_token",
"id_token": "my_id_token",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def mock_get_json() -> typing.Dict:
mocked_post.return_value = mock_get_resp()

saml_assertion: str = bacp.fetch_saml_response(token="blah")
assert str(browser_azure_data.saml_response) == saml_assertion
assert browser_azure_data.saml_response == saml_assertion


malformed_json_responses: typing.List[typing.Tuple[typing.Optional[typing.Dict], str]] = [
Expand Down