Commit 4d9f6d78 authored by Nick Thomas's avatar Nick Thomas

Fix jenkins service specs

parent d9bd7172
...@@ -8,19 +8,26 @@ describe JenkinsService do ...@@ -8,19 +8,26 @@ describe JenkinsService do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:jenkins_url) { 'http://jenkins.example.com/' }
let(:jenkins_hook_url) { jenkins_url + 'project/my_project' }
let(:jenkins_username) { 'u$er name%2520' }
let(:jenkins_password) { 'pas$ word' }
let(:jenkins_params) do let(:jenkins_params) do
{ {
active: true, active: true,
project: project, project: project,
properties: { properties: {
password: 'pas$ word', password: jenkins_password,
username: 'u$er name%2520', username: jenkins_username,
jenkins_url: 'http://jenkins.example.com/', jenkins_url: jenkins_url,
project_name: 'my_project' project_name: 'my_project'
} }
} }
end end
let(:jenkins_authorization) { "Basic " + ::Base64.strict_encode64(jenkins_username + ':' + jenkins_password) }
describe 'username validation' do describe 'username validation' do
before do before do
@jenkins_service = described_class.create( @jenkins_service = described_class.create(
...@@ -121,7 +128,7 @@ describe JenkinsService do ...@@ -121,7 +128,7 @@ describe JenkinsService do
project = create(:project, name: 'project') project = create(:project, name: 'project')
push_sample_data = Gitlab::DataBuilder::Push.build_sample(project, user) push_sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
jenkins_service = described_class.create(jenkins_params) jenkins_service = described_class.create(jenkins_params)
stub_request(:post, jenkins_service.hook_url) stub_request(:post, jenkins_hook_url).with(headers: { 'Authorization' => jenkins_authorization })
result = jenkins_service.test(push_sample_data) result = jenkins_service.test(push_sample_data)
...@@ -135,13 +142,13 @@ describe JenkinsService do ...@@ -135,13 +142,13 @@ describe JenkinsService do
project = create(:project, name: 'project') project = create(:project, name: 'project')
push_sample_data = Gitlab::DataBuilder::Push.build_sample(project, user) push_sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
jenkins_service = described_class.create(jenkins_params) jenkins_service = described_class.create(jenkins_params)
stub_request(:post, jenkins_service.hook_url) stub_request(:post, jenkins_hook_url)
jenkins_service.execute(push_sample_data) jenkins_service.execute(push_sample_data)
expect( expect(
a_request(:post, jenkins_service.hook_url) a_request(:post, jenkins_hook_url)
.with(headers: { 'X-Gitlab-Event' => 'Push Hook' }) .with(headers: { 'X-Gitlab-Event' => 'Push Hook', 'Authorization' => jenkins_authorization })
).to have_been_made.once ).to have_been_made.once
end end
...@@ -150,12 +157,13 @@ describe JenkinsService do ...@@ -150,12 +157,13 @@ describe JenkinsService do
project = create(:project, name: 'project') project = create(:project, name: 'project')
push_sample_data = Gitlab::DataBuilder::Push.build_sample(project, user) push_sample_data = Gitlab::DataBuilder::Push.build_sample(project, user)
jenkins_service = described_class.create(jenkins_params) jenkins_service = described_class.create(jenkins_params)
stub_request(:post, jenkins_service.hook_url) stub_request(:post, jenkins_hook_url)
jenkins_service.execute(push_sample_data) jenkins_service.execute(push_sample_data)
expect( expect(
a_request(:post, 'http://u%24er%20name%252520:pas%24%20word@jenkins.example.com/project/my_project') a_request(:post, 'http://jenkins.example.com/project/my_project')
.with(headers: { 'Authorization' => jenkins_authorization })
).to have_been_made.once ).to have_been_made.once
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment