Skip to content

Commit

Permalink
Merge pull request #2274 from peterbe/bug-1049683-debug-always-on-in-…
Browse files Browse the repository at this point in the history
…_debug_login

fixes bug 1049683 - DEBUG always on in /_debug_login
  • Loading branch information
peterbe committed Aug 8, 2014
2 parents 2c17625 + 055ccfa commit 2cb4ffa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
8 changes: 7 additions & 1 deletion webapp-django/crashstats/auth/static/auth/js/debug_login.js
Expand Up @@ -131,6 +131,12 @@ $(function() {
var browserid_audiences = $('#browserid-audiences');
var debug = browserid_audiences.data('debug');
var audiences = browserid_audiences.data('audiences');
if (audiences.length) {
// necessary because `"".split(',')` becomes `[""]`
audiences = audiences.split(',');
} else {
audiences = [];
}

function matchesCurrentOrigin(url) {
var a = document.createElement('a');
Expand Down Expand Up @@ -158,7 +164,7 @@ $(function() {
addVerdict(
browserid_audiences,
'No value in your <code>BROWSERID_AUDIENCES</code> setting appears ' +
"to match the current URL you're using.",
"to match the current URL you're using. ",
'bad'
);
}
Expand Down
6 changes: 3 additions & 3 deletions webapp-django/crashstats/auth/templates/auth/debug_login.html
Expand Up @@ -41,7 +41,7 @@ <h3>There appears to be some trouble in the configuration</h3>
</div>

<div class="test" id="session-cookie-secure"
data-session-cookie-secure="{{ SESSION_COOKIE_SECURE }}"
data-session-cookie-secure="{{ SESSION_COOKIE_SECURE | json_dumps }}"
data-cookie-value="{{ cookie_value }}">
<h4><code>SESSION_COOKIE_SECURE</code></h4>
<p class="loading">Loading...</p>
Expand All @@ -56,8 +56,8 @@ <h4>Caching</h4>
</div>

<div class="test" id="browserid-audiences"
data-debug="{{ DEBUG }}"
data-audiences="{{ BROWSERID_AUDIENCES }}">
data-debug="{{ DEBUG | json_dumps }}"
data-audiences="{{ ','.join(BROWSERID_AUDIENCES) }}">
{% if DEBUG %}
You're currently in <b>DEBUG</b> mode which means that if
<code>BROWSERID_AUDIENCES</code> does not have to be set.
Expand Down
7 changes: 5 additions & 2 deletions webapp-django/crashstats/auth/tests/test_views.py
Expand Up @@ -65,15 +65,18 @@ def test_render(self):
SESSION_COOKIE_SECURE=True,
CACHES=_caches,
DEBUG=True,
BROWSERID_AUDIENCES=['http://socorro']
BROWSERID_AUDIENCES=[
'http://socorro',
'http://crashstats.com'
]
):
response = self.client.get(url)
eq_(response.status_code, 200)
ok_('data-session-cookie-secure="true"' in response.content)
ok_('data-cache-setting="SomeCache"' in response.content)
ok_('data-debug="true"' in response.content)
ok_(
'data-audiences="[&#34;http://socorro&#34;]"'
'data-audiences="http://socorro,http://crashstats.com"'
in response.content
)

Expand Down
9 changes: 3 additions & 6 deletions webapp-django/crashstats/auth/views.py
@@ -1,5 +1,4 @@
import datetime
import json
import random

from django.conf import settings
Expand Down Expand Up @@ -39,14 +38,12 @@ def debug_login(request):
cache.set('cache_value', cache_value, 10)
cookie_value = random.randint(10, 100)
context = {
'SESSION_COOKIE_SECURE': json.dumps(settings.SESSION_COOKIE_SECURE),
'SESSION_COOKIE_SECURE': settings.SESSION_COOKIE_SECURE,
'cache_setting': settings.CACHES['default']['BACKEND'].split('.')[-1],
'cache_value': cache_value,
'cookie_value': cookie_value,
'DEBUG': json.dumps(settings.DEBUG),
'BROWSERID_AUDIENCES': json.dumps(
getattr(settings, 'BROWSERID_AUDIENCES', None)
),
'DEBUG': settings.DEBUG,
'BROWSERID_AUDIENCES': getattr(settings, 'BROWSERID_AUDIENCES', []),
}
response = render(request, 'auth/debug_login.html', context)
future = datetime.datetime.utcnow() + datetime.timedelta(seconds=10)
Expand Down

0 comments on commit 2cb4ffa

Please sign in to comment.