def clean(self): """ clean override to check the validity of both redirect uri's and scopes """ cleaned_data = super(NewClientForm, self).clean() scopes = cleaned_data.get('scopes') redirect_uris = cleaned_data.get('redirect_uris') # Preliminary check that the data has passed per-field cleaning if scopes and redirect_uris: # Split the scopes and check that the requested scopes are a subset of the available ones scopes_list = scopes.split(' ') if not set(scopes_list) <= set([s for s, k in oauth2_settings.user_settings['SCOPES'].items()]): self.add_error('scopes', 'Feltet inneholder ugyldige tilganger.') # Validate the uris try: validate_uris(redirect_uris) except ValidationError: self.add_error('redirect_uris', 'Feltet inneholder ugyldige URIer.')
def test_validate_whitespace_separators(self): # Check that whitespace can be used as a separator good_uris = "http://example\r\nhttp://example\thttp://example" # Check ValidationError not thrown validate_uris(good_uris)
def test_validate_good_uris(self): good_uris = "http://example.com/ http://example.org/?key=val http://example" # Check ValidationError not thrown validate_uris(good_uris)
def test_validate_custom_uri_scheme(self): oauth2_settings.ALLOWED_REDIRECT_URI_SCHEMES = ["my-scheme", "http"] good_uris = "my-scheme://example.com http://example.com" # Check ValidationError not thrown validate_uris(good_uris)