{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/kibana/pulls/comments/188404105","pull_request_review_id":120375735,"id":188404105,"diff_hunk":"@@ -0,0 +1,231 @@\n+/*\n+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n+ * or more contributor license agreements. Licensed under the Elastic License;\n+ * you may not use this file except in compliance with the Elastic License.\n+ */\n+\n+import { createRequestHasPrivileges } from './has_privileges';\n+import { getClient } from '../../../../../server/lib/get_client_shield';\n+import { DEFAULT_RESOURCE } from '../../../common/constants';\n+import { getLoginPrivilege, getVersionPrivilege } from '../privileges';\n+\n+jest.mock('../../../../../server/lib/get_client_shield', () => ({\n+  getClient: jest.fn()\n+}));\n+\n+let mockCallWithRequest;\n+beforeEach(() => {\n+  mockCallWithRequest = jest.fn();\n+  getClient.mockReturnValue({\n+    callWithRequest: mockCallWithRequest\n+  });\n+});\n+\n+const defaultVersion = 'default-version';\n+const defaultApplication = 'default-application';\n+\n+const createMockServer = ({ settings = {} } = {}) => {\n+  const mockServer = {\n+    config: jest.fn().mockReturnValue({\n+      get: jest.fn()\n+    })\n+  };\n+\n+  const defaultSettings = {\n+    'pkg.version': defaultVersion,\n+    'xpack.security.rbac.application': defaultApplication\n+  };\n+\n+  mockServer.config().get.mockImplementation(key => {\n+    return key in settings ? settings[key] : defaultSettings[key];\n+  });\n+\n+  return mockServer;\n+};\n+\n+const mockResponse = (hasAllRequested, privileges, application = defaultApplication) => {\n+  mockCallWithRequest.mockImplementationOnce(async () => ({\n+    has_all_requested: hasAllRequested,\n+    application: {\n+      [application]: {\n+        [DEFAULT_RESOURCE]: privileges\n+      }\n+    }\n+  }));\n+};\n+\n+\n+test(`calls shield.hasPrivileges with request`, async () => {\n+  const mockServer = createMockServer();\n+  mockResponse(true, {\n+    [getVersionPrivilege(defaultVersion)]: true,\n+    [getLoginPrivilege()]: true,\n+    foo: true,\n+  });\n+\n+  const requestHasPrivileges = createRequestHasPrivileges(mockServer);\n+  const request = {};\n+  const hasPrivileges = requestHasPrivileges(request);","path":"x-pack/plugins/security/server/lib/authorization/has_privileges.test.js","position":68,"original_position":68,"commit_id":"4096be9a7fa4d3697954857e50622bcf1c26a22e","original_commit_id":"4096be9a7fa4d3697954857e50622bcf1c26a22e","user":{"login":"archanid","id":13165182,"avatar_url":"https://avatars3.githubusercontent.com/u/13165182?v=4","gravatar_id":"","url":"https://api.github.com/users/archanid","html_url":"https://github.com/archanid","followers_url":"https://api.github.com/users/archanid/followers","following_url":"https://api.github.com/users/archanid/following{/other_user}","gists_url":"https://api.github.com/users/archanid/gists{/gist_id}","starred_url":"https://api.github.com/users/archanid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/archanid/subscriptions","organizations_url":"https://api.github.com/users/archanid/orgs","repos_url":"https://api.github.com/users/archanid/repos","events_url":"https://api.github.com/users/archanid/events{/privacy}","received_events_url":"https://api.github.com/users/archanid/received_events","type":"User","site_admin":false},"body":"what if this was\r\n`const hasPrivileges = checkRequestPrivileges(request);`","created_at":"2018-05-15T19:12:42Z","updated_at":"2018-05-15T19:12:42Z","html_url":"https://github.com/elastic/kibana/pull/18645#discussion_r188404105","pull_request_url":"https://api.github.com/repos/elastic/kibana/pulls/18645","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/elastic/kibana/pulls/comments/188404105"},"html":{"href":"https://github.com/elastic/kibana/pull/18645#discussion_r188404105"},"pull_request":{"href":"https://api.github.com/repos/elastic/kibana/pulls/18645"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/kibana/pulls/18645","id":184719187,"html_url":"https://github.com/elastic/kibana/pull/18645","diff_url":"https://github.com/elastic/kibana/pull/18645.diff","patch_url":"https://github.com/elastic/kibana/pull/18645.patch","issue_url":"https://api.github.com/repos/elastic/kibana/issues/18645","number":18645,"state":"open","locked":false,"title":"Beginning to use the ES APIs to insert/check privileges","user":{"login":"kobelb","id":627123,"avatar_url":"https://avatars0.githubusercontent.com/u/627123?v=4","gravatar_id":"","url":"https://api.github.com/users/kobelb","html_url":"https://github.com/kobelb","followers_url":"https://api.github.com/users/kobelb/followers","following_url":"https://api.github.com/users/kobelb/following{/other_user}","gists_url":"https://api.github.com/users/kobelb/gists{/gist_id}","starred_url":"https://api.github.com/users/kobelb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kobelb/subscriptions","organizations_url":"https://api.github.com/users/kobelb/orgs","repos_url":"https://api.github.com/users/kobelb/repos","events_url":"https://api.github.com/users/kobelb/events{/privacy}","received_events_url":"https://api.github.com/users/kobelb/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-04-27T20:23:04Z","updated_at":"2018-05-15T19:12:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"98488ca837c32076b62992f5b1680afe48cb8614","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/elastic/kibana/pulls/18645/commits","review_comments_url":"https://api.github.com/repos/elastic/kibana/pulls/18645/comments","review_comment_url":"https://api.github.com/repos/elastic/kibana/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/kibana/issues/18645/comments","statuses_url":"https://api.github.com/repos/elastic/kibana/statuses/4096be9a7fa4d3697954857e50622bcf1c26a22e","head":{"label":"kobelb:use-es-apis","ref":"use-es-apis","sha":"4096be9a7fa4d3697954857e50622bcf1c26a22e","user":{"login":"kobelb","id":627123,"avatar_url":"https://avatars0.githubusercontent.com/u/627123?v=4","gravatar_id":"","url":"https://api.github.com/users/kobelb","html_url":"https://github.com/kobelb","followers_url":"https://api.github.com/users/kobelb/followers","following_url":"https://api.github.com/users/kobelb/following{/other_user}","gists_url":"https://api.github.com/users/kobelb/gists{/gist_id}","starred_url":"https://api.github.com/users/kobelb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kobelb/subscriptions","organizations_url":"https://api.github.com/users/kobelb/orgs","repos_url":"https://api.github.com/users/kobelb/repos","events_url":"https://api.github.com/users/kobelb/events{/privacy}","received_events_url":"https://api.github.com/users/kobelb/received_events","type":"User","site_admin":false},"repo":{"id":69892470,"name":"kibana","full_name":"kobelb/kibana","owner":{"login":"kobelb","id":627123,"avatar_url":"https://avatars0.githubusercontent.com/u/627123?v=4","gravatar_id":"","url":"https://api.github.com/users/kobelb","html_url":"https://github.com/kobelb","followers_url":"https://api.github.com/users/kobelb/followers","following_url":"https://api.github.com/users/kobelb/following{/other_user}","gists_url":"https://api.github.com/users/kobelb/gists{/gist_id}","starred_url":"https://api.github.com/users/kobelb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kobelb/subscriptions","organizations_url":"https://api.github.com/users/kobelb/orgs","repos_url":"https://api.github.com/users/kobelb/repos","events_url":"https://api.github.com/users/kobelb/events{/privacy}","received_events_url":"https://api.github.com/users/kobelb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kobelb/kibana","description":":bar_chart: Kibana analytics and search dashboard for Elasticsearch","fork":true,"url":"https://api.github.com/repos/kobelb/kibana","forks_url":"https://api.github.com/repos/kobelb/kibana/forks","keys_url":"https://api.github.com/repos/kobelb/kibana/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kobelb/kibana/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kobelb/kibana/teams","hooks_url":"https://api.github.com/repos/kobelb/kibana/hooks","issue_events_url":"https://api.github.com/repos/kobelb/kibana/issues/events{/number}","events_url":"https://api.github.com/repos/kobelb/kibana/events","assignees_url":"https://api.github.com/repos/kobelb/kibana/assignees{/user}","branches_url":"https://api.github.com/repos/kobelb/kibana/branches{/branch}","tags_url":"https://api.github.com/repos/kobelb/kibana/tags","blobs_url":"https://api.github.com/repos/kobelb/kibana/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kobelb/kibana/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kobelb/kibana/git/refs{/sha}","trees_url":"https://api.github.com/repos/kobelb/kibana/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kobelb/kibana/statuses/{sha}","languages_url":"https://api.github.com/repos/kobelb/kibana/languages","stargazers_url":"https://api.github.com/repos/kobelb/kibana/stargazers","contributors_url":"https://api.github.com/repos/kobelb/kibana/contributors","subscribers_url":"https://api.github.com/repos/kobelb/kibana/subscribers","subscription_url":"https://api.github.com/repos/kobelb/kibana/subscription","commits_url":"https://api.github.com/repos/kobelb/kibana/commits{/sha}","git_commits_url":"https://api.github.com/repos/kobelb/kibana/git/commits{/sha}","comments_url":"https://api.github.com/repos/kobelb/kibana/comments{/number}","issue_comment_url":"https://api.github.com/repos/kobelb/kibana/issues/comments{/number}","contents_url":"https://api.github.com/repos/kobelb/kibana/contents/{+path}","compare_url":"https://api.github.com/repos/kobelb/kibana/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kobelb/kibana/merges","archive_url":"https://api.github.com/repos/kobelb/kibana/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kobelb/kibana/downloads","issues_url":"https://api.github.com/repos/kobelb/kibana/issues{/number}","pulls_url":"https://api.github.com/repos/kobelb/kibana/pulls{/number}","milestones_url":"https://api.github.com/repos/kobelb/kibana/milestones{/number}","notifications_url":"https://api.github.com/repos/kobelb/kibana/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kobelb/kibana/labels{/name}","releases_url":"https://api.github.com/repos/kobelb/kibana/releases{/id}","deployments_url":"https://api.github.com/repos/kobelb/kibana/deployments","created_at":"2016-10-03T17:12:25Z","updated_at":"2016-10-03T17:12:31Z","pushed_at":"2018-05-15T17:59:54Z","git_url":"git://github.com/kobelb/kibana.git","ssh_url":"git@github.com:kobelb/kibana.git","clone_url":"https://github.com/kobelb/kibana.git","svn_url":"https://github.com/kobelb/kibana","homepage":"https://www.elastic.co/products/kibana","size":381363,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:rbac-phase-1","ref":"rbac-phase-1","sha":"646a80a1f1bdaa0b005300d76113f90799d7263c","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars0.githubusercontent.com/u/6764390?v=4","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":7833168,"name":"kibana","full_name":"elastic/kibana","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars0.githubusercontent.com/u/6764390?v=4","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/kibana","description":":bar_chart: Kibana analytics and search dashboard for Elasticsearch","fork":false,"url":"https://api.github.com/repos/elastic/kibana","forks_url":"https://api.github.com/repos/elastic/kibana/forks","keys_url":"https://api.github.com/repos/elastic/kibana/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/kibana/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/kibana/teams","hooks_url":"https://api.github.com/repos/elastic/kibana/hooks","issue_events_url":"https://api.github.com/repos/elastic/kibana/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/kibana/events","assignees_url":"https://api.github.com/repos/elastic/kibana/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/kibana/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/kibana/tags","blobs_url":"https://api.github.com/repos/elastic/kibana/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/kibana/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/kibana/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/kibana/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/kibana/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/kibana/languages","stargazers_url":"https://api.github.com/repos/elastic/kibana/stargazers","contributors_url":"https://api.github.com/repos/elastic/kibana/contributors","subscribers_url":"https://api.github.com/repos/elastic/kibana/subscribers","subscription_url":"https://api.github.com/repos/elastic/kibana/subscription","commits_url":"https://api.github.com/repos/elastic/kibana/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/kibana/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/kibana/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/kibana/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/kibana/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/kibana/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/kibana/merges","archive_url":"https://api.github.com/repos/elastic/kibana/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/kibana/downloads","issues_url":"https://api.github.com/repos/elastic/kibana/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/kibana/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/kibana/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/kibana/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/kibana/labels{/name}","releases_url":"https://api.github.com/repos/elastic/kibana/releases{/id}","deployments_url":"https://api.github.com/repos/elastic/kibana/deployments","created_at":"2013-01-26T04:00:59Z","updated_at":"2018-05-15T18:24:34Z","pushed_at":"2018-05-15T19:07:44Z","git_url":"git://github.com/elastic/kibana.git","ssh_url":"git@github.com:elastic/kibana.git","clone_url":"https://github.com/elastic/kibana.git","svn_url":"https://github.com/elastic/kibana","homepage":"https://www.elastic.co/products/kibana","size":389024,"stargazers_count":9349,"watchers_count":9349,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3634,"mirror_url":null,"archived":false,"open_issues_count":3092,"license":{"key":"other","name":"Other","spdx_id":null,"url":null},"forks":3634,"open_issues":3092,"watchers":9349,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/kibana/pulls/18645"},"html":{"href":"https://github.com/elastic/kibana/pull/18645"},"issue":{"href":"https://api.github.com/repos/elastic/kibana/issues/18645"},"comments":{"href":"https://api.github.com/repos/elastic/kibana/issues/18645/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/kibana/pulls/18645/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/kibana/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/kibana/pulls/18645/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/kibana/statuses/4096be9a7fa4d3697954857e50622bcf1c26a22e"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"archanid"}}