gemirro 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56fa41eef2a76a964a6d885f5c78ea8e6193c2442ae9dc7b3db6cae10c934ea9
4
- data.tar.gz: '08152e167296fd41283619abf268f08279b950ff3d683f500f3cdce5fe49ae5e'
3
+ metadata.gz: 1129e2117ef615eddf786284610e84808bd3e2ddd2ab21e8fafc972d9b5923e5
4
+ data.tar.gz: 2c6325d376cf3be31e8f447549697dfb9df6811da7e6aab17654059bf2a1cae6
5
5
  SHA512:
6
- metadata.gz: 0ab54b560eb64207ce1074ac87c02a71569ecf626069a59ae4aa3bfb8dbc5e504c57712e57e216a9c0d27347fca1c54db3037846fefe90ad1ad70de35423b257
7
- data.tar.gz: da5e332d738e42ca80ed7946a2bb598b213ce50d54df704f672d3717d010b07bfa5dc3e07d7b3290cc95557f657635a7de46ab9372c6a981b3b19f233c3f2acf
6
+ metadata.gz: 9550ed8196a872207d6db5809e97223f190aba44704c2886b469066f57ff7c5f4ab9ab50c11d8a43f010eef88a718fc7a5f736c3aebbf6fc2fd2a702d9c9b5f3
7
+ data.tar.gz: '0951b6fd87d27b0c830e25c1774e13fe88e322bcd8277facf4950726da931c4b1de2ee6ad0b8ba71742c9567615a57c742bbffcfb2c69a0a0ef81b67cc7bb8d6'
data/Gemfile CHANGED
@@ -3,3 +3,12 @@
3
3
  source 'https://rubygems.org/'
4
4
 
5
5
  gemspec
6
+
7
+ group :development, :test do
8
+ gem 'fakefs', '~> 2'
9
+ gem 'rack-test', '~> 1.1'
10
+ gem 'rake', '~> 13'
11
+ gem 'rspec', '~> 3.10'
12
+ gem 'rubocop', '~> 1'
13
+ gem 'simplecov', '~> 0.21'
14
+ end
data/gemirro.gemspec CHANGED
@@ -24,15 +24,10 @@ Gem::Specification.new do |s|
24
24
  s.add_dependency 'erubis', '~>2.7'
25
25
  s.add_dependency 'httpclient', '~>2.8'
26
26
  s.add_dependency 'parallel', '~>1.21'
27
- s.add_dependency 'sinatra', '>=2.1', '<4.0'
28
- s.add_dependency 'sinatra-static-assets', '~>1.0'
27
+ s.add_dependency 'sinatra', '>=3.1', '<4.0'
29
28
  s.add_dependency 'slop', '~>3.6'
29
+ s.add_dependency 'stringio', '~> 3.1'
30
30
  s.add_dependency 'thin', '~>1.8'
31
31
 
32
- s.add_development_dependency 'fakefs', '~>1'
33
- s.add_development_dependency 'rack-test', '~>1.1'
34
- s.add_development_dependency 'rake', '~>13'
35
- s.add_development_dependency 'rspec', '~>3.10'
36
- s.add_development_dependency 'rubocop', '~>1'
37
- s.add_development_dependency 'simplecov', '~>0.21'
32
+ s.metadata['rubygems_mfa_required'] = 'true'
38
33
  end
@@ -42,9 +42,7 @@ Gemirro::CLI.options.command 'server' do
42
42
  $PROGRAM_NAME = 'gemirro'
43
43
 
44
44
  def create_pid
45
- File.open(@pid_file, 'w') do |f|
46
- f.write(Process.pid.to_s)
47
- end
45
+ File.write(@pid_file, Process.pid.to_s)
48
46
  rescue Errno::EACCES
49
47
  $stdout.reopen @orig_stdout
50
48
  puts "Error: Can't write to #{@pid_file} - Permission denied"
