Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BB2-2660: Move logic from save to clean for oauth client and grant type #1210

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/dot_ext/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class Meta:
required_css_class = "required"

def clean(self):
self.cleaned_data['client_type'] = "confidential"
self.cleaned_data['authorization_grant_type'] = "authorization-code"
return self.cleaned_data

def clean_name(self):
Expand Down Expand Up @@ -155,8 +157,6 @@ def clean_require_demographic_scopes(self):
return require_demographic_scopes

def save(self, *args, **kwargs):
self.instance.client_type = "confidential"
self.instance.authorization_grant_type = "authorization-code"
app = self.instance
# Only log agreement from a Register form
if app.agree and type(self) == CustomRegisterApplicationForm:
Expand Down
25 changes: 25 additions & 0 deletions apps/dot_ext/tests/test_form_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,31 @@ def test_update_form_edit(self):
form = CustomRegisterApplicationForm(user, passing_app_fields)
self.assertTrue(form.is_valid())

# Test client_type = 'confidential' and authorization_grant_type = 'authorization-code' regardless of input
data = passing_app_fields
data['client_type'] = 'confidential'
data['authorization_grant_type'] = 'implicit'
form = CustomRegisterApplicationForm(user, data)
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data.get('client_type'), 'confidential')
self.assertEqual(form.cleaned_data.get('authorization_grant_type'), 'authorization-code')

data = passing_app_fields
data['client_type'] = 'public'
data['authorization_grant_type'] = 'authorization-code'
form = CustomRegisterApplicationForm(user, data)
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data.get('client_type'), 'confidential')
self.assertEqual(form.cleaned_data.get('authorization_grant_type'), 'authorization-code')

data = passing_app_fields
data['client_type'] = 'public'
data['authorization_grant_type'] = 'implicit'
form = CustomRegisterApplicationForm(user, data)
self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data.get('client_type'), 'confidential')
self.assertEqual(form.cleaned_data.get('authorization_grant_type'), 'authorization-code')

def test_create_applications_with_logo(self):
"""
regression test: BB2-66: Fix-logo-display-in-Published-Applications-API
Expand Down
Loading