Repository: mozilla/django-csp

Issue:
Setting a lazy-evaluated string to CSP_REPORT_URI no longer works
```
Traceback (most recent call last):
  File "/app/sitepackages/django/core/handlers/base.py", line 235, in get_response
    response = middleware_method(request, response)
  File "/app/sitepackages/csp/middleware.py", line 43, in process_response
    replace=replace)
  File "/app/sitepackages/csp/utils.py", line 58, in build_policy
    policy.append('report-uri %s' % ' '.join(report_uri))
TypeError: sequence item 0: expected string, __proxy__ found
```

With `CSP_REPORT_URI = reverse_lazy('report_csp')`

Discussion:

Patch:
diff --git a/csp/utils.py b/csp/utils.py
index 1ca6268..33e51f3 100644
--- a/csp/utils.py
+++ b/csp/utils.py
@@ -1,4 +1,5 @@
 from django.conf import settings
+from django.utils.encoding import force_text
 import copy
 from itertools import chain
 
@@ -55,5 +56,6 @@ def build_policy(config=None, update=None, replace=None):
     policy = ['%s %s' % (kk, ' '.join(vv)) for kk, vv in
               csp.items() if vv is not None]
     if report_uri:
+        report_uri = map(force_text, report_uri)
         policy.append('report-uri %s' % ' '.join(report_uri))
     return '; '.join(policy)


Test patch:
diff --git a/csp/tests/test_utils.py b/csp/tests/test_utils.py
index afdd880..d918b6f 100644
--- a/csp/tests/test_utils.py
+++ b/csp/tests/test_utils.py
@@ -1,4 +1,6 @@
 from django.test.utils import override_settings
+from django.utils.functional import lazy
+from django.utils import six
 
 from csp.utils import build_policy
 
@@ -14,6 +16,13 @@ def test_empty_policy():
     assert "default-src 'self'" == policy
 
 
+def literal(s):
+    return s
+
+
+lazy_literal = lazy(literal, six.text_type)
+
+
 @override_settings(CSP_DEFAULT_SRC=['example.com', 'example2.com'])
 def test_default_src():
     policy = build_policy()
@@ -86,6 +95,12 @@ def test_report_uri():
     policy_eq("default-src 'self'; report-uri /foo", policy)
 
 
+@override_settings(CSP_REPORT_URI=lazy_literal('/foo'))
+def test_report_uri_lazy():
+    policy = build_policy()
+    policy_eq("default-src 'self'; report-uri /foo", policy)
+
+
 @override_settings(CSP_IMG_SRC=['example.com'])
 def test_update_img():
     policy = build_policy(update={'img-src': 'example2.com'})