Skip to content

Commit

Permalink
Merge pull request #438 from bobbrodie/webmock3
Browse files Browse the repository at this point in the history
#430 Upgrade webmock and tests
  • Loading branch information
bobbrodie authored Apr 27, 2024
2 parents 0c1a923 + adf937c commit 9b09576
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion jira-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'railties'
s.add_development_dependency 'rake', '~> 13.2', '>= 13.2.1'
s.add_development_dependency 'rspec', '~> 3.0', '>= 3.13'
s.add_development_dependency 'webmock', '~> 1.18', '>= 1.18.0'
s.add_development_dependency 'webmock', '~> 3.23', '>= 3.23.0'
end
18 changes: 10 additions & 8 deletions spec/jira/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,12 @@
subject { JIRA::Client.new(username: 'foo', password: 'bar', auth_type: :basic) }

before(:each) do
stub_request(:get, 'https://foo:bar@localhost:2990/jira/rest/api/2/project')
stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project')
.with(headers: { 'Authorization' => "Basic #{Base64.strict_encode64('foo:bar').chomp}" })
.to_return(status: 200, body: '[]', headers: {})

stub_request(:get, 'https://foo:badpassword@localhost:2990/jira/rest/api/2/project')
stub_request(:get, 'https://localhost:2990/jira/rest/api/2/project')
.with(headers: { 'Authorization' => "Basic #{Base64.strict_encode64('foo:badpassword').chomp}" })
.to_return(status: 401, headers: {})
end

Expand All @@ -157,17 +159,17 @@
expect(subject.options[:password]).to eq('bar')
end

it 'only returns a true for #authenticated? once we have requested some data' do
expect(subject.authenticated?).to be_nil
expect(subject.Project.all).to be_empty
expect(subject.authenticated?).to be_truthy
end

it 'fails with wrong user name and password' do
bad_login = JIRA::Client.new(username: 'foo', password: 'badpassword', auth_type: :basic)
expect(bad_login.authenticated?).to be_falsey
expect { bad_login.Project.all }.to raise_error JIRA::HTTPError
end

it 'only returns a true for #authenticated? once we have requested some data' do
expect(subject.authenticated?).to be_falsey
expect(subject.Project.all).to be_empty
expect(subject.authenticated?).to be_truthy
end
end

context 'with cookie authentication' do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/clients_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def with_each_client
clients['http://localhost:2990'] = oauth_client

basic_client = JIRA::Client.new(username: 'foo', password: 'bar', auth_type: :basic, use_ssl: false)
clients['http://foo:bar@localhost:2990'] = basic_client
clients['http://localhost:2990'] = basic_client

clients.each do |site_url, client|
yield site_url, client
Expand Down

0 comments on commit 9b09576

Please sign in to comment.