nexus-debug 1.4.0

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.
@@ -0,0 +1,365 @@
1
+ require 'command_helper'
2
+ require 'fileutils'
3
+
4
+ class NexusCommandTest < CommandTest
5
+
6
+ context "all repos" do
7
+ setup do
8
+ @command = Gem::Commands::NexusCommand.new
9
+ config = File.join( 'pkg', 'allrepocfg' )
10
+ FileUtils.rm_f( config )
11
+ @command.options[ :nexus_config ] = config
12
+ end
13
+
14
+ should "list" do
15
+ @command.options[ :nexus_all_repos ] = true
16
+ mock(@command).list_repos
17
+ @command.execute
18
+ assert_received(@command) { |command| command.list_repos }
19
+ end
20
+
21
+ should "not list" do
22
+ @command.options[ :nexus_all_repos ] = false
23
+ mock(@command).configure_url
24
+ mock(@command).sign_in
25
+ mock(@command).send_gem
26
+ @command.execute
27
+ assert_received(@command) { |command| command.configure_url }
28
+ assert_received(@command) { |command| command.sign_in }
29
+ assert_received(@command) { |command| command.send_gem }
30
+ end
31
+ end
32
+
33
+ context "encryption" do
34
+ setup do
35
+ @command = Gem::Commands::NexusCommand.new
36
+ @with = File.join( 'pkg', 'encryption' )
37
+ @from = File.join( 'test', 'encryption' )
38
+ [ ".config", ".secrets" ].each do |postfix|
39
+ FileUtils.cp( @from + postfix, @with + postfix )
40
+ end
41
+
42
+ FileUtils.cp( @from, @with )
43
+ end
44
+
45
+ should "with secrets file" do
46
+ @command.options[ :nexus_config ] = @with + ".config"
47
+ @command.options[ :nexus_encrypt ] = true
48
+ mock(@command).ask( "Enter your Nexus encryption credentials (no prompt)" ) { 'behappy' }
49
+ @command.execute
50
+ assert_equal( File.read( @with + ".config" ),
51
+ File.read( @from + ".config" ) )
52
+ assert_equal( File.read( @with + ".secrets" ) != File.read( @from + ".secrets" ), true )
53
+
54
+ @command.options.delete( :nexus_encrypt )
55
+ mock(@command).prompt_encryption
56
+ mock(@command).send_gem
57
+ @command.execute
58
+ assert_equal @command.authorization != /^Basic /, true
59
+ assert_received(@command) { |command| command.prompt_encryption }
60
+ assert_received(@command) { |command| command.send_gem }
61
+ end
62
+
63
+ should "without secrets file" do
64
+ @command.options[ :nexus_config ] = @with
65
+ @command.options[ :nexus_encrypt ] = true
66
+ mock(@command).ask( "Enter your Nexus encryption credentials (no prompt)" ) { 'behappy' }
67
+ @command.execute
68
+ assert_equal( File.read( @with ) != File.read( @from ), true )
69
+
70
+ @command.options.delete( :nexus_encrypt )
71
+ mock(@command).prompt_encryption
72
+ mock(@command).send_gem
73
+ @command.execute
74
+ assert_equal @command.authorization != /^Basic /, true
75
+ assert_received(@command) { |command| command.prompt_encryption }
76
+ assert_received(@command) { |command| command.send_gem }
77
+ end
78
+
79
+ should "prompt when configured" do
80
+ config_path = File.join( 'pkg', 'encconfig_prompt')
81
+ File.open( config_path, 'w') do |f|
82
+ h = { :url => 'http://example.com',
83
+ :authorization => 'something',
84
+ :token => 'pe/ty1I5sl7qD5drdsSXOBi0peRYOqdhhvRXJBjzzNY=' }
85
+ f.write h.to_yaml
86
+ end
87
+ stub(@command).options { {:nexus_config => config_path } }
88
+ stub(@command).ask_for_password { "behappy" }
89
+
90
+ @command.setup
91
+ assert_equal @command.config.encrypted?, true
92
+ end
93
+ end
94
+
95
+ context "decryption" do
96
+ setup do
97
+ @command = Gem::Commands::NexusCommand.new
98
+ @with = File.join( 'pkg', 'decryption' )
99
+ @from = File.join( 'test', 'decryption' )
100
+ [ ".config", ".secrets" ].each do |postfix|
101
+ FileUtils.cp( @from + postfix, @with + postfix )
102
+ end
103
+
104
+ FileUtils.cp( @from, @with )
105
+ end
106
+
107
+ should "with secrets file" do
108
+ @command.options[ :nexus_config ] = @with + ".config"
109
+ @command.options[ :nexus_encrypt ] = false
110
+ mock(@command).ask( "Enter your Nexus encryption credentials (no prompt)" ) { 'behappy' }
111
+ @command.execute
112
+ assert_equal( File.read( @with + ".config" ),
113
+ File.read( @from + ".config" ) )
114
+ assert_equal( File.read( @with + ".secrets" ) != File.read( @from + ".secrets" ), true )
115
+
116
+ @command.options.delete( :nexus_encrypt )
117
+ mock(@command).send_gem
118
+ @command.execute
119
+ assert_equal @command.authorization != /^Basic /, true
120
+ assert_received(@command) { |command| command.send_gem }
121
+ end
122
+
123
+ should "without secrets file" do
124
+ @command.options[ :nexus_config ] = @with
125
+ @command.options[ :nexus_encrypt ] = false
126
+ mock(@command).ask( "Enter your Nexus encryption credentials (no prompt)" ) { 'behappy' }
127
+ @command.execute
128
+ assert_equal( File.read( @with ) != File.read( @from ), true )
129
+
130
+ @command.options.delete( :nexus_encrypt )
131
+ mock(@command).send_gem
132
+ @command.execute
133
+ assert_equal @command.authorization != /^Basic /, true
134
+ assert_received(@command) { |command| command.send_gem }
135
+ end
136
+ end
137
+
138
+ context "clear credentials" do
139
+ setup do
140
+ @command = Gem::Commands::NexusCommand.new
141
+ @with = File.join( 'pkg', 'clearcredentials' )
142
+ from = File.join( 'test', 'clearcredentials' )
143
+ [ ".config", ".secrets" ].each do |postfix|
144
+ FileUtils.cp( from + postfix, @with + postfix )
145
+ end
146
+
147
+ FileUtils.cp( from, @with )
148
+ end
149
+
150
+ should "with secrets file" do
151
+ @command.options[ :nexus_config ] = @with + ".config"
152
+ @command.options[ :nexus_clear_all ] = true
153
+ mock(@command).ask( 'delete all current credentials ? (y/N)' ){ 'y' }
154
+ @command.execute
155
+ assert_equal( File.exists?( @with + ".config" ), true )
156
+ assert_equal( File.exists?( @with + ".secrets" ), false )
157
+
158
+ @command.options.delete( :nexus_clear_all )
159
+ mock(@command).sign_in
160
+ mock(@command).send_gem
161
+ @command.execute
162
+ assert_received(@command) { |command| command.sign_in }
163
+ assert_received(@command) { |command| command.send_gem }
164
+ end
165
+
166
+ should "without secrets file" do
167
+ @command.options[ :nexus_config ] = @with
168
+ @command.options[ :nexus_clear_all ] = true
169
+ mock(@command).ask( 'delete all current credentials ? (y/N)' ){ 'y' }
170
+ @command.execute
171
+
172
+ @command.options.delete( :nexus_clear_all )
173
+ mock(@command).sign_in
174
+ mock(@command).send_gem
175
+ @command.execute
176
+ assert_received(@command) { |command| command.sign_in }
177
+ assert_received(@command) { |command| command.send_gem }
178
+ end
179
+ end
180
+
181
+ context "secrets file" do
182
+ setup do
183
+ @command = Gem::Commands::NexusCommand.new
184
+ @with = File.join( 'pkg', 'secretsfile' )
185
+ from = File.join( 'test', 'secretsfile' )
186
+ [ ".config", ".secrets" ].each do |postfix|
187
+ FileUtils.cp( from + postfix, @with + postfix )
188
+ end
189
+
190
+ FileUtils.cp( from, @with )
191
+ end
192
+
193
+ should "delete secrets file" do
194
+ @command.options[ :nexus_config ] = @with + ".config"
195
+ @command.options[ :nexus_secrets ] = false
196
+ @command.execute
197
+ assert_equal( File.exists?( @with + ".secrets" ), false )
198
+
199
+ @command.options.delete( :nexus_secrets )
200
+ mock(@command).send_gem
201
+ @command.execute
202
+ assert_received(@command) { |command| command.send_gem }
203
+ end
204
+
205
+ should "create secrets file" do
206
+ @command.options[ :nexus_config ] = @with
207
+ @command.options[ :nexus_secrets ] = @with + '.newsecrets'
208
+ @command.execute
209
+ assert_equal( File.exists?( @with + ".newsecrets" ), true )
210
+
211
+ @command.options.delete( :nexus_secrets )
212
+ mock(@command).send_gem
213
+ @command.execute
214
+ assert_received(@command) { |command| command.send_gem }
215
+ end
216
+
217
+ should "move secrets file" do
218
+ @command.options[ :nexus_config ] = @with + ".config"
219
+ @command.options[ :nexus_secrets ] = @with + '.newsecrets'
220
+ @command.execute
221
+ assert_equal( File.exists?( @with + ".secrets" ), false )
222
+ assert_equal( File.exists?( @with + ".newsecrets" ), true )
223
+
224
+ @command.options.delete( :nexus_secrets )
225
+ mock(@command).send_gem
226
+ @command.execute
227
+ assert_received(@command) { |command| command.send_gem }
228
+ end
229
+ end
230
+
231
+ context "always prompt" do
232
+ setup do
233
+ @command = Gem::Commands::NexusCommand.new
234
+ config = File.join( 'pkg', 'alwayspromptconfig' )
235
+ FileUtils.cp( File.join( 'test', 'alwayspromptconfig' ),
236
+ config )
237
+ @command.options[ :nexus_config ] = config
238
+ end
239
+
240
+ should "prompt" do
241
+ mock(@command).sign_in
242
+ mock(@command).send_gem
243
+ @command.execute
244
+ assert_received(@command) { |command| command.sign_in }
245
+ assert_received(@command) { |command| command.send_gem }
246
+ end
247
+
248
+ should "prompt with repo" do
249
+ @command.options[ :repo ] = 'hosted'
250
+ mock(@command).sign_in
251
+ mock(@command).send_gem
252
+ @command.execute
253
+ assert_received(@command) { |command| command.sign_in }
254
+ assert_received(@command) { |command| command.send_gem }
255
+ end
256
+
257
+ should "not prompt" do
258
+ @command.options[ :nexus_prompt_all ] = false
259
+ mock(@command).say "setup nexus to store username/passwords"
260
+ @command.execute
261
+ @command.options.delete( :nexus_prompt_all )
262
+ @command.config.authorization = 'asd'
263
+ mock(@command).send_gem
264
+ @command.execute
265
+ assert_received(@command) { |command| command.send_gem }
266
+ end
267
+ end
268
+
269
+ context "pushing" do
270
+ setup do
271
+ @command = Gem::Commands::NexusCommand.new
272
+ stub(@command).say
273
+ end
274
+
275
+ should "setup and send the gem" do
276
+ mock(@command).setup
277
+ mock(@command).send_gem
278
+ @command.execute
279
+ assert_received(@command) { |command| command.setup }
280
+ assert_received(@command) { |command| command.send_gem }
281
+ end
282
+
283
+ should "raise an error with no arguments" do
284
+ assert_raise Gem::CommandLineError do
285
+ @command.send_gem
286
+ end
287
+ end
288
+
289
+ context "pushing a gem" do
290
+ setup do
291
+
292
+ @gem_path = "path/to/foo-0.0.0.gem"
293
+ baseurl = 'http://localhost:8081/nexus/content/repositories/localgems'
294
+ @url = baseurl + @gem_path.sub(/.*\//, '/gems/')
295
+ @gem_binary = StringIO.new("gem")
296
+
297
+ stub(@command).say
298
+ stub(@command).options { {:args => [@gem_path]} }
299
+ stub(Gem).read_binary(@gem_path) { @gem_binary }
300
+ stub(@command).config do
301
+ obj = Object.new
302
+ def obj.authorization; "key"; end
303
+ def obj.url; 'http://localhost:8081/nexus/content/repositories/localgems'; end
304
+ obj
305
+ end
306
+ stub_request(:put, @url).to_return(:status => 201)
307
+ @command.send_gem
308
+ end
309
+
310
+ should "say push was successful" do
311
+ assert_received(@command) { |command| command.say("Uploading 1 gem to Nexus...") }
312
+ # due to webmock there is no status message
313
+ assert_received(@command) { |command| command.say(" foo-0.0.0.gem") }
314
+ end
315
+
316
+ should "put to api" do
317
+ # webmock doesn't pass body params on correctly :[
318
+ assert_requested(:put, @url,
319
+ :times => 1)
320
+ assert_requested(:put, @url,
321
+ :body => @gem_binary,
322
+ :headers => {
323
+ 'Authorization' => 'key',
324
+ 'Content-Type' => 'application/octet-stream'
325
+ })
326
+ end
327
+
328
+ context "non-successful push" do
329
+ should "say something went wrong - maybe (re)deployment is not allowed when receiving a 400 reponse" do
330
+ stub_request(:put, @url).to_return(:status => 400)
331
+ begin
332
+ @command.send_gem
333
+ rescue SystemExit => e
334
+ @exit_code = e.status
335
+ msg = "something went wrong - maybe (re)deployment is not allowed"
336
+ assert_received(@command) { |command| command.say(msg) }
337
+ assert_equal 1, @exit_code
338
+ end
339
+ end
340
+
341
+ should "say unauthorized when receiving a 401 response" do
342
+ stub_request(:put, @url).to_return(:status => 401)
343
+ begin
344
+ @command.send_gem
345
+ rescue SystemExit => e
346
+ @exit_code = e.status
347
+ assert_received(@command) { |command| command.say("Unauthorized") }
348
+ assert_equal 1, @exit_code
349
+ end
350
+ end
351
+
352
+ should "say something went wrong when receiving a 500 response" do
353
+ stub_request(:put, @url).to_return(:status => 500)
354
+ begin
355
+ @exit_code = @command.send_gem
356
+ rescue SystemExit => e
357
+ @exit_code = e.status
358
+ assert_received(@command) { |command| command.say("something went wrong") }
359
+ assert_equal 1, @exit_code
360
+ end
361
+ end
362
+ end
363
+ end
364
+ end
365
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nexus-debug
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Nick
8
+ - Quaranto
9
+ - Christian
10
+ - Meier
11
+ - Torben
12
+ - Carstens
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+ date: 2021-09-21 00:00:00.000000000 Z
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: rake
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - "~>"
23
+ - !ruby/object:Gem::Version
24
+ version: '10.1'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - "~>"
30
+ - !ruby/object:Gem::Version
31
+ version: '10.1'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rr
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '1.1'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '1.1'
46
+ - !ruby/object:Gem::Dependency
47
+ name: shoulda
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '3.1'
53
+ type: :development
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '3.1'
60
+ - !ruby/object:Gem::Dependency
61
+ name: activesupport
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '='
65
+ - !ruby/object:Gem::Version
66
+ version: 4.0.13
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '='
72
+ - !ruby/object:Gem::Version
73
+ version: 4.0.13
74
+ - !ruby/object:Gem::Dependency
75
+ name: addressable
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '2.4'
81
+ type: :development
82
+ prerelease: false
83
+ version_requirements: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '2.4'
88
+ - !ruby/object:Gem::Dependency
89
+ name: webmock
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '1.8'
95
+ - - "<"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.16'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.8'
105
+ - - "<"
106
+ - !ruby/object:Gem::Version
107
+ version: '1.16'
108
+ description: Adds a command to RubyGems for uploading gems to a nexus server.
109
+ email:
110
+ - nick@quaran.to
111
+ - m.kristian@web.de
112
+ - rubygems@carstens.tech
113
+ executables:
114
+ - nbundle
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - MIT-LICENSE
119
+ - Rakefile
120
+ - bin/nbundle
121
+ - lib/commands/abstract_command.rb
122
+ - lib/commands/nexus.rb
123
+ - lib/nexus/cipher.rb
124
+ - lib/nexus/config.rb
125
+ - lib/nexus/config_file.rb
126
+ - lib/nexus/version.rb
127
+ - lib/rubygems_plugin.rb
128
+ - test/abstract_command_test.rb
129
+ - test/cipher_test.rb
130
+ - test/command_helper.rb
131
+ - test/config_test.rb
132
+ - test/configfile_test.rb
133
+ - test/nexus_command_test.rb
134
+ homepage: https://github.com/torbencarstens/nexus-gem
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubygems_version: 3.2.22
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Gem Command to interact with Nexus server
157
+ test_files: []