Skip to content

Commit

Permalink
OM-180 (#24)
Browse files Browse the repository at this point in the history
* OM-180 Changed default language for mpass user to RO

* OM-180 Fixed flake8 issues
  • Loading branch information
malinowskikam authored Jun 4, 2024
1 parent ec2a3d6 commit a5634b6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
13 changes: 8 additions & 5 deletions msystems/apps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from django.apps import AppConfig

DEFAULT_CFG = {
"default_mpass_language": "ro",

# URL to be redirected to after successful login
"mpass_login_redirect": "",

# Mpass configurations
"mpass_config": {
# Strict mode: SAML responses must be validated strictly.
Expand Down Expand Up @@ -95,19 +98,19 @@ class MsystemsConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "msystems"

##### DO NOT CHANGE THIS ####
# DO NOT CHANGE THIS ####
ADMIN = "Admin"
INSPECTOR = "Inspector"
EMPLOYER = "Employer"
IMIS_ADMIN = "IMIS Administrator"
ENROLMENT_OFFICER = "Enrolment Officer"
##### ------------------ ####
# ------------------ ####

mpass_config = None
mpass_login_redirect = None
default_mpass_language = None

mpass_login_redirect = None
mpass_config = None
mpay_config = None

mconnect_config = None

def ready(self):
Expand Down
2 changes: 1 addition & 1 deletion msystems/services/saml_user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _create_user(self, username: str, user_data: dict) -> User:
login_name=username,
other_names=user_data.get('FirstName')[0],
last_name=user_data.get('LastName')[0],
language_id='en',
language_id=MsystemsConfig.default_mpass_language,
audit_user_id=0,
is_associated=False,
private_key=token_hex(128),
Expand Down
2 changes: 1 addition & 1 deletion msystems/tests/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
'Test Organisation 2 1234123412341'
],
'Role': ['Employer']
}
}
8 changes: 5 additions & 3 deletions msystems/views/mpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ def _validate_envelope(ctx):
try:
verify_timestamp(root)
except ValueError as e:
logger.error(f"Timestamp verification failed", exc_info=e)
logger.error("Timestamp verification failed", exc_info=e)
raise Fault(faultcode='InvalidRequest', faultstring=str(e))

try:
verify_signature(root, MsystemsConfig.mpay_config['mpay_certificate'])
except SignatureVerificationFailed as e:
logger.error("Envelope signature verification failed", exc_info=e)
raise Fault(faultcode='InvalidRequest', faultstring=f'Envelope signature verification failed')
raise Fault(faultcode='InvalidRequest', faultstring='Envelope signature verification failed')


def _add_envelope_header(ctx):
Expand Down Expand Up @@ -155,7 +155,9 @@ def GetOrderDetails(ctx, query: OrderDetailsQuery) -> GetOrderDetailsResult:
Reason="Voucher Acquirement",
ServiceID=query.ServiceID,
Status=_order_status_map[bill.status],
TotalAmountDue=str(bill.amount_total)
TotalAmountDue=str(bill.amount_total),
IssuedAt=bill.date_created.strftime("%Y-%m-%dT%H:%M:%SZ"),
DueAt=bill.date_due.strftime("%Y-%m-%dT%H:%M:%SZ"),
)

ret = GetOrderDetailsResult(OrderDetails=order_details)
Expand Down
1 change: 1 addition & 0 deletions msystems/xml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def replace_utc_timezone_with_offset(dt_str):
# Python 3.9 does not support Z timezone in datetime strings
return re.sub(r'Z$', '+00:00', dt_str)


def verify_timestamp(root):
dt_now = datetime.datetime.from_ad_datetime(py_datetime.datetime.now(tz=py_datetime.timezone.utc))
created, expires = root.find(created_xpath), root.find(expires_xpath)
Expand Down

0 comments on commit a5634b6

Please sign in to comment.