@@ -76,7 +74,7 @@ Gemirro::CLI.options.command 'server' do
76
74
  puts "done! (PID is #{pid})\n"
77
75
  Gemirro::Server.run!
78
76
  destroy_pid
79
- $stdout.reopen '/dev/null', 'a'
77
+ $stdout.reopen File::NULL, 'a'
80
78
  end
81
79
 
82
80
  def stop
data/lib/gemirro/http.rb CHANGED
@@ -40,21 +40,21 @@ module Gemirro
40
40
 
41
41
  if defined?(config.proxy)
42
42
  proxy = config.proxy
43
- client.proxy=(proxy)
43
+ client.proxy = (proxy)
44
44
  end
45
45
 
46
46
  # Use my own ca file for self signed cert
47
47
  if defined?(config.rootca)
48
- abort "The configuration file #{config.rootca} does not exist" unless File.file?(config.rootca)
49
- client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_PEER
50
- client.ssl_config.set_trust_ca(config.rootca)
48
+ abort "The configuration file #{config.rootca} does not exist" unless File.file?(config.rootca)
49
+ client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_PEER
50
+ client.ssl_config.set_trust_ca(config.rootca)
51
51
  elsif defined?(config.verify_mode)
52
52
  client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE unless config.verify_mode
53
53
  end
54
54
 
55
55
  # Enforce base auth
56
- if defined?(config.basic_auth)
57
- client.force_basic_auth=(true) if config.basic_auth
56
+ if defined?(config.basic_auth) && config.basic_auth
57
+ client.www_auth.basic_auth.force_auth = (true)
58
58
  end
59
59
  @client = client
60
60
  end
@@ -183,7 +183,7 @@ module Gemirro
183
183
  def map_gems_to_specs(gems)
184
184
  gems.map.with_index do |gemfile, index|
185
185
  Utils.logger.info("[#{index + 1}/#{gems.size}]: Processing #{gemfile.split('/')[-1]}")
186
- if File.size(gemfile).zero?
186
+ if File.empty?(gemfile)
187
187
  Utils.logger.warn("Skipping zero-length gem: #{gemfile}")
188
188
  next
189
189
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'sinatra/base'
4
- require 'sinatra/static_assets'
5
4
  require 'thin'
6
5
  require 'uri'
7
6
  require 'addressable/uri'
@@ -11,8 +10,6 @@ module Gemirro
11
10
  # Launch Sinatra server to easily download gems.
12
11
  #
13
12
  class Server < Sinatra::Base
14
- register Sinatra::StaticAssets
15
-
16
13
  # rubocop:disable Layout/LineLength
17
14
  URI_REGEXP = /^(.*)-(\d+(?:\.\d+){1,4}.*?)(?:-(x86-(?:(?:mswin|mingw)(?:32|64)).*?|java))?\.(gem(?:spec\.rz)?)$/.freeze
18
15
  # rubocop:enable Layout/LineLength
@@ -223,6 +220,8 @@ module Gemirro
223
220
  gem_collection.compact!
224
221
 
225
222
  Parallel.map(gem_collection, in_threads: 4) do |gem, spec|
223
+ next if spec.nil?
224
+
226
225
  dependencies = spec.dependencies.select do |d|
227
226
  d.type == :runtime
228
227
  end
@@ -262,7 +261,14 @@ module Gemirro
262
261
 
263
262
  File.open(spec_file, 'r') do |uz_file|
264
263
  uz_file.binmode
265
- Marshal.load(::Gem.inflate(uz_file.read))
264
+ inflater = Zlib::Inflate.new
265
+ begin
266
+ inflate_data = inflater.inflate(uz_file.read)
267
+ ensure
268
+ inflater.finish
269
+ inflater.close
270
+ end
271
+ Marshal.load(inflate_data)
266
272
  end
267
273
  end
268
274
 
@@ -46,8 +46,8 @@ module Gemirro
46
46
  #
47
47
  def fetch_prerelease_versions
