Esempio n. 1
0
    def test_set_enterprise_customer_cookie(self):
        """
        Verify that enterprise cookies are set properly.
        """
        enterprise_customer_uuid = uuid.uuid4()
        response = HttpResponse()

        result = set_enterprise_customer_cookie(self.site, response, enterprise_customer_uuid)

        cookie = result.cookies[settings.ENTERPRISE_CUSTOMER_COOKIE_NAME]
        self.assertEqual(str(enterprise_customer_uuid), cookie.value)
Esempio n. 2
0
    def _decorated(request, *args, **kwargs):
        code, enterprise_customer_uuid = request.GET.get('code'), None
        if code:
            enterprise_customer_uuid = utils.get_enterprise_customer_uuid(code)

        response = func(request, *args, **kwargs)

        # Set enterprise customer cookie if enterprise customer uuid is available.
        if enterprise_customer_uuid:
            response = utils.set_enterprise_customer_cookie(request.site, response, enterprise_customer_uuid)

        return response
Esempio n. 3
0
    def test_set_enterprise_customer_cookie_empty_cookie_domain(self):
        """
        Verify that enterprise cookie is not set if base_cookie_domain is empty
        in site configuration.
        """
        self.site.siteconfiguration.base_cookie_domain = ''
        self.site.siteconfiguration.save()

        enterprise_customer_uuid = uuid.uuid4()
        response = HttpResponse()

        result = set_enterprise_customer_cookie(self.site, response, enterprise_customer_uuid)

        self.assertNotIn(settings.ENTERPRISE_CUSTOMER_COOKIE_NAME, result.cookies)
Esempio n. 4
0
    def _decorated(request, *args, **kwargs):
        response = func(request, *args, **kwargs)

        # Set enterprise customer cookie if enterprise customer uuid is available.
        # The max_age of the cookie is set to a relatively short 60 seconds to
        # maintain the Enterprise context across jumps over to other Open edX
        # services, e.g. LMS, but also to ensure that the Enterprise context
        # does not linger longer than it should.
        code, enterprise_customer_uuid = request.GET.get('code'), None
        if code:
            enterprise_customer_uuid = utils.get_enterprise_customer_uuid(code)
            if enterprise_customer_uuid:
                response = utils.set_enterprise_customer_cookie(
                    request.site,
                    response,
                    enterprise_customer_uuid,
                    max_age=60)

        return response