jira-ruby 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e2f1a7c44350f6423550154d1dd1929e38f5c2af002ebc463eef3bfa035b404
4
- data.tar.gz: 4c2eb811cb02e66ff324a062fa27edaed2cf215b87cc89856a42dde1618fb3c5
3
+ metadata.gz: 280f02562d113b77a58fa5716f9cf9fe39fe6641893d3aecdd250caf4acf7d33
4
+ data.tar.gz: f29efc88140a3381b816bcbcec7a977120610470c72b4758bf359353f69eb316
5
5
  SHA512:
6
- metadata.gz: 24f0604ca0ad23f7a4204b920f4ec90ec816033c607db5686cde519a0a00668ddf13828f03769f07f0a6cd36bee51186b02164e91ed144cf0892b5cd124d5df8
7
- data.tar.gz: 2c7866e454e455465103803030f1fb40708d1ff9e04c09975594423884c5f84ceb43afb7ba853209ac26e8c9e12a91d3268b80452f8fb3641eee4a1556a787a8
6
+ metadata.gz: '087796061f2ef0472f91c36f64de9550ecb3f7ba6028e8ba91de43b3868e898d7ec4e82733bf31cf336f4a4fd4db9f2f89db320b9ff1db0759c303b6fcbf33ca'
7
+ data.tar.gz: b7fff299ec8eac30ff10f00bf36c6c659a6f29b2ab90a6b62e8ce810167ad9188d497a57f29dd389c536a393a2f8aa9897283c24f37b93ed554e8a21140b1e3e
@@ -13,8 +13,6 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.required_ruby_version = '>= 1.9.3'
15
15
 
16
- s.rubyforge_project = 'jira-ruby'
17
-
18
16
  s.files = `git ls-files`.split("\n")
19
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
18
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
@@ -4,7 +4,7 @@ module JIRA
4
4
  class JwtClient < HttpClient
5
5
  def make_request(http_method, url, body = '', headers = {})
6
6
  # When a proxy is enabled, Net::HTTP expects that the request path omits the domain name
7
- path = request_path(url) + "?jwt=#{jwt_header(http_method, url)}"
7
+ path = request_path(http_method, url)
8
8
 
9
9
  request = Net::HTTP.const_get(http_method.to_s.capitalize).new(path, headers)
10
10
  request.body = body unless body.nil?
@@ -15,18 +15,52 @@ module JIRA
15
15
  response
16
16
  end
17
17
 
18
+ class JwtUriBuilder
19
+ attr_reader :request_url, :http_method, :shared_secret, :site, :issuer
20
+
21
+ def initialize(request_url, http_method, shared_secret, site, issuer)
22
+ @request_url = request_url
23
+ @http_method = http_method
24
+ @shared_secret = shared_secret
25
+ @site = site
26
+ @issuer = issuer
27
+ end
28
+
29
+ def build
30
+ uri = URI.parse(request_url)
31
+ new_query = URI.decode_www_form(String(uri.query)) << ['jwt', jwt_header]
32
+ uri.query = URI.encode_www_form(new_query)
33
+
34
+ return uri.to_s unless uri.is_a?(URI::HTTP)
35
+
36
+ uri.request_uri
37
+ end
38
+
39
+ private
40
+
41
+ def jwt_header
42
+ claim = Atlassian::Jwt.build_claims \
43
+ issuer,
44
+ request_url,
45
+ http_method.to_s,
46
+ site,
47
+ (Time.now - 60).to_i,
48
+ (Time.now + 86_400).to_i
49
+
50
+ JWT.encode claim, shared_secret
51
+ end
52
+ end
53
+
18
54
  private
19
55
 