48
48
  Utils.logger.info(
49
- "Fetching #{Configuration.prerelease_versions_file}" \
50
- " on #{@name} (#{@host})"
49
+ "Fetching #{Configuration.prerelease_versions_file} " \
50
+ "on #{@name} (#{@host})"
51
51
  )
52
52
  Http.get("#{host}/#{Configuration.prerelease_versions_file}").body
53
53
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Gemirro Version
4
4
  module Gemirro
5
- VERSION = '1.4.0'
5
+ VERSION = '1.5.0'
6
6
  end
data/lib/gemirro.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'builder'
3
4
  require 'confstruct'
4
5
  require 'digest/sha2'
5
6
  require 'fileutils'
@@ -2,34 +2,93 @@ require 'spec_helper'
2
2
  require 'httpclient'
3
3
  require 'gemirro/http'
4
4
 
5
- # Http tests
6
5
  module Gemirro
7
- describe 'Http' do
8
- it 'should return http client' do
9
- expect(Http.client).to be_a(HTTPClient)
6
+ describe Http do
7
+ let(:config) { double('Configuration') }
8
+
9
+ before do
10
+ Http.instance_variable_set(:@client, nil)
11
+ allow(Utils).to receive(:configuration).and_return(config)
10
12
  end
11
13
 
12
- it 'should raise error when get request failed' do
13
- uri = 'http://github.com/PierreRambaud'
14
- Struct.new('HTTPError', :status, :reason)
15
- result = Struct::HTTPError.new(401, 'Unauthorized')
16
- allow(Http.client).to receive(:get)
17
- .once.with(uri, follow_redirect: true).and_return(result)
18
- expect { Http.get(uri) }
19
- .to raise_error HTTPClient::BadResponseError, 'Unauthorized'
14
+ describe '.client' do
15
+ it 'initializes a new HTTPClient' do
16
+ expect(Http.client).to be_a(HTTPClient)
17
+ end
18
+
19
+ context 'with proxy configuration' do
20
+ it 'sets proxy configuration' do
21
+ allow(config).to receive(:proxy).and_return('http://proxy.example.com:8080')
22
+
23
+ expect(Http.client.proxy.to_s).to eq('http://proxy.example.com:8080')
24
+ end
25
+ end
26
+
27
+ context 'with SSL configuration' do
28
+ context 'with invalid root CA path' do
29
+ before do
30
+ allow(config).to receive(:rootca).and_return('/nonexistent/ca.crt')
31
+ allow(File).to receive(:file?).with('/nonexistent/ca.crt').and_return(false)
32
+ end
33
+
34
+ it 'aborts with error message' do
35
+ expect { Http.client }.to raise_error(SystemExit)
36
+ end
37
+ end
38
+
39
+ context 'with verify_mode disabled' do
40
+ before do
41
+ allow(config).to receive(:verify_mode).and_return(false)
42
+ end
43
+
44
+ it 'sets SSL verify mode to VERIFY_NONE' do
45
+ expect(Http.client.ssl_config.verify_mode).to eq(OpenSSL::SSL::VERIFY_NONE)
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'with basic auth forced' do
51
+ before do
52
+ allow(config).to receive(:basic_auth).and_return(true)
53
+ end
54
+
55
+ it 'forces basic authentication' do
56
+ expect(Http.client.www_auth.basic_auth.force_auth).to be true
57
+ end
58
+ end
20
59
  end
21
60
 
