{"action":"created","comment":{"url":"https://api.github.com/repos/edx/ecommerce/pulls/comments/34161400","id":34161400,"diff_hunk":"@@ -104,14 +114,86 @@ def test_authenticate(self):\n         self.assertEqual(self.auth.authenticate(request), (user, self.DEFAULT_TOKEN))\n \n \n-class JwtAuthenticationTests(TestCase):\n+class JwtAuthenticationTests(JwtMixin, UserMixin, TestCase):\n+\n+    def setUp(self):\n+        api_settings.JWT_ISSUER = 'http://example.com/oauth'\n+        api_settings.JWT_VERIFY_EXPIRATION = True\n+\n+    def _mock_payload_response(self, payload):\n+        auth_header = 'JWT ' + self.generate_token(payload)\n+        response = self.client.get(reverse('api:v2:orders:list'), HTTP_AUTHORIZATION=auth_header)\n+        return response\n+\n+    def test_validate_issuer(self):\n+        \"\"\" Test whether authentication fails if the JWT has an invalid issuer. \"\"\"\n+\n+        staff_user = self.create_user(is_staff=True)\n+        self.client.login(username=staff_user.username, password=self.password)\n+\n+        valid_date = date(2084, 1, 24)\n+        valid_timestamp = mktime(valid_date.timetuple())\n+\n+        # Invalid issuer\n+        # -------------\n+        payload = {\n+            'iss': 'some_invalid_issuer',\n+            'exp': valid_timestamp,\n+            'username': staff_user.username,\n+            'email': staff_user.email,\n+            'full_name': staff_user.full_name\n+        }\n+\n+        response = self._mock_payload_response(payload)\n+        self.assertEqual(response.status_code, 401)\n+\n+        # Valid issuer\n+        # -------------\n+        payload['iss'] = api_settings.JWT_ISSUER\n+\n+        response = self._mock_payload_response(payload)\n+        self.assertEqual(response.status_code, 200)\n+\n+    def test_validate_expiration(self):\n+        \"\"\" Test whether authentication fails if the JWT token has expired. \"\"\"\n+\n+        staff_user = self.create_user(is_staff=True)\n+        self.client.login(username=staff_user.username, password=self.password)\n+\n+        # Expired token\n+        # -------------\n+        expired_date = date(1984, 1, 24)\n+        expired_timestamp = mktime(expired_date.timetuple())\n+\n+        payload = {\n+            'iss': api_settings.JWT_ISSUER,\n+            'exp': expired_timestamp,\n+            'username': staff_user.username,\n+            'email': staff_user.email,\n+            'full_name': staff_user.full_name\n+        }\n+\n+        response = self._mock_payload_response(payload)\n+        self.assertEqual(response.status_code, 401)\n+\n+        # Non-expired token\n+        # -----------------\n+        valid_date = date(2084, 1, 24)","path":"ecommerce/extensions/api/tests/test_authentication.py","position":99,"original_position":99,"commit_id":"3d71dd4e41cfeb4092ebf01a34682e7b8ff93179","original_commit_id":"3d71dd4e41cfeb4092ebf01a34682e7b8ff93179","user":{"login":"clintonb","id":910510,"avatar_url":"https://avatars.githubusercontent.com/u/910510?v=3","gravatar_id":"","url":"https://api.github.com/users/clintonb","html_url":"https://github.com/clintonb","followers_url":"https://api.github.com/users/clintonb/followers","following_url":"https://api.github.com/users/clintonb/following{/other_user}","gists_url":"https://api.github.com/users/clintonb/gists{/gist_id}","starred_url":"https://api.github.com/users/clintonb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clintonb/subscriptions","organizations_url":"https://api.github.com/users/clintonb/orgs","repos_url":"https://api.github.com/users/clintonb/repos","events_url":"https://api.github.com/users/clintonb/events{/privacy}","received_events_url":"https://api.github.com/users/clintonb/received_events","type":"User","site_admin":false},"body":"You can also use `datetime.max()`.","created_at":"2015-07-08T15:31:08Z","updated_at":"2015-07-08T15:31:08Z","html_url":"https://github.com/edx/ecommerce/pull/191#discussion_r34161400","pull_request_url":"https://api.github.com/repos/edx/ecommerce/pulls/191","_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/comments/34161400"},"html":{"href":"https://github.com/edx/ecommerce/pull/191#discussion_r34161400"},"pull_request":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/191"}}},"pull_request":{"url":"https://api.github.com/repos/edx/ecommerce/pulls/191","id":39486333,"html_url":"https://github.com/edx/ecommerce/pull/191","diff_url":"https://github.com/edx/ecommerce/pull/191.diff","patch_url":"https://github.com/edx/ecommerce/pull/191.patch","issue_url":"https://api.github.com/repos/edx/ecommerce/issues/191","number":191,"state":"open","locked":false,"title":"XCOM-281: JWT issuer and expiration date are now validated","user":{"login":"Nickersoft","id":2104129,"avatar_url":"https://avatars.githubusercontent.com/u/2104129?v=3","gravatar_id":"","url":"https://api.github.com/users/Nickersoft","html_url":"https://github.com/Nickersoft","followers_url":"https://api.github.com/users/Nickersoft/followers","following_url":"https://api.github.com/users/Nickersoft/following{/other_user}","gists_url":"https://api.github.com/users/Nickersoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Nickersoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nickersoft/subscriptions","organizations_url":"https://api.github.com/users/Nickersoft/orgs","repos_url":"https://api.github.com/users/Nickersoft/repos","events_url":"https://api.github.com/users/Nickersoft/events{/privacy}","received_events_url":"https://api.github.com/users/Nickersoft/received_events","type":"User","site_admin":false},"body":"In order to enable this feature in production, the following settings must be set in base.py under JWT_AUTH:\r\n\r\n'JWT_ISSUER': \\<issuer passed in LMS\\>\r\n'JWT_VERIFY_EXPIRATION': True\r\n\r\n@clintonb @rlucioni @wedaly @jimabramson ","created_at":"2015-07-08T14:57:26Z","updated_at":"2015-07-08T15:31:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2e9e1cc0d73b6ad338b604f2c1621f51b3573f87","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/ecommerce/pulls/191/commits","review_comments_url":"https://api.github.com/repos/edx/ecommerce/pulls/191/comments","review_comment_url":"https://api.github.com/repos/edx/ecommerce/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/ecommerce/issues/191/comments","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/3d71dd4e41cfeb4092ebf01a34682e7b8ff93179","head":{"label":"edx:nickersoft/jwt-security","ref":"nickersoft/jwt-security","sha":"3d71dd4e41cfeb4092ebf01a34682e7b8ff93179","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":30175039,"name":"ecommerce","full_name":"edx/ecommerce","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/ecommerce","description":"Django application used to manage edX's product catalog and handle orders for those products","fork":false,"url":"https://api.github.com/repos/edx/ecommerce","forks_url":"https://api.github.com/repos/edx/ecommerce/forks","keys_url":"https://api.github.com/repos/edx/ecommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/ecommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/ecommerce/teams","hooks_url":"https://api.github.com/repos/edx/ecommerce/hooks","issue_events_url":"https://api.github.com/repos/edx/ecommerce/issues/events{/number}","events_url":"https://api.github.com/repos/edx/ecommerce/events","assignees_url":"https://api.github.com/repos/edx/ecommerce/assignees{/user}","branches_url":"https://api.github.com/repos/edx/ecommerce/branches{/branch}","tags_url":"https://api.github.com/repos/edx/ecommerce/tags","blobs_url":"https://api.github.com/repos/edx/ecommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/ecommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/ecommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/ecommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/ecommerce/languages","stargazers_url":"https://api.github.com/repos/edx/ecommerce/stargazers","contributors_url":"https://api.github.com/repos/edx/ecommerce/contributors","subscribers_url":"https://api.github.com/repos/edx/ecommerce/subscribers","subscription_url":"https://api.github.com/repos/edx/ecommerce/subscription","commits_url":"https://api.github.com/repos/edx/ecommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/ecommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/ecommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/ecommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/ecommerce/contents/{+path}","compare_url":"https://api.github.com/repos/edx/ecommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/ecommerce/merges","archive_url":"https://api.github.com/repos/edx/ecommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/ecommerce/downloads","issues_url":"https://api.github.com/repos/edx/ecommerce/issues{/number}","pulls_url":"https://api.github.com/repos/edx/ecommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/ecommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/ecommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/ecommerce/labels{/name}","releases_url":"https://api.github.com/repos/edx/ecommerce/releases{/id}","created_at":"2015-02-02T06:55:15Z","updated_at":"2015-07-05T20:02:17Z","pushed_at":"2015-07-08T14:57:27Z","git_url":"git://github.com/edx/ecommerce.git","ssh_url":"git@github.com:edx/ecommerce.git","clone_url":"https://github.com/edx/ecommerce.git","svn_url":"https://github.com/edx/ecommerce","homepage":"","size":3532,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":6,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"04446b58993d217420c629bb9c10894475f17a5c","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":30175039,"name":"ecommerce","full_name":"edx/ecommerce","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/ecommerce","description":"Django application used to manage edX's product catalog and handle orders for those products","fork":false,"url":"https://api.github.com/repos/edx/ecommerce","forks_url":"https://api.github.com/repos/edx/ecommerce/forks","keys_url":"https://api.github.com/repos/edx/ecommerce/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/ecommerce/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/ecommerce/teams","hooks_url":"https://api.github.com/repos/edx/ecommerce/hooks","issue_events_url":"https://api.github.com/repos/edx/ecommerce/issues/events{/number}","events_url":"https://api.github.com/repos/edx/ecommerce/events","assignees_url":"https://api.github.com/repos/edx/ecommerce/assignees{/user}","branches_url":"https://api.github.com/repos/edx/ecommerce/branches{/branch}","tags_url":"https://api.github.com/repos/edx/ecommerce/tags","blobs_url":"https://api.github.com/repos/edx/ecommerce/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/ecommerce/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/ecommerce/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/ecommerce/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/ecommerce/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/ecommerce/languages","stargazers_url":"https://api.github.com/repos/edx/ecommerce/stargazers","contributors_url":"https://api.github.com/repos/edx/ecommerce/contributors","subscribers_url":"https://api.github.com/repos/edx/ecommerce/subscribers","subscription_url":"https://api.github.com/repos/edx/ecommerce/subscription","commits_url":"https://api.github.com/repos/edx/ecommerce/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/ecommerce/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/ecommerce/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/ecommerce/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/ecommerce/contents/{+path}","compare_url":"https://api.github.com/repos/edx/ecommerce/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/ecommerce/merges","archive_url":"https://api.github.com/repos/edx/ecommerce/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/ecommerce/downloads","issues_url":"https://api.github.com/repos/edx/ecommerce/issues{/number}","pulls_url":"https://api.github.com/repos/edx/ecommerce/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/ecommerce/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/ecommerce/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/ecommerce/labels{/name}","releases_url":"https://api.github.com/repos/edx/ecommerce/releases{/id}","created_at":"2015-02-02T06:55:15Z","updated_at":"2015-07-05T20:02:17Z","pushed_at":"2015-07-08T14:57:27Z","git_url":"git://github.com/edx/ecommerce.git","ssh_url":"git@github.com:edx/ecommerce.git","clone_url":"https://github.com/edx/ecommerce.git","svn_url":"https://github.com/edx/ecommerce","homepage":"","size":3532,"stargazers_count":6,"watchers_count":6,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":4,"forks":6,"open_issues":4,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/191"},"html":{"href":"https://github.com/edx/ecommerce/pull/191"},"issue":{"href":"https://api.github.com/repos/edx/ecommerce/issues/191"},"comments":{"href":"https://api.github.com/repos/edx/ecommerce/issues/191/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/191/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/ecommerce/pulls/191/commits"},"statuses":{"href":"https://api.github.com/repos/edx/ecommerce/statuses/3d71dd4e41cfeb4092ebf01a34682e7b8ff93179"}}}}