<commit_before>from django.test import TestCase
from sso import permissions
from django.contrib.auth.models import User, Group
from unicoresso.models import AuthorizedSite


class customAttributesTest(TestCase):

    def test_group_access(self):
        user = User.objects.create(first_name='foo')
        site = AuthorizedSite.objects.create(site='http://foobar.com')
        self.assertEqual(
            permissions.custom_attributes(user, site.site)['has_perm'], False)

    def test_correct_user(self):
        user = User.objects.create(first_name='foo')
        site = AuthorizedSite.objects.create(site='http://foobar.com')
        self.assertEqual(
            permissions.custom_attributes(user, site.site)['givenName'], 'foo')

    def test_correct_group(self):
        user = User.objects.create(first_name=' ')
        site = AuthorizedSite.objects.create(site='http://foobar.com')
        self.assertEqual(
            len(permissions.custom_attributes(user, site.site)['groups']), 0)

    def test_wildcard_url(self):
        user = User.objects.create(first_name='foo')
        group = Group.objects.create(name='Unicef')
        user.groups.add(group)
        user.save()

        site = AuthorizedSite.objects.create(
            site='*.fflangola.qa-hub.unicore.io')
        site.group.add(group)
        site.save()

        attr = permissions.custom_attributes(
            user, 'htto://cms.tz.fflangola.qa-hub.unicore.io/login/')
        self.assertEqual(attr['has_perm'], True)
        self.assertEqual(attr['groups'], ['Unicef'])

        attr = permissions.custom_attributes(
            user, 'htto://cms.za.fflangola.qa-hub.unicore.io/login/')
        self.assertEqual(attr['has_perm'], True)

        attr = permissions.custom_attributes(
            user, 'htto://cms.za.ffl.qa-hub.unicore.io/login/')
        self.assertEqual(attr['has_perm'], False)

        attr = permissions.custom_attributes(
            user, 'htto://cms.za.gem.qa-hub.unicore.io/login/')
        self.assertEqual(attr['has_perm'], False)<commit_msg>add test for exact match<commit_after>from django.test import TestCase
from sso import permissions
from django.contrib.auth.models import User, Group
from unicoresso.models import AuthorizedSite


class customAttributesTest(TestCase):

    def test_group_access(self):
        user = User.objects.create(first_name='foo')
        attr = permissions.custom_attributes(user, 'htto://foobar.com/')
        self.assertEqual(attr['has_perm'], False)

    def test_correct_user(self):
        user = User.objects.create(first_name='foo')
        attr = permissions.custom_attributes(user, 'htto://foobar.com/')
        self.assertEqual(attr['givenName'], 'foo')

    def test_correct_group(self):
        user = User.objects.create(first_name=' ')
        attr = permissions.custom_attributes(user, 'htto://foobar.com/')
        self.assertEqual(len(attr['groups']), 0)

        group = Group.objects.create(name='The Foo')
        user.groups.add(group)
        user.save()
        site = AuthorizedSite.objects.create(site='foobar.com')
        site.group.add(group)
        site.save()

        attr = permissions.custom_attributes(user, 'htto://foobar.com/')
        self.assertEqual(len(attr['groups']), 1)
        self.assertEqual(attr['groups'], ['The Foo'])

    def test_wildcard_url(self):
        user = User.objects.create(first_name='foo')
        group = Group.objects.create(name='Unicef')
        user.groups.add(group)
        user.save()

        site = AuthorizedSite.objects.create(
            site='*.fflangola.qa-hub.unicore.io')
        site.group.add(group)
        site.save()

        attr = permissions.custom_attributes(
            user, 'htto://cms.tz.fflangola.qa-hub.unicore.io/login/')
        self.assertEqual(attr['has_perm'], True)
        self.assertEqual(attr['groups'], ['Unicef'])

        attr = permissions.custom_attributes(
            user, 'htto://cms.za.fflangola.qa-hub.unicore.io/login/')
        self.assertEqual(attr['has_perm'], True)

        attr = permissions.custom_attributes(
            user, 'htto://cms.za.ffl.qa-hub.unicore.io/login/')
        self.assertEqual(attr['has_perm'], False)

        attr = permissions.custom_attributes(
            user, 'htto://cms.za.gem.qa-hub.unicore.io/login/')
        self.assertEqual(attr['has_perm'], False)
{'fraction_non_alphanumeric': 0.143184947223497, 'fraction_numerical': 0.0006883891693437356, 'mean_word_length': 2.8850267379679146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4609512', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1309, 'n_words': 193}