22
- it 'should execute get request' do
23
- uri = 'http://github.com/PierreRambaud'
24
- Struct.new('HTTPResponse', :status, :body)
25
- result = Struct::HTTPResponse.new(200, 'body content')
26
- allow(Http.client).to receive(:get)
27
- .once.with(uri, follow_redirect: true).and_return(result)
28
-
29
- response = Http.get(uri)
30
- expect(response).to be_a(Struct::HTTPResponse)
31
- expect(response.body).to eq('body content')
32
- expect(response.status).to eq(200)
61
+ describe '.get' do
62
+ let(:client) { instance_double(HTTPClient) }
63
+
64
+ before do
65
+ allow(Http).to receive(:client).and_return(client)
66
+ end
67
+
68
+ context 'with successful response' do
69
+ let(:response) { double('Response', status: 200, body: 'content') }
70
+
71
+ it 'returns response for successful request' do
72
+ allow(client).to receive(:get)
73
+ .with('http://example.com', follow_redirect: true)
74
+ .and_return(response)
75
+
76
+ expect(Http.get('http://example.com')).to eq(response)
77
+ end
78
+ end
79
+
80
+ context 'with error response' do
81
+ let(:response) { double('Response', status: 404, reason: 'Not Found') }
82
+
83
+ it 'raises BadResponseError for failed request' do
84
+ allow(client).to receive(:get)
85
+ .with('http://example.com', follow_redirect: true)
86
+ .and_return(response)
87
+
88
+ expect { Http.get('http://example.com') }
89
+ .to raise_error(HTTPClient::BadResponseError, 'Not Found')
90
+ end
91
+ end
33
92
  end
34
93
  end
35
- end
94
+ end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'builder'
2
3
  require 'rubygems/indexer'
3
4
  require 'tempfile'
4
5
  require 'gemirro/source'
@@ -34,6 +35,8 @@ module Gemirro
34
35
  end
35
36
 
36
37
  it 'should install indices' do
38
+ allow(Gemirro.configuration).to receive(:destination).and_return('/tmp')
39
+
37
40
  dir = MirrorDirectory.new('/tmp')
38
41
  dir.add_directory('test')
39
42
  dir.add_directory('gem_generate_index/quick/Marshal.4.8')
data/views/layout.erb CHANGED
@@ -9,12 +9,9 @@
9
9
 
10
10
  <title>Gemirro - a simple ruby gems mirror</title>
11
11
 
12
- <%=
13
- stylesheet_link_tag(
14
- "/dist/css/bootstrap.min.css",
15
- "/dist/css/gemirro.css",
16
- :media => "screen"
17
- ) %>
12
+ <link href="/dist/css/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
13
+ <link href="/dist/css/gemirro.css" media="screen" rel="stylesheet" type="text/css" />
14
+
18
15
  </head>
19
16
  <body>
20
17
  <div class="container-fluid">
@@ -29,11 +26,7 @@
29
26
  </div>
30
27
  </div>
31
28
  </div>
32
- <%=
33
- javascript_script_tag(
34
- "/dist/js/jquery-3.2.1.slim.min.js",
35
- "/dist/js/bootstrap.bundle.min.js",
36
- :media => "screen"
37
- ) %>
29
+ <script src="/dist/js/jquery-3.2.1.slim.min.js" type="text/javascript"></script>
30
+ <script src="/dist/js/bootstrap.bundle.min.js" type="text/javascript"></script>
38
31
  </body>
39
32
  </html>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemirro
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre Rambaud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-10 00:00:00.000000000 Z
11
+ date: 2025-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -100,7 +100,7 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '2.1'
103
+ version: '3.1'
104
104
  - - "<"
105
105
  - !ruby/object:Gem::Version
106
106
  version: '4.0'
@@ -110,38 +110,38 @@ dependencies:
110
110
  requirements:
111
111
  - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: '2.1'
113
+ version: '3.1'
114
114
  - - "<"
115
115
  - !ruby/object:Gem::Version
116
116
  version: '4.0'
117
117
  - !ruby/object:Gem::Dependency
118
- name: sinatra-static-assets
118
+ name: slop
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '1.0'
123
+ version: '3.6'
124
124
  type: :runtime
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: '1.0'
130
+ version: '3.6'
131
131
  - !ruby/object:Gem::Dependency
