Skip to content

Commit

Permalink
clean up jsapps config
Browse files Browse the repository at this point in the history
  • Loading branch information
johanlundberg committed Sep 29, 2023
1 parent fd8f86e commit 2815747
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 169 deletions.
80 changes: 46 additions & 34 deletions src/eduid/webapp/jsconfig/settings/jsapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,61 @@ class JsAppsConfig(PasswordConfigMixin):
This is sent to the client, so care must be taken to avoid setting secrets here.
"""

debug: bool = False
environment: EduidEnvironment = EduidEnvironment.production
csrf_token: Optional[str] = None
available_languages: dict[str, str] = Field(default={"en": "English", "sv": "Svenska"})
csrf_token: Optional[str] = None
dashboard_link: HttpUrl
dashboard_url: Optional[str] # deprecated
debug: bool = False
eduid_site_link: HttpUrl = "https://eduid.se"
eduid_site_name: str = "eduID"
eduid_site_url: str = "https://eduid.se"
dashboard_url: str
signup_url: str
reset_password_link: str # used for directing a user to the reset password app
static_faq_url: str
eduid_site_url: Optional[str] = "https://eduid.se" # deprecated
environment: EduidEnvironment = EduidEnvironment.production
faq_link: HttpUrl
reset_password_link: HttpUrl # used for directing a user to the reset password app
sentry_dsn: Optional[str] = None
signup_link: HttpUrl
signup_url: Optional[str] # deprecated
static_faq_url: Optional[str] # deprecated
# backend endpoint urls
authn_url: str
eidas_url: str
emails_url: str
group_mgmt_url: str
ladok_url: str
letter_proofing_url: str
login_base_url: AnyUrl
login_next_url: HttpUrl # Needs to be a full URL since the backend is on the idp, not on https://eduid.se
request_other_url: Optional[
authn_service_url: HttpUrl
authn_url: Optional[str] # deprecated
eidas_service_url: HttpUrl
eidas_url: Optional[str] # deprecated
emails_service_url: HttpUrl
emails_url: Optional[str] # deprecated
error_info_url: Optional[
HttpUrl
] = None # Needs to be a full URL since the backend is on the idp, not on https://eduid.se
error_info_url: Optional[
group_mgmt_service_url: HttpUrl
group_mgmt_url: Optional[str] # deprecated
ladok_service_url: HttpUrl
ladok_url: Optional[str] # deprecated
letter_proofing_service_url: HttpUrl
letter_proofing_url: Optional[str] # deprecated
login_base_url: Optional[AnyUrl] # deprecated
login_next_url: HttpUrl # Needs to be a full URL since the backend is on the idp, not on https://eduid.se
login_request_other_url: Optional[
HttpUrl
] = None # Needs to be a full URL since the backend is on the idp, not on https://eduid.se
lookup_mobile_proofing_url: str
mobile_url: Optional[str] = None # should be replaced by phone_url
oidc_proofing_freja_url: str
oidc_proofing_url: str
orcid_url: str
password_service_url: Optional[str] = None # should be replaced by reset_password_url
personal_data_url: str
phone_url: str
reset_passwd_url: Optional[str] = None # should be replaced by reset_password_url
reset_password_url: str
security_url: str
svipe_url: Optional[str] # if not set the frontend component will not show
token_service_url: Optional[str] = None # should be replaced by authn_url
login_service_url: HttpUrl
lookup_mobile_proofing_service_url: HttpUrl
lookup_mobile_proofing_url: Optional[str] # deprecated
orcid_service_url: HttpUrl
orcid_url: Optional[str] # deprecated
personal_data_service_url: HttpUrl
personal_data_url: Optional[str] # deprecated
phone_service_url: HttpUrl
phone_url: Optional[str] # deprecated
reset_password_service_url: HttpUrl
reset_password_url: Optional[str] # deprecated
security_service_url: HttpUrl
security_url: Optional[str] # deprecated
svipe_service_url: Optional[HttpUrl] # if not set the frontend component will not show
svipe_url: Optional[str] # deprecated
# Dashboard config
proofing_methods: list = Field(default=["letter", "lookup_mobile", "oidc", "eidas"])
default_country_code: int = 46
token_verify_idp: str
proofing_methods: list = Field(default=["letter", "lookup_mobile", "oidc", "eidas"])
token_verify_idp: HttpUrl
# Signup config
tous: Optional[dict[str, str]] = None
recaptcha_public_key: Optional[str] = None
tous: Optional[dict[str, str]] = None
38 changes: 29 additions & 9 deletions src/eduid/webapp/jsconfig/tests/data/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,46 @@ eduid:
jsconfig:
app_name: jsconfig
jsapps:
password_entropy: 12
password_length: 10
authn_service_url: 'https://dashboard.example.com/services/authn'
authn_url: 'authn_url'
dashboard_url: 'dashboard_url'
dashboard_link: 'https://example.com/dashboard'
dashboard_url: 'https://example.com/dashboard'
eidas_service_url: 'https://dashboard.example.com/services/eidas'
eidas_url: 'eidas_url'
emails_service_url: 'https://dashboard.example.com/services/email'
emails_url: 'emails_url'
error_info_url: 'https://idp.example.com/services/idp/error_info'
faq_link: 'https://example.com/faq'
group_mgmt_service_url: 'https://dashboard.example.com/services/group_mgmt'
group_mgmt_url: 'group_mgmt_url'
ladok_service_url: 'https://dashboard.example.com/services/ladok'
ladok_url: 'ladok_url'
letter_proofing_service_url: 'https://dashboard.example.com/services/letter'
letter_proofing_url: 'letter_proofing_url'
login_base_url: 'http://eduid.docker/login'
login_next_url: 'http://eduid.docker/login/next'
login_base_url: 'https://example.com/login'
login_next_url: 'https://idp.example.com/servics/idp/next'
login_request_other_url: 'https://idp.example.com/services/idp/other'
login_service_url: 'https://idp.example.com/servics/idp'
lookup_mobile_proofing_service_url: 'https://dashboard.example.com/services/mobile-proofing'
lookup_mobile_proofing_url: 'lookup_mobile_proofing_url'
oidc_proofing_freja_url: 'oidc_proofing_freja_url'
oidc_proofing_url: 'oidc_proofing_url'
orcid_service_url: 'https://dashboard.example.com/services/orcid'
orcid_url: 'orcid_url'
password_entropy: 12
password_length: 10
personal_data_service_url: 'https://dashboard.example.com/services/pdata'
personal_data_url: 'personal_data_url'
phone_service_url: 'https://dashboard.example.com/services/phone'
phone_url: 'phone_url'
recaptcha_public_key: 'public_key'
reset_password_link: 'https://example.com/reset-password'
reset_password_service_url: 'https://idp.example.com/servics/reset-password'
reset_password_url: 'reset_password_url'
security_service_url: 'https://idp.example.com/servics/security'
security_url: 'security_url'
sentry_dsn: 'sentry_dsn'
signup_link: 'https://example.com/signup'
signup_url: 'signup_url'
static_faq_url: 'static_faq_url'
token_verify_idp: 'token_verify_idp'
reset_password_link: 'reset_password_link'
svipe_service_url: 'https://dashboard.example.com/services/svipe'
svipe_url: 'svipe_url'
token_verify_idp: 'https://some-other-idp.example.com'
97 changes: 60 additions & 37 deletions src/eduid/webapp/jsconfig/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@
from typing import Any, Mapping, cast

from eduid.common.config.parsers import load_config
from eduid.common.testing_base import normalised_data
from eduid.webapp.common.api.testing import CSRFTestClient, EduidAPITestCase
from eduid.webapp.jsconfig.app import JSConfigApp, jsconfig_init_app
from eduid.webapp.jsconfig.settings.common import JSConfigConfig
from eduid.webapp.jsconfig.settings.jsapps import JsAppsConfig

DASHBOARD_LINK = "https://dashboard.example.com"
PERSONAL_DATA_SERVICE_URL = "https://example.com/personal_data_url"
FAQ_LINK = "https://example.com/static_faq_url"


class JSConfigTests(EduidAPITestCase[JSConfigApp]):
Expand All @@ -63,83 +69,100 @@ def update_config(self, config: dict[str, Any]) -> dict[str, Any]:
"server_name": "example.com",
"testing": True,
"jsapps": {
"password_entropy": 12,
"password_length": 10,
"authn_service_url": "https://dashboard.example.com/services/authn",
"authn_url": "authn_url",
"dashboard_url": "dashboard_url",
"dashboard_link": "https://example.com/dashboard",
"dashboard_url": "https://example.com/dashboard",
"eidas_service_url": "https://dashboard.example.com/services/eidas",
"eidas_url": "eidas_url",
"emails_service_url": "https://dashboard.example.com/services/email",
"emails_url": "emails_url",
"error_info_url": "https://idp.example.com/services/idp/error_info",
"faq_link": "https://example.com/faq",
"group_mgmt_service_url": "https://dashboard.example.com/services/group_mgmt",
"group_mgmt_url": "group_mgmt_url",
"ladok_service_url": "https://dashboard.example.com/services/ladok",
"ladok_url": "ladok_url",
"letter_proofing_service_url": "https://dashboard.example.com/services/letter",
"letter_proofing_url": "letter_proofing_url",
"login_base_url": "http://eduid.docker/login",
"login_next_url": "http://eduid.docker/login/next",
"login_base_url": "https://example.com/login",
"login_next_url": "https://idp.example.com/servics/idp/next",
"login_request_other_url": "https://idp.example.com/services/idp/other",
"login_service_url": "https://idp.example.com/servics/idp",
"lookup_mobile_proofing_service_url": "https://dashboard.example.com/services/mobile-proofing",
"lookup_mobile_proofing_url": "lookup_mobile_proofing_url",
"oidc_proofing_freja_url": "oidc_proofing_freja_url",
"oidc_proofing_url": "oidc_proofing_url",
"orcid_service_url": "https://dashboard.example.com/services/orcid",
"orcid_url": "orcid_url",
"password_entropy": 12,
"password_length": 10,
"personal_data_service_url": "https://dashboard.example.com/services/pdata",
"personal_data_url": "personal_data_url",
"phone_service_url": "https://dashboard.example.com/services/phone",
"phone_url": "phone_url",
"recaptcha_public_key": "public_key",
"reset_password_link": "https://example.com/reset-password",
"reset_password_service_url": "https://idp.example.com/servics/reset-password",
"reset_password_url": "reset_password_url",
"security_service_url": "https://idp.example.com/servics/security",
"security_url": "security_url",
"sentry_dsn": "sentry_dsn",
"signup_link": "https://example.com/signup",
"signup_url": "signup_url",
"static_faq_url": "static_faq_url",
"token_verify_idp": "token_verify_idp",
"reset_password_link": "reset_password_link",
"svipe_service_url": "https://dashboard.example.com/services/svipe",
"svipe_url": "svipe_url",
"token_verify_idp": "https://some-other-idp.example.com",
},
}
)
return config

def _validate_jsconfig(self, config_data: dict[str, Any]) -> None:
assert config_data["type"] == "GET_JSCONFIG_CONFIG_SUCCESS"
assert config_data["payload"].pop("success") is True # success is added by _make_payload but probably shouldn't
assert config_data["payload"]["csrf_token"] is not None

config_data["payload"]["csrf_token"] = None # csrf_token is None when config is first loaded
assert normalised_data(self.app.conf.jsapps.dict()) == normalised_data(config_data["payload"])

def test_get_config(self):
eppn = self.test_user_data["eduPersonPrincipalName"]
with self.session_cookie(self.browser, eppn) as client:
response = client.get("http://example.com/config")
self.assertEqual(response.status_code, 200)
self._validate_jsconfig(json.loads(response.data))

def test_get_dashboard_config(self):
eppn = self.test_user_data["eduPersonPrincipalName"]
with self.session_cookie(self.browser, eppn, subdomain="dashboard") as client:
response = client.get("http://dashboard.example.com/config")
response = client.get("http://dashboard.example.com/dashboard/config")

self.assertEqual(response.status_code, 200)

config_data = json.loads(response.data)

assert config_data["type"] == "GET_JSCONFIG_CONFIG_SUCCESS"
assert config_data["payload"]["dashboard_url"] == "dashboard_url"
assert config_data["payload"]["personal_data_url"] == "personal_data_url"
assert config_data["payload"]["static_faq_url"] == "static_faq_url"
assert config_data["payload"]["available_languages"] == [["en", "English"], ["sv", "Svenska"]]

assert config_data["payload"]["DASHBOARD_URL"] == "dashboard_url"
assert config_data["payload"]["PERSONAL_DATA_URL"] == "personal_data_url"
assert config_data["payload"]["STATIC_FAQ_URL"] == "static_faq_url"
assert config_data["payload"]["AVAILABLE_LANGUAGES"] == [["en", "English"], ["sv", "Svenska"]]
self._validate_jsconfig(json.loads(response.data))

def test_get_signup_config(self):
eppn = self.test_user_data["eduPersonPrincipalName"]
with self.session_cookie(self.browser, eppn, subdomain="signup") as client:
response = client.get("http://signup.example.com/signup/config")

self.assertEqual(response.status_code, 200)

config_data = json.loads(response.data)

assert config_data["type"] == "GET_JSCONFIG_SIGNUP_CONFIG_SUCCESS"
assert config_data["payload"]["dashboard_url"] == "dashboard_url"
assert config_data["payload"]["static_faq_url"] == "static_faq_url"
assert config_data["payload"]["available_languages"] == [["en", "English"], ["sv", "Svenska"]]
assert config_data["payload"]["DASHBOARD_URL"] == "dashboard_url"
assert config_data["payload"]["STATIC_FAQ_URL"] == "static_faq_url"
assert config_data["payload"]["AVAILABLE_LANGUAGES"] == [["en", "English"], ["sv", "Svenska"]]
self._validate_jsconfig(json.loads(response.data))

def test_get_login_config(self):
eppn = self.test_user_data["eduPersonPrincipalName"]
with self.session_cookie(self.browser, eppn, subdomain="login") as client:
response = client.get("http://login.example.com/login/config")

self.assertEqual(response.status_code, 200)
self._validate_jsconfig(json.loads(response.data))

config_data = json.loads(response.data)
def test_get_errors_config(self):
eppn = self.test_user_data["eduPersonPrincipalName"]
with self.session_cookie(self.browser, eppn) as client:
response = client.get("http://example.com/errors/config")

assert config_data["type"] == "GET_JSCONFIG_LOGIN_CONFIG_SUCCESS"
assert config_data["payload"]["password_entropy"] == 12
assert config_data["payload"]["password_length"] == 10
self.assertEqual(response.status_code, 200)
self._validate_jsconfig(json.loads(response.data))

def test_jsapps_config_from_yaml(self):
os.environ["EDUID_CONFIG_YAML"] = f"{self.data_dir}/config.yaml"
Expand Down
Loading

0 comments on commit 2815747

Please sign in to comment.