diff options
author | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-09-26 16:53:18 +0300 |
---|---|---|
committer | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2019-09-26 16:53:18 +0300 |
commit | 42902b2fcba875241edca5ed5b24c6eb8108b4d0 (patch) | |
tree | 56ed32824607102e5c11ab0ca9da79acf5e93187 /spec | |
parent | 7224fd1cc5bda5aa5b0e822f7e5eba66b8d87012 (diff) | |
parent | e82f50d0e5c2aecb8041ad73cba0a571cf5f38a7 (diff) |
Merge branch 'security-12630-private-system-note-disclosed-in-graphql-12-3-ce' into '12-3-stable'
Add policy check if cross reference system notes are accessible
See merge request gitlab/gitlabhq!3426
Diffstat (limited to 'spec')
-rw-r--r-- | spec/graphql/types/issue_type_spec.rb | 79 | ||||
-rw-r--r-- | spec/policies/note_policy_spec.rb | 83 |
2 files changed, 162 insertions, 0 deletions
diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb index 799a8662b94..734e5af3cd8 100644 --- a/spec/graphql/types/issue_type_spec.rb +++ b/spec/graphql/types/issue_type_spec.rb @@ -17,4 +17,83 @@ describe GitlabSchema.types['Issue'] do expect(described_class).to have_graphql_field(field_name) end end + + describe "issue notes" do + let(:user) { create(:user) } + let(:project) { create(:project, :public) } + let(:issue) { create(:issue, project: project) } + let(:confidential_issue) { create(:issue, :confidential, project: project) } + let(:private_note_body) { "mentioned in issue #{confidential_issue.to_reference(project)}" } + let!(:note1) { create(:note, system: true, noteable: issue, author: user, project: project, note: private_note_body) } + let!(:note2) { create(:note, system: true, noteable: issue, author: user, project: project, note: 'public note') } + + let(:query) do + %( + query { + project(fullPath:"#{project.full_path}"){ + issue(iid:"#{issue.iid}"){ + descriptionHtml + notes{ + edges{ + node{ + bodyHtml + author{ + username + } + body + } + } + } + } + } + } + ) + end + + context 'query issue notes' do + subject { GitlabSchema.execute(query, context: { current_user: current_user }).as_json } + + shared_examples_for 'does not include private notes' do + it "does not return private notes" do + notes = subject.dig("data", "project", "issue", "notes", 'edges') + notes_body = notes.map {|n| n.dig('node', 'body')} + + expect(notes.size).to eq 1 + expect(notes_body).not_to include(private_note_body) + expect(notes_body).to include('public note') + end + end + + shared_examples_for 'includes private notes' do + it "returns all notes" do + notes = subject.dig("data", "project", "issue", "notes", 'edges') + notes_body = notes.map {|n| n.dig('node', 'body')} + + expect(notes.size).to eq 2 + expect(notes_body).to include(private_note_body) + expect(notes_body).to include('public note') + end + end + + context 'when user signed in' do + let(:current_user) { user } + + it_behaves_like 'does not include private notes' + + context 'when user member of the project' do + before do + project.add_developer(user) + end + + it_behaves_like 'includes private notes' + end + end + + context 'when user is anonymous' do + let(:current_user) { nil } + + it_behaves_like 'does not include private notes' + end + end + end end diff --git a/spec/policies/note_policy_spec.rb b/spec/policies/note_policy_spec.rb index bcf021f1dfd..d18ded8bce9 100644 --- a/spec/policies/note_policy_spec.rb +++ b/spec/policies/note_policy_spec.rb @@ -152,6 +152,89 @@ describe NotePolicy do it_behaves_like 'a discussion with a private noteable' end end + + context 'when it is a system note' do + let(:developer) { create(:user) } + let(:any_user) { create(:user) } + + shared_examples_for 'user can read the note' do + it 'allows the user to read the note' do + expect(policy).to be_allowed(:read_note) + end + end + + shared_examples_for 'user can act on the note' do + it 'allows the user to read the note' do + expect(policy).not_to be_allowed(:admin_note) + expect(policy).to be_allowed(:resolve_note) + expect(policy).to be_allowed(:award_emoji) + end + end + + shared_examples_for 'user cannot read or act on the note' do + it 'allows user to read the note' do + expect(policy).not_to be_allowed(:admin_note) + expect(policy).not_to be_allowed(:resolve_note) + expect(policy).not_to be_allowed(:read_note) + expect(policy).not_to be_allowed(:award_emoji) + end + end + + context 'when noteable is a public issue' do + let(:note) { create(:note, system: true, noteable: noteable, author: user, project: project) } + + before do + project.add_developer(developer) + end + + context 'when user is project member' do + let(:policy) { described_class.new(developer, note) } + + it_behaves_like 'user can read the note' + it_behaves_like 'user can act on the note' + end + + context 'when user is not project member' do + let(:policy) { described_class.new(any_user, note) } + + it_behaves_like 'user can read the note' + end + + context 'when user is anonymous' do + let(:policy) { described_class.new(nil, note) } + + it_behaves_like 'user can read the note' + end + end + + context 'when it is a system note referencing a confidential issue' do + let(:confidential_issue) { create(:issue, :confidential, project: project) } + let(:note) { create(:note, system: true, noteable: issue, author: user, project: project, note: "mentioned in issue #{confidential_issue.to_reference(project)}") } + + before do + project.add_developer(developer) + end + + context 'when user is project member' do + let(:policy) { described_class.new(developer, note) } + + it_behaves_like 'user can read the note' + it_behaves_like 'user can act on the note' + end + + context 'when user is not project member' do + let(:policy) { described_class.new(any_user, note) } + + it_behaves_like 'user cannot read or act on the note' + end + + context 'when user is anonymous' do + let(:policy) { described_class.new(nil, note) } + + it_behaves_like 'user cannot read or act on the note' + end + end + end end end end |