132
- name: slop
132
+ name: stringio
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '3.6'
137
+ version: '3.1'
138
138
  type: :runtime
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '3.6'
144
+ version: '3.1'
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: thin
147
147
  requirement: !ruby/object:Gem::Requirement
@@ -156,90 +156,6 @@ dependencies:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
158
  version: '1.8'
159
- - !ruby/object:Gem::Dependency
160
- name: fakefs
161
- requirement: !ruby/object:Gem::Requirement
162
- requirements:
163
- - - "~>"
164
- - !ruby/object:Gem::Version
165
- version: '1'
166
- type: :development
167
- prerelease: false
168
- version_requirements: !ruby/object:Gem::Requirement
169
- requirements:
170
- - - "~>"
171
- - !ruby/object:Gem::Version
172
- version: '1'
173
- - !ruby/object:Gem::Dependency
174
- name: rack-test
175
- requirement: !ruby/object:Gem::Requirement
176
- requirements:
177
- - - "~>"
178
- - !ruby/object:Gem::Version
179
- version: '1.1'
180
- type: :development
181
- prerelease: false
182
- version_requirements: !ruby/object:Gem::Requirement
183
- requirements:
184
- - - "~>"
185
- - !ruby/object:Gem::Version
186
- version: '1.1'
187
- - !ruby/object:Gem::Dependency
188
- name: rake
189
- requirement: !ruby/object:Gem::Requirement
190
- requirements:
191
- - - "~>"
192
- - !ruby/object:Gem::Version
193
- version: '13'
194
- type: :development
195
- prerelease: false
196
- version_requirements: !ruby/object:Gem::Requirement
197
- requirements:
198
- - - "~>"
199
- - !ruby/object:Gem::Version
200
- version: '13'
201
- - !ruby/object:Gem::Dependency
202
- name: rspec
203
- requirement: !ruby/object:Gem::Requirement
204
- requirements:
205
- - - "~>"
206
- - !ruby/object:Gem::Version
207
- version: '3.10'
208
- type: :development
209
- prerelease: false
210
- version_requirements: !ruby/object:Gem::Requirement
211
- requirements:
212
- - - "~>"
213
- - !ruby/object:Gem::Version
214
- version: '3.10'
215
- - !ruby/object:Gem::Dependency
216
- name: rubocop
217
- requirement: !ruby/object:Gem::Requirement
218
- requirements:
219
- - - "~>"
220
- - !ruby/object:Gem::Version
221
- version: '1'
222
- type: :development
223
- prerelease: false
224
- version_requirements: !ruby/object:Gem::Requirement
225
- requirements:
226
- - - "~>"
227
- - !ruby/object:Gem::Version
228
- version: '1'
229
- - !ruby/object:Gem::Dependency
230
- name: simplecov
231
- requirement: !ruby/object:Gem::Requirement
232
- requirements:
233
- - - "~>"
234
- - !ruby/object:Gem::Version
235
- version: '0.21'
236
- type: :development
237
- prerelease: false
238
- version_requirements: !ruby/object:Gem::Requirement
239
- requirements:
240
- - - "~>"
241
- - !ruby/object:Gem::Version
242
- version: '0.21'
243
159
  description: Create your own gems mirror.
244
160
  email: pierre.rambaud86@gmail.com
245
161
  executables:
@@ -318,7 +234,8 @@ files:
318
234
  homepage: https://github.com/PierreRambaud/gemirro
319
235
  licenses:
320
236
  - GPL-3.0
321
- metadata: {}
237
+ metadata:
238
+ rubygems_mfa_required: 'true'
322
239
  post_install_message:
323
240
  rdoc_options: []
324
241
  require_paths:
@@ -334,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
334
251
  - !ruby/object:Gem::Version
335
252
  version: '0'
336
253
  requirements: []
337
- rubygems_version: 3.3.7
254
+ rubygems_version: 3.4.19
338
255
  signing_key:
339
256
  specification_version: 4
340
257
  summary: Gem for easily creating your own gems mirror.