Skip to content

Commit

Permalink
Merge pull request #3092 from anuragkanungo/nalanda-rct3
Browse files Browse the repository at this point in the history
Fix 3040, Redirect to login page in case of Unauthorized
  • Loading branch information
aronasorman committed Feb 25, 2015
2 parents 8e5e8e5 + 4ffdb35 commit 7c9085b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 20 additions & 1 deletion kalite/distributed/tests/browser_tests/quiz.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
"""
These use a web-browser, along selenium, to simulate user actions.
"""

import urllib

from django.conf import settings
logging = settings.LOG
from django.core.urlresolvers import reverse
from django.test.utils import override_settings

from kalite.testing.base import KALiteBrowserTestCase
from kalite.testing.mixins import BrowserActionMixins, FacilityMixins
from selenium.webdriver.common.keys import Keys

PLAYLIST_ID = "g3_p1"
PLAYLIST_ID = "g4_u400_ap1"


class QuizTest(BrowserActionMixins, FacilityMixins, KALiteBrowserTestCase):
Expand Down Expand Up @@ -53,3 +57,18 @@ def test_quiz_first_answer_correct_not_registered(self):
self.browser.execute_script("quizlog.add_response_log_item({correct: true});")
self.assertEqual(self.browser.execute_script("return quizlog.get('total_correct')"), 1)
self.assertEqual(self.browser.execute_script("return quizlog._response_log_cache[0]"), 1)


def test_unauthorized_request_redirect_to_login(self):

self.browse_to(
self.live_server_url +
reverse("view_playlist", kwargs={"playlist_id": PLAYLIST_ID}))
hash_value = urllib.urlparse(self.browser.current_url).fragment
self.browser.delete_all_cookies()
self.browser.implicitly_wait(30)
self.browser.find_element_by_id('solutionarea').find_element_by_css_selector('input[type=text]').click()
self.browser_send_keys(unicode("Anurag"))
self.browser_send_keys(Keys.RETURN)
#Not using urlencode for next param as its hassle to use escape character for params only.
self.assertEqual(self.browser.current_url, self.reverse('login') + "?next=" + reverse("view_playlist", kwargs={"playlist_id": PLAYLIST_ID}) + "#" + hash_value)
3 changes: 3 additions & 0 deletions static-libraries/js/khan-lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ function handleFailedAPI(resp, error_prefix) {
console.log(e);
}
break;
case 401:
case 403:
// Redirect to Login Page and add the current url as next
window.location.href = setGetParam(USER_LOGIN_URL, "next", window.location.pathname + window.location.hash)
messages = {error: sprintf(gettext("You are not authorized to complete the request. Please <a href='%(login_url)s'>login</a> as an authorized user, then retry the request."), {
login_url: USER_LOGIN_URL
})};
Expand Down

0 comments on commit 7c9085b

Please sign in to comment.