{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/notifications-admin/pulls/comments/149652002","pull_request_review_id":75077435,"id":149652002,"diff_hunk":"@@ -213,3 +215,108 @@ def test_two_factor_should_activate_pending_user(\n \n     assert mock_update_user.called\n     assert api_user_pending.is_active\n+\n+\n+def test_valid_two_factor_email_link_logs_in_user(\n+    client,\n+    valid_token,\n+    mock_get_user,\n+    mock_get_services_with_one_service,\n+    mocker\n+):\n+    mocker.patch('app.user_api_client.check_verify_code', return_value=(True, ''))\n+\n+    response = client.get(\n+        url_for('main.two_factor_email', token=valid_token),\n+    )\n+\n+    assert response.status_code == 302\n+    assert response.location == url_for('main.service_dashboard', service_id=SERVICE_ONE_ID, _external=True)\n+\n+\n+def test_two_factor_email_link_has_expired(\n+    app_,\n+    valid_token,\n+    client,\n+    mock_send_verify_code,\n+    fake_uuid\n+):\n+\n+    with set_config(app_, 'EMAIL_2FA_EXPIRY_SECONDS', -1):\n+        response = client.get(\n+            url_for('main.two_factor_email', token=valid_token),\n+            follow_redirects=True,\n+        )\n+\n+    assert response.status_code == 200\n+    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')\n+\n+    assert normalize_spaces(\n+        page.select_one('.banner-dangerous').text\n+    ) == \"The link in the email we sent you has expired. We've sent you a new one.\"\n+    assert page.h1.text.strip() == 'Email resent'\n+    mock_send_verify_code.assert_called_once_with(fake_uuid, 'email', None)\n+\n+\n+def test_two_factor_email_link_is_invalid(\n+    client\n+):\n+    token = 12345\n+    response = client.get(\n+        url_for('main.two_factor_email', token=token),\n+        follow_redirects=True\n+    )\n+    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')\n+    assert normalize_spaces(\n+        page.select_one('.banner-dangerous').text\n+    ) == \"There’s something wrong with the link you’ve used.\"\n+    assert response.status_code == 404\n+\n+\n+def test_two_factor_email_link_is_already_used(\n+    client,\n+    valid_token,\n+    mocker\n+):\n+    mocker.patch('app.user_api_client.check_verify_code', return_value=(False, 'Code has expired'))\n+\n+    response = client.get(\n+        url_for('main.two_factor_email', token=valid_token),\n+        follow_redirects=True\n+    )\n+\n+    page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')\n+    assert normalize_spaces(\n+        page.select_one('.banner-dangerous').text\n+    ) == \"There's something wrong with the code\"","path":"tests/app/main/views/test_two_factor.py","position":89,"original_position":89,"commit_id":"1abe828702651c7b93503c8716f9c82fe62364a1","original_commit_id":"1abe828702651c7b93503c8716f9c82fe62364a1","user":{"login":"quis","id":355079,"avatar_url":"https://avatars2.githubusercontent.com/u/355079?v=4","gravatar_id":"","url":"https://api.github.com/users/quis","html_url":"https://github.com/quis","followers_url":"https://api.github.com/users/quis/followers","following_url":"https://api.github.com/users/quis/following{/other_user}","gists_url":"https://api.github.com/users/quis/gists{/gist_id}","starred_url":"https://api.github.com/users/quis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quis/subscriptions","organizations_url":"https://api.github.com/users/quis/orgs","repos_url":"https://api.github.com/users/quis/repos","events_url":"https://api.github.com/users/quis/events{/privacy}","received_events_url":"https://api.github.com/users/quis/received_events","type":"User","site_admin":false},"body":"Again 😛 ","created_at":"2017-11-08T12:17:15Z","updated_at":"2017-11-08T12:17:15Z","html_url":"https://github.com/alphagov/notifications-admin/pull/1622#discussion_r149652002","pull_request_url":"https://api.github.com/repos/alphagov/notifications-admin/pulls/1622","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/alphagov/notifications-admin/pulls/comments/149652002"},"html":{"href":"https://github.com/alphagov/notifications-admin/pull/1622#discussion_r149652002"},"pull_request":{"href":"https://api.github.com/repos/alphagov/notifications-admin/pulls/1622"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/notifications-admin/pulls/1622","id":151158893,"html_url":"https://github.com/alphagov/notifications-admin/pull/1622","diff_url":"https://github.com/alphagov/notifications-admin/pull/1622.diff","patch_url":"https://github.com/alphagov/notifications-admin/pull/1622.patch","issue_url":"https://api.github.com/repos/alphagov/notifications-admin/issues/1622","number":1622,"state":"open","locked":false,"title":"Alter login flow to allow for email auth login","user":{"login":"gov-cjwaszczuk","id":31617728,"avatar_url":"https://avatars1.githubusercontent.com/u/31617728?v=4","gravatar_id":"","url":"https://api.github.com/users/gov-cjwaszczuk","html_url":"https://github.com/gov-cjwaszczuk","followers_url":"https://api.github.com/users/gov-cjwaszczuk/followers","following_url":"https://api.github.com/users/gov-cjwaszczuk/following{/other_user}","gists_url":"https://api.github.com/users/gov-cjwaszczuk/gists{/gist_id}","starred_url":"https://api.github.com/users/gov-cjwaszczuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gov-cjwaszczuk/subscriptions","organizations_url":"https://api.github.com/users/gov-cjwaszczuk/orgs","repos_url":"https://api.github.com/users/gov-cjwaszczuk/repos","events_url":"https://api.github.com/users/gov-cjwaszczuk/events{/privacy}","received_events_url":"https://api.github.com/users/gov-cjwaszczuk/received_events","type":"User","site_admin":false},"body":"# Summary\r\nAdded the login functionality for a user currently on email auth. If they log in correctly, they will be sent an email with a token inside it (with 'next' query string appended to it if they came to the log-in from a different notify request). The user will then be able to click the link to log into the platform. \r\n\r\n## :o: Two factor email sent \r\n![image](https://user-images.githubusercontent.com/31617728/32505330-d57e35cc-c3d9-11e7-8d59-91c7a38ca891.png)\r\n## :o: Resend email \r\n![image](https://user-images.githubusercontent.com/31617728/32505361-e6852f2e-c3d9-11e7-8c72-6778ac98b02d.png)\r\n## :o: Two factor email\r\n![image](https://user-images.githubusercontent.com/31617728/32505468-2fda99e8-c3da-11e7-9777-558f3a3ec621.png)\r\n\r\n","created_at":"2017-11-07T16:16:16Z","updated_at":"2017-11-08T12:17:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dc4f536b8607c59ca4d7576d8dc126defe0f1ae9","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/notifications-admin/pulls/1622/commits","review_comments_url":"https://api.github.com/repos/alphagov/notifications-admin/pulls/1622/comments","review_comment_url":"https://api.github.com/repos/alphagov/notifications-admin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/notifications-admin/issues/1622/comments","statuses_url":"https://api.github.com/repos/alphagov/notifications-admin/statuses/1abe828702651c7b93503c8716f9c82fe62364a1","head":{"label":"gov-cjwaszczuk:master","ref":"master","sha":"1abe828702651c7b93503c8716f9c82fe62364a1","user":{"login":"gov-cjwaszczuk","id":31617728,"avatar_url":"https://avatars1.githubusercontent.com/u/31617728?v=4","gravatar_id":"","url":"https://api.github.com/users/gov-cjwaszczuk","html_url":"https://github.com/gov-cjwaszczuk","followers_url":"https://api.github.com/users/gov-cjwaszczuk/followers","following_url":"https://api.github.com/users/gov-cjwaszczuk/following{/other_user}","gists_url":"https://api.github.com/users/gov-cjwaszczuk/gists{/gist_id}","starred_url":"https://api.github.com/users/gov-cjwaszczuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gov-cjwaszczuk/subscriptions","organizations_url":"https://api.github.com/users/gov-cjwaszczuk/orgs","repos_url":"https://api.github.com/users/gov-cjwaszczuk/repos","events_url":"https://api.github.com/users/gov-cjwaszczuk/events{/privacy}","received_events_url":"https://api.github.com/users/gov-cjwaszczuk/received_events","type":"User","site_admin":false},"repo":{"id":102352937,"name":"notifications-admin","full_name":"gov-cjwaszczuk/notifications-admin","owner":{"login":"gov-cjwaszczuk","id":31617728,"avatar_url":"https://avatars1.githubusercontent.com/u/31617728?v=4","gravatar_id":"","url":"https://api.github.com/users/gov-cjwaszczuk","html_url":"https://github.com/gov-cjwaszczuk","followers_url":"https://api.github.com/users/gov-cjwaszczuk/followers","following_url":"https://api.github.com/users/gov-cjwaszczuk/following{/other_user}","gists_url":"https://api.github.com/users/gov-cjwaszczuk/gists{/gist_id}","starred_url":"https://api.github.com/users/gov-cjwaszczuk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gov-cjwaszczuk/subscriptions","organizations_url":"https://api.github.com/users/gov-cjwaszczuk/orgs","repos_url":"https://api.github.com/users/gov-cjwaszczuk/repos","events_url":"https://api.github.com/users/gov-cjwaszczuk/events{/privacy}","received_events_url":"https://api.github.com/users/gov-cjwaszczuk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gov-cjwaszczuk/notifications-admin","description":"Frontend application for notify admin","fork":true,"url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin","forks_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/forks","keys_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/teams","hooks_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/hooks","issue_events_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/issues/events{/number}","events_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/events","assignees_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/assignees{/user}","branches_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/branches{/branch}","tags_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/tags","blobs_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/git/refs{/sha}","trees_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/statuses/{sha}","languages_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/languages","stargazers_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/stargazers","contributors_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/contributors","subscribers_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/subscribers","subscription_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/subscription","commits_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/commits{/sha}","git_commits_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/git/commits{/sha}","comments_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/comments{/number}","issue_comment_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/issues/comments{/number}","contents_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/contents/{+path}","compare_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/merges","archive_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/downloads","issues_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/issues{/number}","pulls_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/pulls{/number}","milestones_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/milestones{/number}","notifications_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/labels{/name}","releases_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/releases{/id}","deployments_url":"https://api.github.com/repos/gov-cjwaszczuk/notifications-admin/deployments","created_at":"2017-09-04T11:13:01Z","updated_at":"2017-09-04T11:13:03Z","pushed_at":"2017-11-08T11:18:55Z","git_url":"git://github.com/gov-cjwaszczuk/notifications-admin.git","ssh_url":"git@github.com:gov-cjwaszczuk/notifications-admin.git","clone_url":"https://github.com/gov-cjwaszczuk/notifications-admin.git","svn_url":"https://github.com/gov-cjwaszczuk/notifications-admin","homepage":null,"size":7470,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"a11e57c50ac873d84b2a2ba6b156e0844eed4aea","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars0.githubusercontent.com/u/596977?v=4","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":46421986,"name":"notifications-admin","full_name":"alphagov/notifications-admin","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars0.githubusercontent.com/u/596977?v=4","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/notifications-admin","description":"Frontend application for notify admin","fork":false,"url":"https://api.github.com/repos/alphagov/notifications-admin","forks_url":"https://api.github.com/repos/alphagov/notifications-admin/forks","keys_url":"https://api.github.com/repos/alphagov/notifications-admin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/notifications-admin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/notifications-admin/teams","hooks_url":"https://api.github.com/repos/alphagov/notifications-admin/hooks","issue_events_url":"https://api.github.com/repos/alphagov/notifications-admin/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/notifications-admin/events","assignees_url":"https://api.github.com/repos/alphagov/notifications-admin/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/notifications-admin/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/notifications-admin/tags","blobs_url":"https://api.github.com/repos/alphagov/notifications-admin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/notifications-admin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/notifications-admin/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/notifications-admin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/notifications-admin/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/notifications-admin/languages","stargazers_url":"https://api.github.com/repos/alphagov/notifications-admin/stargazers","contributors_url":"https://api.github.com/repos/alphagov/notifications-admin/contributors","subscribers_url":"https://api.github.com/repos/alphagov/notifications-admin/subscribers","subscription_url":"https://api.github.com/repos/alphagov/notifications-admin/subscription","commits_url":"https://api.github.com/repos/alphagov/notifications-admin/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/notifications-admin/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/notifications-admin/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/notifications-admin/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/notifications-admin/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/notifications-admin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/notifications-admin/merges","archive_url":"https://api.github.com/repos/alphagov/notifications-admin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/notifications-admin/downloads","issues_url":"https://api.github.com/repos/alphagov/notifications-admin/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/notifications-admin/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/notifications-admin/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/notifications-admin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/notifications-admin/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/notifications-admin/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/notifications-admin/deployments","created_at":"2015-11-18T13:55:17Z","updated_at":"2017-03-02T19:12:08Z","pushed_at":"2017-11-08T11:53:39Z","git_url":"git://github.com/alphagov/notifications-admin.git","ssh_url":"git@github.com:alphagov/notifications-admin.git","clone_url":"https://github.com/alphagov/notifications-admin.git","svn_url":"https://github.com/alphagov/notifications-admin","homepage":null,"size":7520,"stargazers_count":5,"watchers_count":5,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"archived":false,"open_issues_count":6,"forks":10,"open_issues":6,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/notifications-admin/pulls/1622"},"html":{"href":"https://github.com/alphagov/notifications-admin/pull/1622"},"issue":{"href":"https://api.github.com/repos/alphagov/notifications-admin/issues/1622"},"comments":{"href":"https://api.github.com/repos/alphagov/notifications-admin/issues/1622/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/notifications-admin/pulls/1622/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/notifications-admin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/notifications-admin/pulls/1622/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/notifications-admin/statuses/1abe828702651c7b93503c8716f9c82fe62364a1"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"quis"}}