20
- def jwt_header(http_method, url)
21
- claim = Atlassian::Jwt.build_claims \
22
- @options[:issuer],
56
+ def request_path(http_method, url)
57
+ JwtUriBuilder.new(
23
58
  url,
24
59
  http_method.to_s,
60
+ @options[:shared_secret],
25
61
  @options[:site],
26
- (Time.now - 60).to_i,
27
- (Time.now + (86400)).to_i
28
-
29
- JWT.encode claim, @options[:shared_secret]
62
+ @options[:issuer]
63
+ ).build
30
64
  end
31
65
  end
32
66
  end
@@ -1,3 +1,3 @@
1
1
  module JIRA
2
- VERSION = '1.7.0'.freeze
2
+ VERSION = '1.7.1'.freeze
3
3
  end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe JIRA::JwtClient::JwtUriBuilder do
4
+ subject(:url_builder) do
5
+ JIRA::JwtClient::JwtUriBuilder.new(url, http_method, shared_secret, site, issuer)
6
+ end
7
+
8
+ let(:url) { '/foo' }
9
+ let(:http_method) { :get }
10
+ let(:shared_secret) { 'shared_secret' }
11
+ let(:site) { 'http://localhost:2990' }
12
+ let(:issuer) { nil }
13
+
14
+ describe '#build' do
15
+ subject { url_builder.build }
16
+
17
+ it 'includes the jwt param' do
18
+ expect(subject).to include('?jwt=')
19
+ end
20
+
21
+ context 'when the url already contains params' do
22
+ let(:url) { '/foo?expand=projects.issuetypes.fields' }
23
+
24
+ it 'includes the jwt param' do
25
+ expect(subject).to include('&jwt=')
26
+ end
27
+ end
28
+
29
+ context 'with a complete url' do
30
+ let(:url) { 'http://localhost:2990/rest/api/2/issue/createmeta' }
31
+
32
+ it 'includes the jwt param' do
33
+ expect(subject).to include('?jwt=')
34
+ end
35
+
36
+ it { is_expected.to start_with('/') }
37
+
38
+ it 'contains only one ?' do
39
+ expect(subject.count('?')).to eq(1)
40
+ end
41
+ end
42
+
43
+ context 'with a complete url containing a param' do
44
+ let(:url) do
45
+ 'http://localhost:2990/rest/api/2/issue/createmeta?expand=projects.issuetypes.fields'
46
+ end
47
+
48
+ it 'includes the jwt param' do
49
+ expect(subject).to include('&jwt=')
50
+ end
51
+
52
+ it { is_expected.to start_with('/') }
53
+
54
+ it 'contains only one ?' do
55
+ expect(subject.count('?')).to eq(1)
56
+ end
57
+ end
58
+ end
59
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SUMO Heavy Industries
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-07-11 00:00:00.000000000 Z
12
+ date: 2019-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -289,6 +289,7 @@ files:
289
289
  - spec/jira/has_many_proxy_spec.rb
290
290
  - spec/jira/http_client_spec.rb
291
291
  - spec/jira/http_error_spec.rb
292
+ - spec/jira/jwt_uri_builder_spec.rb
292
293
  - spec/jira/oauth_client_spec.rb
293
294
  - spec/jira/request_client_spec.rb
294
295
  - spec/jira/resource/agile_spec.rb
@@ -383,7 +384,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
383
384
  - !ruby/object:Gem::Version
384
385
  version: '0'
385
386
  requirements: []
386
- rubyforge_project: jira-ruby
387
+ rubyforge_project:
387
388
  rubygems_version: 2.7.6
388
389
  signing_key:
389
390
  specification_version: 4
@@ -413,6 +414,7 @@ test_files:
413
414
  - spec/jira/has_many_proxy_spec.rb
414
415
  - spec/jira/http_client_spec.rb
415
416
  - spec/jira/http_error_spec.rb
417
+ - spec/jira/jwt_uri_builder_spec.rb
416
418
  - spec/jira/oauth_client_spec.rb
417
419
  - spec/jira/request_client_spec.rb
418
420
  - spec/jira/resource/agile_spec.rb