0001-apiclient-prefill-password-69527.patch
src/authentic2/manager/views.py | ||
---|---|---|
20 | 20 |
import json |
21 | 21 |
import pickle |
22 | 22 |
import random |
23 |
import uuid |
|
23 | 24 | |
24 | 25 |
from django.contrib.messages.views import SuccessMessageMixin |
25 | 26 |
from django.core.exceptions import PermissionDenied, ValidationError |
... | ... | |
892 | 893 |
def get_success_url(self): |
893 | 894 |
return reverse('a2-manager-api-client-detail', kwargs={'pk': self.object.pk}) |
894 | 895 | |
896 |
def get_form_kwargs(self): |
|
897 |
kwargs = super().get_form_kwargs() |
|
898 |
kwargs['initial'] = {'password': str(uuid.uuid4())} |
|
899 |
return kwargs |
|
900 | ||
895 | 901 | |
896 | 902 |
api_client_add = APIClientAddView.as_view() |
897 | 903 |
tests/test_manager.py | ||
---|---|---|
1365 | 1365 |
role_2 = Role.objects.create(name='role-2') |
1366 | 1366 |
resp = login(app, superuser_or_admin, 'a2-manager-api-client-add') |
1367 | 1367 |
form = resp.form |
1368 |
# password is prefilled |
|
1369 |
assert form.get('password').value |
|
1368 | 1370 |
form.set('name', 'api-client-name') |
1369 | 1371 |
form.set('description', 'api-client-description') |
1370 | 1372 |
form.set('identifier', 'api-client-identifier') |
... | ... | |
1415 | 1417 |
assert APIClient.objects.count() == 1 |
1416 | 1418 |
resp = login(app, superuser_or_admin, 'a2-manager-api-client-edit', kwargs={'pk': api_client.pk}) |
1417 | 1419 |
form = resp.form |
1420 |
assert form.get('password').value == 'foo-password' |
|
1418 | 1421 |
resp.form.set('password', 'easy') |
1419 | 1422 |
response = form.submit().follow() |
1420 | 1423 |
assert urlparse(response.request.url).path == api_client.get_absolute_url() |
1421 |
- |