|
| 1 | +import json |
| 2 | + |
| 3 | +from httpretty import HTTPretty |
| 4 | + |
| 5 | +from .oauth import OAuth2Test |
| 6 | +from .test_open_id_connect import OpenIdConnectTestMixin |
| 7 | + |
| 8 | +class VaultOpenIdConnectTest(OpenIdConnectTestMixin, OAuth2Test): |
| 9 | + backend_path = \ |
| 10 | + 'social_core.backends.vault.VaultOpenIdConnect' |
| 11 | + issuer = 'https://vault.example.net:8200/v1/identity/oidc/provider/default' |
| 12 | + openid_config_body = json.dumps({ |
| 13 | + 'issuer': 'https://vault.example.net:8200/v1/identity/oidc/provider/default', |
| 14 | + 'jwks_uri': 'https://vault.example.net:8200/v1/identity/oidc/provider/default/.well-known/keys', |
| 15 | + 'authorization_endpoint': 'https://vault.example.net:8200/ui/vault/identity/oidc/provider/default/authorize', |
| 16 | + 'token_endpoint': 'https://vault.example.net:8200/v1/identity/oidc/provider/default/token', |
| 17 | + 'userinfo_endpoint': 'https://vault.example.net:8200/v1/identity/oidc/provider/default/userinfo', |
| 18 | + 'request_uri_parameter_supported': False, |
| 19 | + 'grant_types_supported': [ 'authorization_code' ], |
| 20 | + 'token_endpoint_auth_methods_supported': [ 'client_secret_basic' ], |
| 21 | + }) |
| 22 | + |
| 23 | + expected_username = 'cartman' |
| 24 | + |
| 25 | + def extra_settings(self): |
| 26 | + settings = super().extra_settings() |
| 27 | + settings.update({ |
| 28 | + f'SOCIAL_AUTH_{self.name}_OIDC_ENDPOINT': 'https://vault.example.net:8200/v1/identity/oidc/provider/default', |
| 29 | + }) |
| 30 | + return settings |
| 31 | + |
| 32 | + def pre_complete_callback(self, start_url): |
| 33 | + super().pre_complete_callback(start_url) |
| 34 | + HTTPretty.register_uri('GET', |
| 35 | + uri=self.backend.userinfo_url(), |
| 36 | + status=200, |
| 37 | + body=json.dumps({'preferred_username': self.expected_username}), |
| 38 | + content_type='text/json') |
| 39 | + |
| 40 | + def test_everything_works(self): |
| 41 | + self.do_login() |
0 commit comments