2019-12-05 07:07:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe API::Entities::Release do
|
2019-12-05 07:07:43 -05:00
|
|
|
let_it_be(:project) { create(:project) }
|
2020-06-02 14:08:32 -04:00
|
|
|
let(:release) { create(:release, project: project) }
|
2020-03-24 08:09:42 -04:00
|
|
|
let(:evidence) { release.evidences.first }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:entity) { described_class.new(release, current_user: user).as_json }
|
2020-03-12 08:09:17 -04:00
|
|
|
|
2020-06-02 14:08:32 -04:00
|
|
|
before do
|
|
|
|
::Releases::CreateEvidenceService.new(release).execute
|
|
|
|
end
|
|
|
|
|
2020-03-24 08:09:42 -04:00
|
|
|
describe 'evidences' do
|
2019-12-05 07:07:43 -05:00
|
|
|
context 'when the current user can download code' do
|
2020-03-24 08:09:42 -04:00
|
|
|
let(:entity_evidence) { entity[:evidences].first }
|
|
|
|
|
2019-12-05 07:07:43 -05:00
|
|
|
it 'exposes the evidence sha and the json path' do
|
|
|
|
allow(Ability).to receive(:allowed?).and_call_original
|
|
|
|
allow(Ability).to receive(:allowed?)
|
|
|
|
.with(user, :download_code, project).and_return(true)
|
|
|
|
|
2020-03-24 08:09:42 -04:00
|
|
|
expect(entity_evidence[:sha]).to eq(evidence.summary_sha)
|
|
|
|
expect(entity_evidence[:collected_at]).to eq(evidence.collected_at)
|
|
|
|
expect(entity_evidence[:filepath]).to eq(
|
|
|
|
Gitlab::Routing.url_helpers.namespace_project_evidence_url(
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
tag: release,
|
|
|
|
id: evidence.id,
|
|
|
|
format: :json))
|
2019-12-05 07:07:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the current user cannot download code' do
|
|
|
|
it 'does not expose any evidence data' do
|
|
|
|
allow(Ability).to receive(:allowed?).and_call_original
|
|
|
|
allow(Ability).to receive(:allowed?)
|
|
|
|
.with(user, :download_code, project).and_return(false)
|
|
|
|
|
2020-03-24 08:09:42 -04:00
|
|
|
expect(entity.keys).not_to include(:evidences)
|
2019-12-05 07:07:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-03-12 08:09:17 -04:00
|
|
|
|
|
|
|
describe 'description_html' do
|
|
|
|
let(:issue) { create(:issue, :confidential, project: project) }
|
|
|
|
let(:issue_path) { Gitlab::Routing.url_helpers.project_issue_path(project, issue) }
|
|
|
|
let(:issue_title) { 'title="%s"' % issue.title }
|
|
|
|
let(:release) { create(:release, project: project, description: "Now shipping #{issue.to_reference}") }
|
|
|
|
|
2020-03-24 08:09:42 -04:00
|
|
|
subject(:description_html) { entity.as_json['description_html'] }
|
2020-03-12 08:09:17 -04:00
|
|
|
|
|
|
|
it 'renders special references if current user has access' do
|
|
|
|
project.add_reporter(user)
|
|
|
|
|
|
|
|
expect(description_html).to include(issue_path)
|
|
|
|
expect(description_html).to include(issue_title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not render special references if current user has no access' do
|
|
|
|
project.add_guest(user)
|
|
|
|
|
|
|
|
expect(description_html).not_to include(issue_path)
|
|
|
|
expect(description_html).not_to include(issue_title)
|
|
|
|
end
|
|
|
|
end
|
2019-12-05 07:07:43 -05:00
|
|
|
end
|