* ENT-3007 auth/saml/v0/saml/providerdata and auth/saml/v0/saml/providerconfig endpoints Move code to subfolder for samlproviderconfig extra comma undo accidental remove of import GET works for a single config now Use ModelViewSet to get all CRUD method. Test still fails Add auth/saml/v0/providerdata endpoints fixup reverse and test issue, remove leading caret just triggering run, why is it failing in CI? pycodelint fixes Skip auth tests unless feature is on Tests for post/put for samlproviderdata move urls to their own folders api tests for post samlprovierconfig create 1 providerconfig test case lint fixes lint lint cleanup code local urls /samlproviderconfig works note needed right now Fix import errors lint unused import wip: first attempt at rbac auth and jwt cookie in test round 2 with enterprise uuid as url param for samlproviderconfig improve tests, still dont pass fix test by using system role, wip other test fix create test add get/post tests for providerdata isort fixes string lint fix Cleanup based on feedback round1 move utils to tests package Move util fn to openedx.feature area lint ENT-3007 : Round 2 of work on auth/saml/v0/providerconfig and auth/saml/v0/providerdata endpoints * Fix test issue use string uuid for permission obj * snake case changes provider_config * snake case * provider_data, tests and lint * patch and delete tests for providerdata * snake_case * snake_case * snake_case * make patch test stronger * 404 if invalid uuid for get param * common util for validate uuid4 * unused import * lint fixes for pycodestyle * 400 when uuid is missing * 400 instead of 404 for missing uuid * spell fix * update docstring for api usage * docstring clarify
31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
"""
|
|
Utility functions for use in SAMLProviderConfig, SAMLProviderData tests
|
|
"""
|
|
|
|
from edx_rest_framework_extensions.auth.jwt.cookies import jwt_cookie_name
|
|
from edx_rest_framework_extensions.auth.jwt.tests.utils import generate_jwt_token, generate_unversioned_payload
|
|
|
|
|
|
def _jwt_token_from_role_context_pairs(user, role_context_pairs):
|
|
"""
|
|
Generates a new JWT token with roles assigned from pairs of (role name, context).
|
|
"""
|
|
roles = []
|
|
for role, context in role_context_pairs:
|
|
role_data = '{role}'.format(role=role)
|
|
if context is not None:
|
|
role_data += ':{context}'.format(context=context)
|
|
roles.append(role_data)
|
|
|
|
payload = generate_unversioned_payload(user)
|
|
payload.update({'roles': roles})
|
|
return generate_jwt_token(payload)
|
|
|
|
|
|
def set_jwt_cookie(client, user, role_context_pairs=None):
|
|
"""
|
|
Set jwt token in cookies
|
|
"""
|
|
jwt_token = _jwt_token_from_role_context_pairs(user, role_context_pairs or [])
|
|
client.cookies[jwt_cookie_name()] = jwt_token
|