Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Jul 21, 2023
1 parent 71b7fb0 commit 6748ef7
Show file tree
Hide file tree
Showing 7 changed files with 312 additions and 110 deletions.
8 changes: 8 additions & 0 deletions README-SATOSA.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@
5. Customize [example/satosa/disco.html](example/satosa/disco.html), then copy it in satosa static file folder. Example `example/static/disco.html`

Then start the proxy.

# Parameters

TBD. A Markdown table with:

- parameter name
- description
- example value
40 changes: 19 additions & 21 deletions pyeudiw/satosa/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import base64
import uuid

from urllib.parse import urlencode, quote_plus
from satosa.response import Response
Expand Down Expand Up @@ -36,7 +37,6 @@ def __init__(self, auth_callback_func, internal_attributes, config, base_url, na
:type base_url: str
:type name: str
"""

super().__init__(auth_callback_func, internal_attributes, base_url, name)

self.client_id = config['metadata']['client_id']
Expand All @@ -53,6 +53,7 @@ def __init__(self, auth_callback_func, internal_attributes, config, base_url, na
self.config['metadata']['jwks'] = config["metadata_jwks"]

self.federation_jwk = JWK(self.config['federation']['federation_jwks'][0])
self.metadata_jwk = JWK(self.config["metadata_jwks"][0])

logger.debug(f"Loaded configuration:\n{json.dumps(config)}")

Expand Down Expand Up @@ -116,14 +117,14 @@ def entity_configuration_endpoint(self, context, *args):
},
plain_dict=data
),
status="200 OK",
status="200",
content="application/entity-statement+jwt"
)

def pre_request_endpoint(self, context, *args):
payload = {
'client_id': self.client_id,
'request_uri': self.complete_request_url
'request_uri': self.absolute_request_url
}
url_params = urlencode(payload, quote_via=quote_plus)

Expand All @@ -133,37 +134,35 @@ def pre_request_endpoint(self, context, *args):

return Response(
response,
status="200 OK",
status="200",
content="text/json; charset=utf8"
)

def redirect_endpoint(self, context, *args):
jwk = JWK()
jwk = self.metadata_jwk

helper = JWSHelper(jwk)
jwt = helper.sign({
"jti": "f47c96a1-f928-4768-aa30-ef32dc78aa69",
data = {
"jti": str(uuid.uuid4()),
"htm": "GET",
"htu": "https://verifier.example.org/request_uri",
"htu": f"{self.client_id}/request_uri",
"iat": int(datetime.now().timestamp()),
"ath": "fUHyO2r2Z3DZ53EsNrWBb0xWXoaNy59IiKCAqksmQEo"
},
"RS256",
)

}
jwt = helper.sign(data)
response = {"request": jwt}

return Response(
json.dumps(response),
status="200 OK",
content="text/json; charset=utf8"
status="200",
content="application/jose; charset=utf8"
)

def request_endpoint(self, context, *args):
jwk = JWK()
jwk = self.metadata_jwk

helper = JWSHelper(jwk)
jwt = helper.sign({
data = {
"state": "3be39b69-6ac1-41aa-921b-3e6c07ddcb03",
"vp_token": "eyJhbGciOiJFUzI1NiIs...PT0iXX0",
"presentation_submission": {
Expand All @@ -182,15 +181,14 @@ def request_endpoint(self, context, *args):
}
]
}
},
"RS256",
)
}
jwt = helper.sign(data)

response = {"response": jwt}

return Response(
json.dumps(response),
status=200,
status="200",
content="text/json; charset=utf8"
)

Expand Down Expand Up @@ -226,7 +224,7 @@ def handle_error(
result = json.dumps(
{"message": message, "troubleshoot": troubleshoot}
)
return Response(result, content="text/json; charset=utf8", status=403)
return Response(result, content="text/json; charset=utf8", status="403")

def authn_response(self, context, binding):
"""
Expand Down
Loading

0 comments on commit 6748ef7

Please sign in to comment.