diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/lib/gitlab/jira | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/lib/gitlab/jira')
-rw-r--r-- | spec/lib/gitlab/jira/dvcs_spec.rb | 58 | ||||
-rw-r--r-- | spec/lib/gitlab/jira/middleware_spec.rb | 40 |
2 files changed, 98 insertions, 0 deletions
diff --git a/spec/lib/gitlab/jira/dvcs_spec.rb b/spec/lib/gitlab/jira/dvcs_spec.rb new file mode 100644 index 00000000000..09e777b38ea --- /dev/null +++ b/spec/lib/gitlab/jira/dvcs_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Jira::Dvcs do + describe '.encode_slash' do + it 'replaces slash character' do + expect(described_class.encode_slash('a/b/c')).to eq('a@b@c') + end + + it 'ignores path without slash' do + expect(described_class.encode_slash('foo')).to eq('foo') + end + end + + describe '.decode_slash' do + it 'replaces slash character' do + expect(described_class.decode_slash('a@b@c')).to eq('a/b/c') + end + + it 'ignores path without slash' do + expect(described_class.decode_slash('foo')).to eq('foo') + end + end + + describe '.encode_project_name' do + let(:group) { create(:group)} + let(:project) { create(:project, group: group)} + + context 'root group' do + it 'returns project path' do + expect(described_class.encode_project_name(project)).to eq(project.path) + end + end + + context 'nested group' do + let(:group) { create(:group, :nested)} + + it 'returns encoded project full path' do + expect(described_class.encode_project_name(project)).to eq(described_class.encode_slash(project.full_path)) + end + end + end + + describe '.restore_full_path' do + context 'project name is an encoded full path' do + it 'returns decoded project path' do + expect(described_class.restore_full_path(namespace: 'group1', project: 'group1@group2@project1')).to eq('group1/group2/project1') + end + end + + context 'project name is not an encoded full path' do + it 'assumes project belongs to root namespace and returns full project path based on passed in namespace' do + expect(described_class.restore_full_path(namespace: 'group1', project: 'project1')).to eq('group1/project1') + end + end + end +end diff --git a/spec/lib/gitlab/jira/middleware_spec.rb b/spec/lib/gitlab/jira/middleware_spec.rb new file mode 100644 index 00000000000..1fe22b145a6 --- /dev/null +++ b/spec/lib/gitlab/jira/middleware_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Jira::Middleware do + let(:app) { double(:app) } + let(:middleware) { described_class.new(app) } + let(:jira_user_agent) { 'Jira DVCS Connector Vertigo/5.0.0-D20170810T012915' } + + describe '.jira_dvcs_connector?' do + it 'returns true when DVCS connector' do + expect(described_class.jira_dvcs_connector?('HTTP_USER_AGENT' => jira_user_agent)).to eq(true) + end + + it 'returns true if user agent starts with "Jira DVCS Connector"' do + expect(described_class.jira_dvcs_connector?('HTTP_USER_AGENT' => 'Jira DVCS Connector')).to eq(true) + end + + it 'returns false when not DVCS connector' do + expect(described_class.jira_dvcs_connector?('HTTP_USER_AGENT' => 'pokemon')).to eq(false) + end + end + + describe '#call' do + it 'adjusts HTTP_AUTHORIZATION env when request from Jira DVCS user agent' do + expect(app).to receive(:call).with('HTTP_USER_AGENT' => jira_user_agent, + 'HTTP_AUTHORIZATION' => 'Bearer hash-123') + + middleware.call('HTTP_USER_AGENT' => jira_user_agent, 'HTTP_AUTHORIZATION' => 'token hash-123') + end + + it 'does not change HTTP_AUTHORIZATION env when request is not from Jira DVCS user agent' do + env = { 'HTTP_USER_AGENT' => 'Mozilla/5.0', 'HTTP_AUTHORIZATION' => 'token hash-123' } + + expect(app).to receive(:call).with(env) + + middleware.call(env) + end + end +end |