0001-authentic2_auth_oidc-add-template-syntax-check-to-cl.patch
src/authentic2/utils/template.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
from django.core.exceptions import ValidationError |
|
17 | 18 |
from django.template import TemplateSyntaxError, VariableDoesNotExist, engines |
18 | 19 |
from django.utils.encoding import force_str |
19 | 20 |
from django.utils.translation import ugettext_lazy as _ |
... | ... | |
52 | 53 | |
53 | 54 |
def null_render(self, context=None): |
54 | 55 |
return str(self.value) |
56 | ||
57 | ||
58 |
def validate_template(value): |
|
59 |
try: |
|
60 |
Template(value, raises=True) |
|
61 |
except TemplateError as e: |
|
62 |
raise ValidationError('%s' % e) |
src/authentic2_auth_oidc/migrations/0007_auto_20200317_1732.py | ||
---|---|---|
2 | 2 | |
3 | 3 |
from django.db import migrations, models |
4 | 4 | |
5 |
import authentic2.utils.template |
|
6 | ||
5 | 7 | |
6 | 8 |
class Migration(migrations.Migration): |
7 | 9 | |
... | ... | |
13 | 15 |
migrations.AlterField( |
14 | 16 |
model_name='oidcclaimmapping', |
15 | 17 |
name='claim', |
16 |
field=models.CharField(max_length=128, verbose_name='claim'), |
|
18 |
field=models.CharField( |
|
19 |
max_length=128, verbose_name='claim', validators=[authentic2.utils.template.validate_template] |
|
20 |
), |
|
17 | 21 |
), |
18 | 22 |
] |
src/authentic2_auth_oidc/models.py | ||
---|---|---|
24 | 24 |
from django.utils.translation import ugettext_lazy as _ |
25 | 25 |
from jwcrypto.jwk import InvalidJWKValue, JWKSet |
26 | 26 | |
27 |
from authentic2.utils.template import validate_template |
|
27 | 28 |
from django_rbac.utils import get_ou_model_name |
28 | 29 | |
29 | 30 |
from . import managers |
... | ... | |
146 | 147 |
provider = models.ForeignKey( |
147 | 148 |
to='OIDCProvider', verbose_name=_('provider'), related_name='claim_mappings', on_delete=models.CASCADE |
148 | 149 |
) |
149 |
claim = models.CharField(max_length=128, verbose_name=_('claim')) |
|
150 |
claim = models.CharField(max_length=128, verbose_name=_('claim'), validators=[validate_template])
|
|
150 | 151 |
attribute = models.CharField(max_length=64, verbose_name=_('attribute')) |
151 | 152 |
verified = models.PositiveIntegerField( |
152 | 153 |
default=NOT_VERIFIED, choices=VERIFIED_CHOICES, verbose_name=_('verified') |
153 |
- |