Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#430 Upgrade webmock and tests #438

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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