nexus-debug 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+ require 'rubygems/local_remote_options'
3
+ require 'net/http'
4
+ require 'base64'
5
+ require 'nexus/cipher'
6
+ require 'yaml'
7
+
8
+ module Nexus
9
+ class ConfigFile
10
+ def initialize(configfile)
11
+ raise 'no file given' unless configfile
12
+
13
+ @all = {}
14
+ if configfile.is_a?(String)
15
+ @file = configfile
16
+
17
+ if File.exist?(configfile)
18
+ @all = YAML.load(::File.read(configfile))
19
+ else
20
+ store # make sure we can write it
21
+ end
22
+ elsif configfile
23
+ @file = configfile.file
24
+ @all = configfile.all
25
+ end
26
+ end
27
+
28
+ attr_reader :all, :file
29
+
30
+ def data(repo)
31
+ if repo
32
+ (@all[repo] ||= {})
33
+ else
34
+ @all
35
+ end
36
+ end
37
+
38
+ def key?(key, repo = nil)
39
+ data(repo).key? key
40
+ end
41
+
42
+ def [](key, repo = nil)
43
+ data(repo)[key]
44
+ end
45
+
46
+ def []=(key, repo, value)
47
+ if value.nil?
48
+ data(repo).delete(key)
49
+ else
50
+ data(repo)[key] = value
51
+ end
52
+ end
53
+
54
+ def repos
55
+ all.collect do |k, v|
56
+ k if v.is_a? Hash
57
+ end.select { |s| s }
58
+ end
59
+
60
+ def section(key)
61
+ all.dup.select do |k, v|
62
+ if v.is_a? Hash
63
+ v.delete_if { |kk, _vv| kk != key }
64
+ else
65
+ k == key
66
+ end
67
+ end
68
+ end
69
+
70
+ def delete(*keys)
71
+ delete_map(all, *keys)
72
+ all.each do |_k, v|
73
+ delete_map(v, *keys) if v.is_a? Hash
74
+ end
75
+ end
76
+
77
+ def delete_map(map, *keys)
78
+ keys.each { |k| map.delete(k) }
79
+ end
80
+
81
+ private :delete_map
82
+
83
+ def merge!(other)
84
+ map = other.all
85
+ merge_map(@all, map)
86
+ end
87
+
88
+ def merge_map(m1, m2)
89
+ return m2 unless m1
90
+
91
+ m2.each do |k, v|
92
+ if v.is_a? Hash
93
+ m1[k] ||= {}
94
+ merge_map(m1[k], v)
95
+ else
96
+ m1[k] = v
97
+ end
98
+ end
99
+ end
100
+
101
+ private :merge_map
102
+
103
+ def store
104
+ dirname = File.dirname(@file)
105
+ Dir.mkdir(dirname) unless File.exist?(dirname)
106
+ new = !File.exist?(@file)
107
+
108
+ File.open(@file, 'w') do |f|
109
+ f.write @all.to_yaml
110
+ end
111
+ if new
112
+ begin
113
+ File.chmod(0o100600, @file)
114
+ rescue StandardError
115
+ nil
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,3 @@
1
+ module Nexus
2
+ VERSION = '1.4.0'.freeze
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems/command_manager'
2
+ require 'commands/abstract_command'
3
+
4
+ require "commands/nexus"
5
+ Gem::CommandManager.instance.register_command :nexus
6
+
@@ -0,0 +1,248 @@
1
+ require 'command_helper'
2
+
3
+ class Gem::Commands::FakeCommand < Gem::AbstractCommand
4
+ def description
5
+ 'fake command'
6
+ end
7
+
8
+ def initialize
9
+ super 'fake', description
10
+ end
11
+
12
+ def execute
13
+ end
14
+ end
15
+
16
+ class AbstractCommandTest < CommandTest
17
+
18
+ context "with an fake command" do
19
+ setup do
20
+ @command = Gem::Commands::FakeCommand.new
21
+ Gem.configuration.verbose = false
22
+ stub(@command).say
23
+ ENV['http_proxy'] = nil
24
+ ENV['HTTP_PROXY'] = nil
25
+ end
26
+
27
+ context "parsing the proxy" do
28
+ should "return nil if no proxy is set" do
29
+ stub_config(:http_proxy => nil)
30
+ assert_equal nil, @command.http_proxy( nil )
31
+ end
32
+
33
+ should "return nil if the proxy is set to :no_proxy" do
34
+ stub_config(:http_proxy => :no_proxy)
35
+ assert_equal nil, @command.http_proxy( 'asd' )
36
+ end
37
+
38
+ should "return a proxy as a URI if set" do
39
+ stub_config( :http_proxy => 'http://proxy.example.org:9192' )
40
+ assert_equal 'proxy.example.org', @command.http_proxy( 'http://asd' ).host
41
+ assert_equal 9192, @command.http_proxy( 'http://asd' ).port
42
+ end
43
+
44
+ should "return a proxy as a URI if set by environment variable" do
45
+ ENV['http_proxy'] = "http://jack:duck@192.168.1.100:9092"
46
+ assert_equal "192.168.1.100", @command.http_proxy( 'http://asd' ).host
47
+ assert_equal 9092, @command.http_proxy( 'http://asd' ).port
48
+ assert_equal "jack", @command.http_proxy( 'http://asd' ).user
49
+ assert_equal "duck", @command.http_proxy( 'http://asd' ).password
50
+ end
51
+ end
52
+
53
+ should "sign in if no authorization and no nexus url in config" do
54
+ config_path = File.join( 'pkg', 'configsomething')
55
+ FileUtils.rm_f( config_path )
56
+ @command.options[ :nexus_config ] = config_path
57
+ stub(@command).sign_in
58
+ stub(@command).configure_url
59
+ @command.setup
60
+ assert_received(@command) { |command| command.configure_url }
61
+ assert_received(@command) { |command| command.sign_in }
62
+ end
63
+
64
+ should "sign in if --clear-config is set" do
65
+ config_path = File.join( 'pkg', 'config_clear')
66
+ FileUtils.rm_f( config_path )
67
+ @command.options[ :nexus_config ] = config_path
68
+ stub(@command).sign_in
69
+ stub(@command).configure_url
70
+ stub(@command).options do
71
+ { :nexus_clear => true,
72
+ :nexus_config => config_path
73
+ }
74
+ end
75
+ @command.setup
76
+ assert_received(@command) { |command| command.sign_in }
77
+ assert_received(@command) { |command| command.configure_url }
78
+ end
79
+
80
+ should "sign in if --password is set" do
81
+ config_path = File.join( 'pkg', 'config_password')
82
+ File.open( config_path, 'w') do |f|
83
+ h = { :url => 'http://example.com' }
84
+ f.write h.to_yaml
85
+ end
86
+ @command.options[ :nexus_config ] = config_path
87
+ @command.options[ :nexus_prompt ] = true
88
+ stub(@command).sign_in
89
+ @command.setup
90
+ assert_received(@command) { |command| command.sign_in }
91
+ end
92
+
93
+
94
+ should "always return stored authorization and url" do
95
+ config_path = File.join( 'pkg', 'configsomething')
96
+ FileUtils.rm_f( config_path )
97
+ @command.options[ :nexus_config ] = config_path
98
+ @command.options[ :nexus_prompt ] = true
99
+ @command.config.url = 'something'
100
+ @command.config.authorization = 'something'
101
+ assert_not_nil @command.authorization
102
+ assert_not_nil @command.url
103
+ end
104
+
105
+ should "not sign in nor configure if authorizaton and url exists" do
106
+ config_path = File.join( 'pkg', 'configsomething')
107
+ FileUtils.rm_f( config_path )
108
+ @command.options[ :nexus_config ] = config_path
109
+ stub(@command).authorization { "1234567890" }
110
+ stub(@command).url { "abc" }
111
+ stub(@command).sign_in
112
+ stub(@command).configure_url
113
+ @command.setup
114
+ assert_received(@command) { |command| command.configure_url.never }
115
+ assert_received(@command) { |command| command.sign_in.never }
116
+ end
117
+
118
+ context "using the proxy" do
119
+ setup do
120
+ stub_config( :http_proxy => "http://gilbert:sekret@proxy.example.org:8081" )
121
+ @proxy_class = Object.new
122
+ mock(Net::HTTP).Proxy('proxy.example.org', 8081, 'gilbert', 'sekret') { @proxy_class }
123
+ @command.use_proxy!( 'http://asd' )
124
+ end
125
+
126
+ should "replace Net::HTTP with a proxy version" do
127
+ assert_equal @proxy_class, @command.proxy_class
128
+ end
129
+ end
130
+
131
+ context 'separeted config per repo key' do
132
+ should 'store the config on per key' do
133
+ config_path = File.join( 'pkg', 'configrepo')
134
+ FileUtils.rm_f( config_path )
135
+ @command.options[ :nexus_config ] = config_path
136
+ @command.options[ :nexus_repo ] = :first
137
+ @command.config.url = :thing
138
+ @command.options[ :nexus_repo ] = :second
139
+ @command.send :instance_variable_set, '@config'.to_sym, nil
140
+ @command.config.url = :otherthing
141
+ @command.options[ :nexus_repo ] = nil
142
+ @command.send :instance_variable_set, '@config'.to_sym, nil
143
+ @command.config.url = :nothing
144
+ assert_equal( Gem.configuration.load_file(config_path),
145
+ { :first => {:url => :thing},
146
+ :second => {:url => :otherthing},
147
+ :url => :nothing } )
148
+ end
149
+ end
150
+
151
+ context "clear username + password" do
152
+
153
+ should "clear stored authorization" do
154
+ stub(@command).options { {:nexus_config => File.join( 'pkg',
155
+ 'config') } }
156
+ stub(@command).say
157
+ stub(@command).ask { nil }
158
+ stub(@command).ask_for_password { nil }
159
+ @command.config.authorization = 'some authentication'
160
+
161
+ @command.sign_in
162
+ assert_nil @command.authorization
163
+ end
164
+ end
165
+
166
+ context "encryption" do
167
+
168
+ end
169
+
170
+ context "signing in" do
171
+ setup do
172
+ @username = "username"
173
+ @password = "password 01234567890123456789012345678901234567890123456789"
174
+ @key = "key"
175
+
176
+ stub(@command).say
177
+ stub(@command).ask { @username }
178
+ stub(@command).ask_for_password { @password }
179
+ stub(@command).options { {:nexus_config => File.join( 'pkg',
180
+ 'configsign') } }
181
+ @command.config.authorization = @key
182
+ end
183
+
184
+ should "ask for username and password" do
185
+ @command.sign_in
186
+ assert_received(@command) { |command| command.ask("Username: ") }
187
+ assert_received(@command) { |command| command.ask_for_password("Password: ") }
188
+ assert_equal( @command.config.authorization,
189
+ "Basic dXNlcm5hbWU6cGFzc3dvcmQgMDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODk=" )
190
+ end
191
+
192
+ should "say that we signed in" do
193
+ @command.sign_in
194
+ assert_received(@command) { |command| command.say("Enter your Nexus credentials") }
195
+ assert_received(@command) { |command| command.say("Your Nexus credentials have been stored in pkg/configsign") }
196
+ assert_equal( @command.config.authorization,
197
+ "Basic dXNlcm5hbWU6cGFzc3dvcmQgMDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODk=" )
198
+ end
199
+ end
200
+
201
+ context "configure nexus url" do
202
+ setup do
203
+ @url = "http://url"
204
+
205
+ stub(@command).say
206
+ stub(@command).ask { @url }
207
+ stub(@command).options { {:nexus_config => File.join( 'pkg',
208
+ 'configurl') } }
209
+ @command.config.url = @url
210
+ end
211
+
212
+ should "ask for nexus url" do
213
+ @command.configure_url
214
+ assert_received(@command) { |command| command.ask("URL: ") }
215
+ assert_equal( @command.config.url, "http://url" )
216
+ end
217
+
218
+ should "say that we configured the url" do
219
+ @command.configure_url
220
+ assert_received(@command) { |command| command.say("Enter the URL of the rubygems repository on a Nexus server") }
221
+ assert_received(@command) { |command| command.say("The Nexus URL has been stored in pkg/configurl") }
222
+ assert_equal( @command.config.url, "http://url" )
223
+ end
224
+ end
225
+
226
+ context "SSL verification" do
227
+ setup do
228
+ @url = "https://url"
229
+ @connection = Net::HTTP.new("host", 443)
230
+ stub(@connection).request
231
+ stub(Net::HTTP).new { @connection }
232
+ @command.config.url = @url
233
+ end
234
+
235
+ should "disable SSL verification" do
236
+ stub(@command.config).ssl_verify_mode { OpenSSL::SSL::VERIFY_NONE }
237
+ stub(Gem.configuration).verbose { 0 }
238
+ @command.make_request(:put, "gems/gem")
239
+ assert_equal( @connection.verify_mode, OpenSSL::SSL::VERIFY_NONE )
240
+ end
241
+
242
+ should "verify SSL" do
243
+ @command.make_request(:put, "gems/gem")
244
+ assert_equal( @connection.verify_mode, OpenSSL::SSL::VERIFY_PEER )
245
+ end
246
+ end
247
+ end
248
+ end
@@ -0,0 +1,68 @@
1
+ require 'minitest/autorun'
2
+ require 'shoulda'
3
+ require 'fileutils'
4
+ require 'nexus/cipher'
5
+
6
+ class ConfigTest < ::MiniTest::Unit::TestCase
7
+ include ShouldaContextLoadable
8
+
9
+ context 'no token' do
10
+
11
+ should 'create token' do
12
+ c = Nexus::Cipher.new( 'behappy' )
13
+ assert_equal( c.token.nil?, false )
14
+ assert_equal( c.iv.nil?, true )
15
+ end
16
+
17
+ should 'en/decrypt data' do
18
+ c = Nexus::Cipher.new( 'behappy' )
19
+ encrypted = c.encrypt( 'something' )
20
+ cc = Nexus::Cipher.new( 'behappy', c.token )
21
+ cc.iv = c.iv
22
+ plain = cc.decrypt( encrypted )
23
+
24
+ assert_equal( plain, 'something' )
25
+ end
26
+
27
+ should 'en/decrypt data using the same cipher' do
28
+ c = Nexus::Cipher.new( 'behappy' )
29
+ encrypted = c.encrypt( 'something' )
30
+ plain = c.decrypt( encrypted )
31
+
32
+ assert_equal( plain, 'something' )
33
+ end
34
+
35
+ end
36
+
37
+ context 'with token' do
38
+
39
+ should 'not create token' do
40
+ c = Nexus::Cipher.new( 'behappy',
41
+ "UvChT3jkwD7jXFd8mTWJ087i2Xb3tlGmPWUSYtAiRJM=" )
42
+ assert_equal( c.token, "UvChT3jkwD7jXFd8mTWJ087i2Xb3tlGmPWUSYtAiRJM=" )
43
+ assert_equal( c.iv.nil?, true )
44
+ end
45
+
46
+ should 'en/decrypt data' do
47
+ c = Nexus::Cipher.new( 'behappy',
48
+ "UvChT3jkwD7jXFd8mTWJ087i2Xb3tlGmPWUSYtAiRJM=" )
49
+ encrypted = c.encrypt( 'something' )
50
+ cc = Nexus::Cipher.new( 'behappy',
51
+ "UvChT3jkwD7jXFd8mTWJ087i2Xb3tlGmPWUSYtAiRJM=" )
52
+ cc.iv = c.iv
53
+ plain = cc.decrypt( encrypted )
54
+
55
+ assert_equal( plain, 'something' )
56
+ end
57
+
58
+ should 'en/decrypt data using the same cipher' do
59
+ c = Nexus::Cipher.new( 'behappy',
60
+ "UvChT3jkwD7jXFd8mTWJ087i2Xb3tlGmPWUSYtAiRJM=" )
61
+ encrypted = c.encrypt( 'something' )
62
+ plain = c.decrypt( encrypted )
63
+
64
+ assert_equal( plain, 'something' )
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,55 @@
1
+ require 'minitest/autorun'
2
+
3
+ require 'shoulda'
4
+
5
+ # for some reasons the refute_predicate is missing when executing
6
+ # via jruby-1.7.4
7
+ module ActiveSupport
8
+ class TestCase < ::MiniTest::Unit::TestCase
9
+ def refute_predicate
10
+ end
11
+ end
12
+ end
13
+
14
+ require 'active_support'
15
+ require 'active_support/test_case'
16
+ require 'webmock'
17
+ require 'rr'
18
+
19
+ begin
20
+ require 'redgreen'
21
+ rescue LoadError
22
+ end
23
+
24
+ WebMock.disable_net_connect!
25
+
26
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), ".."))
27
+
28
+ require "rubygems_plugin"
29
+
30
+ class CommandTest < ActiveSupport::TestCase
31
+ include WebMock::API
32
+ include ShouldaContextLoadable
33
+
34
+ def teardown
35
+ WebMock.reset!
36
+ end
37
+ end
38
+
39
+ def stub_config(config)
40
+ file = Gem::ConfigFile.new({})
41
+ config.each { |key, value| file[key] = value }
42
+ stub(Gem).configuration { config }
43
+ end
44
+
45
+ def assert_said(command, what)
46
+ assert_received(command) do |command|
47
+ command.say(what)
48
+ end
49
+ end
50
+
51
+ def assert_never_said(command, what)
52
+ assert_received(command) do |command|
53
+ command.say(what).never
54
+ end
55
+ end
@@ -0,0 +1,117 @@
1
+ require 'minitest/autorun'
2
+ require 'shoulda'
3
+ require 'fileutils'
4
+ require 'nexus/config'
5
+
6
+ class ConfigTest < ::MiniTest::Unit::TestCase
7
+ include ShouldaContextLoadable
8
+
9
+ context 'storing url and authorization' do
10
+
11
+ should 'with plain text file' do
12
+ file = File.join( 'pkg', 'plainconfig' )
13
+ FileUtils.rm_f file
14
+
15
+ repos = [ nil, 'first', 'second' ]
16
+
17
+ repos.each do |repo|
18
+ c = Nexus::Config.new( file, repo )
19
+ c.url = "http://example.com/#{repo}"
20
+ c.authorization = "BASIC asddsa#{repo}"
21
+
22
+ assert_equal c.authorization, "BASIC asddsa#{repo}"
23
+ assert_equal c.url, "http://example.com/#{repo}"
24
+ end
25
+
26
+ repos.each do |repo|
27
+ c = Nexus::Config.new( file, repo )
28
+ assert_equal c.authorization, "BASIC asddsa#{repo}"
29
+ assert_equal c.url, "http://example.com/#{repo}"
30
+ end
31
+
32
+ assert_equal( Nexus::Config.new( file ).repos,
33
+ { "first"=>"http://example.com/first",
34
+ "second"=>"http://example.com/second",
35
+ "DEFAULT"=>"http://example.com/"} )
36
+ end
37
+
38
+ end
39
+
40
+ context 'auxilary functions' do
41
+
42
+ should 'encrypt and decrypt credentials' do
43
+ file = File.join( 'pkg', 'auxconfig' )
44
+ FileUtils.rm_f file
45
+
46
+ [ nil, 'key' ].each do |repo|
47
+ c = Nexus::Config.new( file, repo )
48
+ c.authorization = 'BASIC asddsa'
49
+
50
+ assert_equal c.authorization, 'BASIC asddsa'
51
+
52
+ cc = Nexus::Config.new( file, repo )
53
+ cc.password = 'be happy'
54
+ cc.encrypt_credentials
55
+
56
+ assert_equal cc.authorization, 'BASIC asddsa'
57
+
58
+ ccc = Nexus::Config.new( file, repo )
59
+ ccc.password = 'be happy'
60
+ assert_equal ccc.authorization, 'BASIC asddsa'
61
+ assert_equal ccc.send( :[], :iv ), cc.send( :[], :iv )
62
+
63
+ cc.decrypt_credentials
64
+
65
+ assert_equal cc.authorization, 'BASIC asddsa'
66
+
67
+ ccc = Nexus::Config.new( file, repo )
68
+
69
+ assert_equal ccc.authorization , 'BASIC asddsa'
70
+ assert_equal ccc.send( :[], :iv ), nil
71
+ assert_equal ccc.send( :[], :token ), nil
72
+ end
73
+ end
74
+
75
+ should 'move credentials to secrets file' do
76
+ file = File.join( 'pkg', 'auxcfg' )
77
+ sfile = File.join( 'pkg', 'auxsrt' )
78
+ FileUtils.rm_f file
79
+ FileUtils.rm_f sfile
80
+
81
+ repos = [ nil, 'first', 'second' ]
82
+
83
+ repos.each do |repo|
84
+ c = Nexus::Config.new( file, repo )
85
+ c.url = "http://example.com/#{repo}"
86
+ c.authorization = "BASIC asddsa#{repo}"
87
+ end
88
+
89
+ Nexus::Config.new( file ).new_secrets( sfile )
90
+ assert File.exists?( sfile ), true
91
+
92
+ repos.each do |repo|
93
+ c = Nexus::Config.new( sfile, repo )
94
+ assert_equal c.url, nil
95
+ assert_equal c.authorization, "BASIC asddsa#{repo}"
96
+ end
97
+
98
+ c = Nexus::ConfigFile.new( file )
99
+ assert_equal c[ :authorization, nil ], nil
100
+ assert_equal c[ :secrets, nil ], sfile
101
+
102
+ repos.each do |repo|
103
+ c = Nexus::ConfigFile.new( file )
104
+ assert_equal c[ :url, repo ], "http://example.com/#{repo}"
105
+ end
106
+
107
+ Nexus::Config.new( file ).new_secrets( nil )
108
+ assert_equal File.exists?( sfile ), false
109
+
110
+ repos.each do |repo|
111
+ c = Nexus::Config.new( file, repo )
112
+ assert_equal c.url, "http://example.com/#{repo}"
113
+ assert_equal c.authorization, "BASIC asddsa#{repo}"
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,78 @@
1
+ require 'minitest/autorun'
2
+ require 'shoulda'
3
+ require 'fileutils'
4
+ require 'nexus/config_file'
5
+
6
+ class ConfigTest < ::MiniTest::Unit::TestCase
7
+ include ShouldaContextLoadable
8
+
9
+ context 'file' do
10
+
11
+ should 'store key/values' do
12
+ file = File.join( 'pkg', 'cfg' )
13
+ FileUtils.rm_f file
14
+ f = Nexus::ConfigFile.new( file )
15
+ f[ 'asd_key', nil ] = 'dsa_value'
16
+ f[ 'asdasd_key', nil ] = 'dsa_value_dsa'
17
+ f[ 'asd_key', 'first' ] = 'dsa_value_dsa'
18
+ f[ 'asdasd_key', 'first' ] = 'dsadsa_value'
19
+
20
+ assert_equal( f[ 'asd_key', nil ], 'dsa_value' )
21
+ assert_equal( f[ 'asdasd_key', 'first' ], 'dsadsa_value' )
22
+
23
+ f.store
24
+
25
+ assert_equal( f.all, Nexus::ConfigFile.new( file ).all )
26
+ assert_equal( f.repos, [ 'first' ] )
27
+
28
+ assert_equal( f.section( 'asd_key' ),
29
+ { "asd_key"=>"dsa_value",
30
+ "first"=>{"asd_key"=>"dsa_value_dsa"} } )
31
+ end
32
+
33
+ should 'delete key/values' do
34
+ file = File.join( 'pkg', 'cfg' )
35
+ FileUtils.rm_f file
36
+ f = Nexus::ConfigFile.new( file )
37
+ f[ 'asd_key', nil ] = 'dsa_value'
38
+ f[ 'asdasd_key', nil ] = 'dsa_value_dsa'
39
+ f[ 'asd_key', 'first' ] = 'dsa_value_dsa'
40
+ f[ 'asdasd_key', 'first' ] = 'dsadsa_value'
41
+
42
+ assert_equal( f[ 'asd_key', nil ], 'dsa_value' )
43
+ assert_equal( f[ 'asdasd_key', 'first' ], 'dsadsa_value' )
44
+
45
+ f.delete( 'asd_key' )
46
+
47
+ assert_equal( f[ 'asd_key', nil ], nil )
48
+ assert_equal( f[ 'asd_key', 'first' ], nil )
49
+ assert_equal( f[ 'asdasd_key', nil ], 'dsa_value_dsa' )
50
+ assert_equal( f[ 'asdasd_key', 'first' ], 'dsadsa_value' )
51
+ end
52
+
53
+ should 'merge other file' do
54
+ file1 = File.join( 'pkg', 'cfg1' )
55
+ file2 = File.join( 'pkg', 'cfg2' )
56
+ FileUtils.rm_f file1
57
+ FileUtils.rm_f file2
58
+ f1 = Nexus::ConfigFile.new( file1 )
59
+ f2 = Nexus::ConfigFile.new( file2 )
60
+
61
+ assert_equal( f1.all, {} )
62
+
63
+ f2[ 'asd_key', nil ] = 'dsa_value'
64
+ f2[ 'asdasd_key', 'first' ] = 'dsadsa_value'
65
+
66
+ f1.merge!( f2 )
67
+
68
+ assert_equal( f1[ 'asd_key', nil ], 'dsa_value' )
69
+ assert_equal( f1[ 'asdasd_key', 'first' ], 'dsadsa_value' )
70
+
71
+ f1.store
72
+ f2.store
73
+
74
+ assert_equal( Nexus::ConfigFile.new( file1 ).all,
75
+ Nexus::ConfigFile.new( file2 ).all )
76
+ end
77
+ end
78
+ end