{"action":"created","comment":{"url":"https://api.github.com/repos/buildo/toctoc/pulls/comments/168451273","pull_request_review_id":96813718,"id":168451273,"diff_hunk":"@@ -0,0 +1,131 @@\n+package io.buildo.toctoc\n+package quill\n+package authentication\n+package test\n+\n+import core.authentication.TokenBasedAuthentication._\n+import login.QuillLoginAuthenticationDomain\n+import token.QuillAccessTokenAuthenticationDomain\n+\n+import org.scalatest._\n+import org.scalatest.concurrent.ScalaFutures\n+import io.getquill._\n+import io.getquill.{CamelCase, PostgresAsyncContext}\n+import org.flywaydb.core.Flyway\n+import com.typesafe.config.ConfigFactory\n+\n+import scala.concurrent.ExecutionContext.Implicits.global\n+\n+class QuillLoginAuthenticationDomainFlowSpec\n+    extends FlatSpec\n+    with BeforeAndAfterEach\n+    with BeforeAndAfterAll\n+    with ScalaFutures\n+    with EitherValues\n+    with Matchers {\n+\n+  val ctx = new PostgresAsyncContext(CamelCase, \"db\")\n+  val loginAuthDomain = new QuillLoginAuthenticationDomain(ctx)(global)\n+  val accessTokenAuthDomain =\n+    new QuillAccessTokenAuthenticationDomain(ctx)(global)\n+\n+  val authFlow = new QuillTokenBasedAuthenticationFlow(ctx)\n+\n+  override def beforeAll() = {\n+    val flyway = new Flyway()\n+    val config = ConfigFactory.load().getConfig(\"db\")\n+    val host = config.getString(\"host\")\n+    val port = config.getString(\"port\")\n+    val user = config.getString(\"user\")\n+    val password = config.getString(\"password\")\n+    val database = config.getString(\"database\")\n+    flyway.setDataSource(s\"jdbc:postgresql://$host:$port/$database\", user, password)\n+    flyway.clean()\n+    flyway.migrate()\n+    ()\n+  }\n+\n+  override def afterEach() = {\n+    import ctx._\n+    ctx.run(quote(querySchema(\"LoginAuthDomain\").delete))\n+    ctx.run(quote(querySchema(\"AccessTokenAuthDomain\").delete))\n+    ()\n+  }\n+\n+  override def afterAll() = {\n+    ctx.close()\n+  }\n+\n+  import org.scalatest.time._\n+  implicit val defaultPatience =\n+    PatienceConfig(timeout = Span(2, Seconds), interval = Span(5, Millis))\n+\n+  val login = Login(\"username\", \"password\")\n+  val login2 = Login(\"usernameoso\", \"password\")\n+  val login3 = Login(\"usernameosone\", \"password\")\n+  val subject = UserSubject(\"test\")\n+  val subject2 = UserSubject(\"test2\")\n+\n+  \"unregistered login credentials\" should \"not be accepted when exchanging for token\" in {\n+    authFlow.exchangeForTokens(login).futureValue shouldBe 'left\n+  }\n+\n+  \"registered login credentials\" should \"be accepted when exchanging for token\" in {\n+    authFlow.registerSubjectLogin(subject, login).futureValue shouldBe 'right\n+    authFlow.exchangeForTokens(login).futureValue shouldBe 'right\n+  }\n+\n+  \"token obtained by login\" should \"be validated\" in {\n+    authFlow.registerSubjectLogin(subject, login).futureValue shouldBe 'right\n+    val token = authFlow.exchangeForTokens(login).futureValue.right.value\n+    authFlow.validateToken(token).futureValue.right.value shouldBe subject\n+  }\n+\n+  \"multiple login with same values\" should \"not be accepted in registration\" in {\n+    authFlow.registerSubjectLogin(subject, login).futureValue shouldBe 'right\n+    authFlow.registerSubjectLogin(subject, login).futureValue shouldBe 'left\n+  }\n+\n+  \"multiple login with different values\" should \"be accepted in registration\" in {\n+    authFlow.registerSubjectLogin(subject, login).futureValue shouldBe 'right\n+    authFlow.registerSubjectLogin(subject2, login2).futureValue shouldBe 'right\n+    val token2 = authFlow.exchangeForTokens(login2).futureValue.right.value\n+    authFlow.validateToken(token2).futureValue.right.value shouldBe subject2\n+  }\n+\n+  \"single token unregistration\" should \"unregister only the specific token\" in {\n+    authFlow.registerSubjectLogin(subject, login).futureValue shouldBe 'right\n+    authFlow.registerSubjectLogin(subject2, login2).futureValue shouldBe 'right\n+    val token = authFlow.exchangeForTokens(login).futureValue.right.value\n+    val token2 = authFlow.exchangeForTokens(login2).futureValue.right.value\n+    authFlow.unregisterToken(token).futureValue\n+    authFlow.validateToken(token).futureValue shouldBe 'left\n+    authFlow.validateToken(token2).futureValue shouldBe 'right\n+  }\n+\n+  \"token unregistration\" should \"unregister all subject's tokens\" in {\n+    authFlow.registerSubjectLogin(subject, login).futureValue shouldBe 'right\n+    authFlow.registerSubjectLogin(subject2, login2).futureValue shouldBe 'right\n+    val token = authFlow.exchangeForTokens(login).futureValue.right.value\n+    val token2 = authFlow.exchangeForTokens(login).futureValue.right.value\n+    val token3 = authFlow.exchangeForTokens(login2).futureValue.right.value\n+    authFlow.unregisterAllSubjectTokens(subject).futureValue\n+    authFlow.validateToken(token).futureValue shouldBe 'left\n+    authFlow.validateToken(token2).futureValue shouldBe 'left\n+    authFlow.validateToken(token3).futureValue shouldBe 'right\n+  }\n+\n+  \"single subject credentials unregistration\" should \"take effect\" in {\n+    authFlow.unregisterLogin(login).futureValue\n+    authFlow.exchangeForTokens(login).futureValue shouldBe 'left","path":"backend/quill/src/test/scala/io.buildo.toctoc/quill/authentication/test/QuillLoginAuthenticationDomainFlowSpec.scala","position":120,"original_position":120,"commit_id":"1d16bc595c2359046d03893b09e713043436e4c1","original_commit_id":"1d16bc595c2359046d03893b09e713043436e4c1","user":{"login":"bytecodeguru","id":11717120,"avatar_url":"https://avatars3.githubusercontent.com/u/11717120?v=4","gravatar_id":"","url":"https://api.github.com/users/bytecodeguru","html_url":"https://github.com/bytecodeguru","followers_url":"https://api.github.com/users/bytecodeguru/followers","following_url":"https://api.github.com/users/bytecodeguru/following{/other_user}","gists_url":"https://api.github.com/users/bytecodeguru/gists{/gist_id}","starred_url":"https://api.github.com/users/bytecodeguru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bytecodeguru/subscriptions","organizations_url":"https://api.github.com/users/bytecodeguru/orgs","repos_url":"https://api.github.com/users/bytecodeguru/repos","events_url":"https://api.github.com/users/bytecodeguru/events{/privacy}","received_events_url":"https://api.github.com/users/bytecodeguru/received_events","type":"User","site_admin":false},"body":"Perhaps this test is missing a precondition:\r\n\r\n```\r\nauthFlow.registerSubjectLogin(subject, login).futureValue shouldBe 'right\r\n```\r\n","created_at":"2018-02-15T11:43:05Z","updated_at":"2018-02-15T11:44:56Z","html_url":"https://github.com/buildo/toctoc/pull/26#discussion_r168451273","pull_request_url":"https://api.github.com/repos/buildo/toctoc/pulls/26","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/buildo/toctoc/pulls/comments/168451273"},"html":{"href":"https://github.com/buildo/toctoc/pull/26#discussion_r168451273"},"pull_request":{"href":"https://api.github.com/repos/buildo/toctoc/pulls/26"}}},"pull_request":{"url":"https://api.github.com/repos/buildo/toctoc/pulls/26","id":168298391,"html_url":"https://github.com/buildo/toctoc/pull/26","diff_url":"https://github.com/buildo/toctoc/pull/26.diff","patch_url":"https://github.com/buildo/toctoc/pull/26.patch","issue_url":"https://api.github.com/repos/buildo/toctoc/issues/26","number":26,"state":"open","locked":false,"title":"Quill tests","user":{"login":"gabro","id":691940,"avatar_url":"https://avatars0.githubusercontent.com/u/691940?v=4","gravatar_id":"","url":"https://api.github.com/users/gabro","html_url":"https://github.com/gabro","followers_url":"https://api.github.com/users/gabro/followers","following_url":"https://api.github.com/users/gabro/following{/other_user}","gists_url":"https://api.github.com/users/gabro/gists{/gist_id}","starred_url":"https://api.github.com/users/gabro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabro/subscriptions","organizations_url":"https://api.github.com/users/gabro/orgs","repos_url":"https://api.github.com/users/gabro/repos","events_url":"https://api.github.com/users/gabro/events{/privacy}","received_events_url":"https://api.github.com/users/gabro/received_events","type":"User","site_admin":false},"body":"Still WIP","created_at":"2018-02-09T17:27:59Z","updated_at":"2018-02-15T11:44:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b0e0e1a0bec8ae72c147bffec27f4b11355cf56a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":703310932,"url":"https://api.github.com/repos/buildo/toctoc/labels/in%20review","name":"in review","color":"333333","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/buildo/toctoc/pulls/26/commits","review_comments_url":"https://api.github.com/repos/buildo/toctoc/pulls/26/comments","review_comment_url":"https://api.github.com/repos/buildo/toctoc/pulls/comments{/number}","comments_url":"https://api.github.com/repos/buildo/toctoc/issues/26/comments","statuses_url":"https://api.github.com/repos/buildo/toctoc/statuses/1d16bc595c2359046d03893b09e713043436e4c1","head":{"label":"buildo:quill-tests","ref":"quill-tests","sha":"1d16bc595c2359046d03893b09e713043436e4c1","user":{"login":"buildo","id":7370958,"avatar_url":"https://avatars3.githubusercontent.com/u/7370958?v=4","gravatar_id":"","url":"https://api.github.com/users/buildo","html_url":"https://github.com/buildo","followers_url":"https://api.github.com/users/buildo/followers","following_url":"https://api.github.com/users/buildo/following{/other_user}","gists_url":"https://api.github.com/users/buildo/gists{/gist_id}","starred_url":"https://api.github.com/users/buildo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buildo/subscriptions","organizations_url":"https://api.github.com/users/buildo/orgs","repos_url":"https://api.github.com/users/buildo/repos","events_url":"https://api.github.com/users/buildo/events{/privacy}","received_events_url":"https://api.github.com/users/buildo/received_events","type":"Organization","site_admin":false},"repo":{"id":104885737,"name":"toctoc","full_name":"buildo/toctoc","owner":{"login":"buildo","id":7370958,"avatar_url":"https://avatars3.githubusercontent.com/u/7370958?v=4","gravatar_id":"","url":"https://api.github.com/users/buildo","html_url":"https://github.com/buildo","followers_url":"https://api.github.com/users/buildo/followers","following_url":"https://api.github.com/users/buildo/following{/other_user}","gists_url":"https://api.github.com/users/buildo/gists{/gist_id}","starred_url":"https://api.github.com/users/buildo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buildo/subscriptions","organizations_url":"https://api.github.com/users/buildo/orgs","repos_url":"https://api.github.com/users/buildo/repos","events_url":"https://api.github.com/users/buildo/events{/privacy}","received_events_url":"https://api.github.com/users/buildo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/buildo/toctoc","description":null,"fork":false,"url":"https://api.github.com/repos/buildo/toctoc","forks_url":"https://api.github.com/repos/buildo/toctoc/forks","keys_url":"https://api.github.com/repos/buildo/toctoc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/buildo/toctoc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/buildo/toctoc/teams","hooks_url":"https://api.github.com/repos/buildo/toctoc/hooks","issue_events_url":"https://api.github.com/repos/buildo/toctoc/issues/events{/number}","events_url":"https://api.github.com/repos/buildo/toctoc/events","assignees_url":"https://api.github.com/repos/buildo/toctoc/assignees{/user}","branches_url":"https://api.github.com/repos/buildo/toctoc/branches{/branch}","tags_url":"https://api.github.com/repos/buildo/toctoc/tags","blobs_url":"https://api.github.com/repos/buildo/toctoc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/buildo/toctoc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/buildo/toctoc/git/refs{/sha}","trees_url":"https://api.github.com/repos/buildo/toctoc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/buildo/toctoc/statuses/{sha}","languages_url":"https://api.github.com/repos/buildo/toctoc/languages","stargazers_url":"https://api.github.com/repos/buildo/toctoc/stargazers","contributors_url":"https://api.github.com/repos/buildo/toctoc/contributors","subscribers_url":"https://api.github.com/repos/buildo/toctoc/subscribers","subscription_url":"https://api.github.com/repos/buildo/toctoc/subscription","commits_url":"https://api.github.com/repos/buildo/toctoc/commits{/sha}","git_commits_url":"https://api.github.com/repos/buildo/toctoc/git/commits{/sha}","comments_url":"https://api.github.com/repos/buildo/toctoc/comments{/number}","issue_comment_url":"https://api.github.com/repos/buildo/toctoc/issues/comments{/number}","contents_url":"https://api.github.com/repos/buildo/toctoc/contents/{+path}","compare_url":"https://api.github.com/repos/buildo/toctoc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/buildo/toctoc/merges","archive_url":"https://api.github.com/repos/buildo/toctoc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/buildo/toctoc/downloads","issues_url":"https://api.github.com/repos/buildo/toctoc/issues{/number}","pulls_url":"https://api.github.com/repos/buildo/toctoc/pulls{/number}","milestones_url":"https://api.github.com/repos/buildo/toctoc/milestones{/number}","notifications_url":"https://api.github.com/repos/buildo/toctoc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/buildo/toctoc/labels{/name}","releases_url":"https://api.github.com/repos/buildo/toctoc/releases{/id}","deployments_url":"https://api.github.com/repos/buildo/toctoc/deployments","created_at":"2017-09-26T13:06:05Z","updated_at":"2017-12-01T11:17:59Z","pushed_at":"2018-02-15T11:15:29Z","git_url":"git://github.com/buildo/toctoc.git","ssh_url":"git@github.com:buildo/toctoc.git","clone_url":"https://github.com/buildo/toctoc.git","svn_url":"https://github.com/buildo/toctoc","homepage":null,"size":257,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":9,"license":null,"forks":0,"open_issues":9,"watchers":0,"default_branch":"master"}},"base":{"label":"buildo:master","ref":"master","sha":"1160bd1167abe4d4ef225753775f9d0b9cc8e5a6","user":{"login":"buildo","id":7370958,"avatar_url":"https://avatars3.githubusercontent.com/u/7370958?v=4","gravatar_id":"","url":"https://api.github.com/users/buildo","html_url":"https://github.com/buildo","followers_url":"https://api.github.com/users/buildo/followers","following_url":"https://api.github.com/users/buildo/following{/other_user}","gists_url":"https://api.github.com/users/buildo/gists{/gist_id}","starred_url":"https://api.github.com/users/buildo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buildo/subscriptions","organizations_url":"https://api.github.com/users/buildo/orgs","repos_url":"https://api.github.com/users/buildo/repos","events_url":"https://api.github.com/users/buildo/events{/privacy}","received_events_url":"https://api.github.com/users/buildo/received_events","type":"Organization","site_admin":false},"repo":{"id":104885737,"name":"toctoc","full_name":"buildo/toctoc","owner":{"login":"buildo","id":7370958,"avatar_url":"https://avatars3.githubusercontent.com/u/7370958?v=4","gravatar_id":"","url":"https://api.github.com/users/buildo","html_url":"https://github.com/buildo","followers_url":"https://api.github.com/users/buildo/followers","following_url":"https://api.github.com/users/buildo/following{/other_user}","gists_url":"https://api.github.com/users/buildo/gists{/gist_id}","starred_url":"https://api.github.com/users/buildo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/buildo/subscriptions","organizations_url":"https://api.github.com/users/buildo/orgs","repos_url":"https://api.github.com/users/buildo/repos","events_url":"https://api.github.com/users/buildo/events{/privacy}","received_events_url":"https://api.github.com/users/buildo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/buildo/toctoc","description":null,"fork":false,"url":"https://api.github.com/repos/buildo/toctoc","forks_url":"https://api.github.com/repos/buildo/toctoc/forks","keys_url":"https://api.github.com/repos/buildo/toctoc/keys{/key_id}","collaborators_url":"https://api.github.com/repos/buildo/toctoc/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/buildo/toctoc/teams","hooks_url":"https://api.github.com/repos/buildo/toctoc/hooks","issue_events_url":"https://api.github.com/repos/buildo/toctoc/issues/events{/number}","events_url":"https://api.github.com/repos/buildo/toctoc/events","assignees_url":"https://api.github.com/repos/buildo/toctoc/assignees{/user}","branches_url":"https://api.github.com/repos/buildo/toctoc/branches{/branch}","tags_url":"https://api.github.com/repos/buildo/toctoc/tags","blobs_url":"https://api.github.com/repos/buildo/toctoc/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/buildo/toctoc/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/buildo/toctoc/git/refs{/sha}","trees_url":"https://api.github.com/repos/buildo/toctoc/git/trees{/sha}","statuses_url":"https://api.github.com/repos/buildo/toctoc/statuses/{sha}","languages_url":"https://api.github.com/repos/buildo/toctoc/languages","stargazers_url":"https://api.github.com/repos/buildo/toctoc/stargazers","contributors_url":"https://api.github.com/repos/buildo/toctoc/contributors","subscribers_url":"https://api.github.com/repos/buildo/toctoc/subscribers","subscription_url":"https://api.github.com/repos/buildo/toctoc/subscription","commits_url":"https://api.github.com/repos/buildo/toctoc/commits{/sha}","git_commits_url":"https://api.github.com/repos/buildo/toctoc/git/commits{/sha}","comments_url":"https://api.github.com/repos/buildo/toctoc/comments{/number}","issue_comment_url":"https://api.github.com/repos/buildo/toctoc/issues/comments{/number}","contents_url":"https://api.github.com/repos/buildo/toctoc/contents/{+path}","compare_url":"https://api.github.com/repos/buildo/toctoc/compare/{base}...{head}","merges_url":"https://api.github.com/repos/buildo/toctoc/merges","archive_url":"https://api.github.com/repos/buildo/toctoc/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/buildo/toctoc/downloads","issues_url":"https://api.github.com/repos/buildo/toctoc/issues{/number}","pulls_url":"https://api.github.com/repos/buildo/toctoc/pulls{/number}","milestones_url":"https://api.github.com/repos/buildo/toctoc/milestones{/number}","notifications_url":"https://api.github.com/repos/buildo/toctoc/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/buildo/toctoc/labels{/name}","releases_url":"https://api.github.com/repos/buildo/toctoc/releases{/id}","deployments_url":"https://api.github.com/repos/buildo/toctoc/deployments","created_at":"2017-09-26T13:06:05Z","updated_at":"2017-12-01T11:17:59Z","pushed_at":"2018-02-15T11:15:29Z","git_url":"git://github.com/buildo/toctoc.git","ssh_url":"git@github.com:buildo/toctoc.git","clone_url":"https://github.com/buildo/toctoc.git","svn_url":"https://github.com/buildo/toctoc","homepage":null,"size":257,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":9,"license":null,"forks":0,"open_issues":9,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/buildo/toctoc/pulls/26"},"html":{"href":"https://github.com/buildo/toctoc/pull/26"},"issue":{"href":"https://api.github.com/repos/buildo/toctoc/issues/26"},"comments":{"href":"https://api.github.com/repos/buildo/toctoc/issues/26/comments"},"review_comments":{"href":"https://api.github.com/repos/buildo/toctoc/pulls/26/comments"},"review_comment":{"href":"https://api.github.com/repos/buildo/toctoc/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/buildo/toctoc/pulls/26/commits"},"statuses":{"href":"https://api.github.com/repos/buildo/toctoc/statuses/1d16bc595c2359046d03893b09e713043436e4c1"}},"author_association":"OWNER"}}
{"actor":{"display_login":"bytecodeguru"}}