dbi-dbrc 1.1.7-x86-mingw32 → 1.1.8-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/dbi-dbrc.gemspec +1 -1
- data/lib/dbi/dbrc.rb +309 -305
- data/test/test_dbi_dbrc.rb +184 -184
- metadata +3 -3
data/CHANGES
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== 1.1.8 - 7-Oct-2010
|
2
|
+
* Fixed a logic bug in the constructor that primarily affected MS Windows with
|
3
|
+
regards to determining the user's home directory.
|
4
|
+
|
1
5
|
== 1.1.7 - 6-Oct-2010
|
2
6
|
* More robust file decryption/encryption for MS Windows.
|
3
7
|
* Better platform checking for MS Windows.
|
data/dbi-dbrc.gemspec
CHANGED
data/lib/dbi/dbrc.rb
CHANGED
@@ -1,305 +1,309 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
require 'rubygems'
|
3
|
-
|
4
|
-
if Config::CONFIG['host_os'] =~ /mswin|msdos|win32|mingw|cygwin/i
|
5
|
-
require 'win32/dir'
|
6
|
-
require 'win32/file'
|
7
|
-
require 'win32/process'
|
8
|
-
end
|
9
|
-
|
10
|
-
require 'sys/admin'
|
11
|
-
|
12
|
-
# The DBI module serves as a namespace only.
|
13
|
-
module DBI
|
14
|
-
|
15
|
-
# The DBRC class encapsulates a database resource config file.
|
16
|
-
class DBRC
|
17
|
-
|
18
|
-
# This error is raised if anything fails trying to read the config file.
|
19
|
-
class Error < StandardError; end
|
20
|
-
|
21
|
-
# The version of the dbi-dbrc library
|
22
|
-
VERSION = '1.1.
|
23
|
-
|
24
|
-
@@windows = Config::CONFIG['host_os'] =~ /mswin|msdos|win32|mingw|cygwin/i
|
25
|
-
|
26
|
-
# The database or host to be connected to.
|
27
|
-
attr_accessor :database
|
28
|
-
|
29
|
-
# The user name used for the database or host connection.
|
30
|
-
attr_accessor :user
|
31
|
-
|
32
|
-
# The password associated with the database or host.
|
33
|
-
attr_accessor :password
|
34
|
-
|
35
|
-
# The driver associated with the database. This is used to internally to
|
36
|
-
# construct the DSN.
|
37
|
-
attr_accessor :driver
|
38
|
-
|
39
|
-
# Data source name, e.g. "dbi:OCI8:your_database".
|
40
|
-
attr_accessor :dsn
|
41
|
-
|
42
|
-
# The maximum number of reconnects a program should make before giving up.
|
43
|
-
attr_accessor :maximum_reconnects
|
44
|
-
|
45
|
-
# The timeout, in seconds, for each connection attempt.
|
46
|
-
attr_accessor :timeout
|
47
|
-
|
48
|
-
# The interval, in seconds, between each connection attempt.
|
49
|
-
attr_accessor :interval
|
50
|
-
|
51
|
-
# The directory where the .dbrc file is stored.
|
52
|
-
attr_accessor :dbrc_dir
|
53
|
-
|
54
|
-
# The full path to the .dbrc file.
|
55
|
-
attr_accessor :dbrc_file
|
56
|
-
|
57
|
-
# Returns a new DBI::DBRC object. The contents of the object depend on
|
58
|
-
# the arguments passed to the constructor. If only a database name is
|
59
|
-
# passed, then the first entry found in the .dbrc file that matches that
|
60
|
-
# database is parsed. If a user name is also included, then the first
|
61
|
-
# entry that matches both the database and user name is parsed.
|
62
|
-
#
|
63
|
-
# If a directory is passed as the third argument, then DBRC will look
|
64
|
-
# in that directory, instead of the default directory, for the .dbrc
|
65
|
-
# file.
|
66
|
-
#
|
67
|
-
# If an entry cannot be found for the database, or database plus user
|
68
|
-
# combination, then a Error is raised. If the .dbrc file cannot be
|
69
|
-
# found, or is setup improperly with regards to permissions or properties
|
70
|
-
# then a DBI::DBRC::Error is raised.
|
71
|
-
#
|
72
|
-
# See the README for the rules regarding .dbrc files and permissions.
|
73
|
-
#
|
74
|
-
# Note that this library can also be used as a general password
|
75
|
-
# storage mechanism. In that case simply treat the 'database' as the
|
76
|
-
# host name, and ignore the DBI::DBRC#dsn and DBI::DBRC#driver methods.
|
77
|
-
#
|
78
|
-
# Examples:
|
79
|
-
#
|
80
|
-
# # Find the first match for 'some_database'
|
81
|
-
# DBI::DBRC.new('some_database')
|
82
|
-
#
|
83
|
-
# # Find the first match for 'foo_user@some_database'
|
84
|
-
# DBI::DBRC.new('some_database', 'foo_user')
|
85
|
-
#
|
86
|
-
# # Find the first match for 'foo_user@some_database' under /usr/local
|
87
|
-
# DBI::DBRC.new('some_database', 'foo_usr', '/usr/local')
|
88
|
-
#
|
89
|
-
def initialize(database, user=nil, dbrc_dir=nil)
|
90
|
-
if dbrc_dir.nil?
|
91
|
-
uid = Process.uid
|
92
|
-
home = ENV['HOME'] || ENV['USERPROFILE']
|
93
|
-
|
94
|
-
if home.nil?
|
95
|
-
if @@windows
|
96
|
-
home ||= Sys::Admin.get_user(uid, :localaccount => true).dir
|
97
|
-
else
|
98
|
-
home ||= Sys::Admin.get_user(uid).dir
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# Default to the app data directory on Windows
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
@
|
120
|
-
@
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
unless @
|
169
|
-
raise Error, "
|
170
|
-
end
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
unless (
|
196
|
-
raise Error, "
|
197
|
-
end
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
@user
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
@
|
225
|
-
@
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
alias_method(:
|
244
|
-
alias_method(:
|
245
|
-
alias_method(:
|
246
|
-
alias_method(:
|
247
|
-
alias_method(:
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
unless
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
@
|
295
|
-
@
|
296
|
-
@
|
297
|
-
@
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
if Config::CONFIG['host_os'] =~ /mswin|msdos|win32|mingw|cygwin/i
|
5
|
+
require 'win32/dir'
|
6
|
+
require 'win32/file'
|
7
|
+
require 'win32/process'
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'sys/admin'
|
11
|
+
|
12
|
+
# The DBI module serves as a namespace only.
|
13
|
+
module DBI
|
14
|
+
|
15
|
+
# The DBRC class encapsulates a database resource config file.
|
16
|
+
class DBRC
|
17
|
+
|
18
|
+
# This error is raised if anything fails trying to read the config file.
|
19
|
+
class Error < StandardError; end
|
20
|
+
|
21
|
+
# The version of the dbi-dbrc library
|
22
|
+
VERSION = '1.1.8'
|
23
|
+
|
24
|
+
@@windows = Config::CONFIG['host_os'] =~ /mswin|msdos|win32|mingw|cygwin/i
|
25
|
+
|
26
|
+
# The database or host to be connected to.
|
27
|
+
attr_accessor :database
|
28
|
+
|
29
|
+
# The user name used for the database or host connection.
|
30
|
+
attr_accessor :user
|
31
|
+
|
32
|
+
# The password associated with the database or host.
|
33
|
+
attr_accessor :password
|
34
|
+
|
35
|
+
# The driver associated with the database. This is used to internally to
|
36
|
+
# construct the DSN.
|
37
|
+
attr_accessor :driver
|
38
|
+
|
39
|
+
# Data source name, e.g. "dbi:OCI8:your_database".
|
40
|
+
attr_accessor :dsn
|
41
|
+
|
42
|
+
# The maximum number of reconnects a program should make before giving up.
|
43
|
+
attr_accessor :maximum_reconnects
|
44
|
+
|
45
|
+
# The timeout, in seconds, for each connection attempt.
|
46
|
+
attr_accessor :timeout
|
47
|
+
|
48
|
+
# The interval, in seconds, between each connection attempt.
|
49
|
+
attr_accessor :interval
|
50
|
+
|
51
|
+
# The directory where the .dbrc file is stored.
|
52
|
+
attr_accessor :dbrc_dir
|
53
|
+
|
54
|
+
# The full path to the .dbrc file.
|
55
|
+
attr_accessor :dbrc_file
|
56
|
+
|
57
|
+
# Returns a new DBI::DBRC object. The contents of the object depend on
|
58
|
+
# the arguments passed to the constructor. If only a database name is
|
59
|
+
# passed, then the first entry found in the .dbrc file that matches that
|
60
|
+
# database is parsed. If a user name is also included, then the first
|
61
|
+
# entry that matches both the database and user name is parsed.
|
62
|
+
#
|
63
|
+
# If a directory is passed as the third argument, then DBRC will look
|
64
|
+
# in that directory, instead of the default directory, for the .dbrc
|
65
|
+
# file.
|
66
|
+
#
|
67
|
+
# If an entry cannot be found for the database, or database plus user
|
68
|
+
# combination, then a Error is raised. If the .dbrc file cannot be
|
69
|
+
# found, or is setup improperly with regards to permissions or properties
|
70
|
+
# then a DBI::DBRC::Error is raised.
|
71
|
+
#
|
72
|
+
# See the README for the rules regarding .dbrc files and permissions.
|
73
|
+
#
|
74
|
+
# Note that this library can also be used as a general password
|
75
|
+
# storage mechanism. In that case simply treat the 'database' as the
|
76
|
+
# host name, and ignore the DBI::DBRC#dsn and DBI::DBRC#driver methods.
|
77
|
+
#
|
78
|
+
# Examples:
|
79
|
+
#
|
80
|
+
# # Find the first match for 'some_database'
|
81
|
+
# DBI::DBRC.new('some_database')
|
82
|
+
#
|
83
|
+
# # Find the first match for 'foo_user@some_database'
|
84
|
+
# DBI::DBRC.new('some_database', 'foo_user')
|
85
|
+
#
|
86
|
+
# # Find the first match for 'foo_user@some_database' under /usr/local
|
87
|
+
# DBI::DBRC.new('some_database', 'foo_usr', '/usr/local')
|
88
|
+
#
|
89
|
+
def initialize(database, user=nil, dbrc_dir=nil)
|
90
|
+
if dbrc_dir.nil?
|
91
|
+
uid = Process.uid
|
92
|
+
home = ENV['HOME'] || ENV['USERPROFILE']
|
93
|
+
|
94
|
+
if home.nil?
|
95
|
+
if @@windows
|
96
|
+
home ||= Sys::Admin.get_user(uid, :localaccount => true).dir
|
97
|
+
else
|
98
|
+
home ||= Sys::Admin.get_user(uid).dir
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# Default to the app data directory on Windows, or root on Unix, if
|
103
|
+
# no home dir can be found.
|
104
|
+
if home.nil?
|
105
|
+
if @@windows
|
106
|
+
home = Dir::APPDATA
|
107
|
+
else
|
108
|
+
home = '/'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
@dbrc_file = File.join(home, '.dbrc')
|
113
|
+
else
|
114
|
+
raise Error, 'bad directory' unless File.directory?(dbrc_dir)
|
115
|
+
@dbrc_file = File.join(dbrc_dir, '.dbrc')
|
116
|
+
end
|
117
|
+
|
118
|
+
@dbrc_dir = dbrc_dir
|
119
|
+
@database = database
|
120
|
+
@user = user
|
121
|
+
encrypted = false # Win32 only
|
122
|
+
|
123
|
+
@driver = nil
|
124
|
+
@interval = nil
|
125
|
+
@timeout = nil
|
126
|
+
@maximum_reconnects = nil
|
127
|
+
|
128
|
+
check_file()
|
129
|
+
|
130
|
+
# Decrypt and re-encrypt the file if we're on MS Windows and the
|
131
|
+
# file is encrypted.
|
132
|
+
begin
|
133
|
+
if @@windows && File.encrypted?(@dbrc_file)
|
134
|
+
file_was_encrypted = true
|
135
|
+
File.decrypt(@dbrc_file)
|
136
|
+
end
|
137
|
+
|
138
|
+
parse_dbrc_config_file()
|
139
|
+
validate_data()
|
140
|
+
convert_numeric_strings()
|
141
|
+
create_dsn_string()
|
142
|
+
ensure
|
143
|
+
if @@windows && file_was_encrypted
|
144
|
+
File.encrypt(@dbrc_file)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# Inspection of the DBI::DBRC object. This is identical to the standard
|
150
|
+
# Ruby Object#inspect, except that the password field is filtered.
|
151
|
+
#
|
152
|
+
def inspect
|
153
|
+
str = instance_variables.map{ |iv|
|
154
|
+
if iv == '@password'
|
155
|
+
"#{iv}=[FILTERED]"
|
156
|
+
else
|
157
|
+
"#{iv}=#{instance_variable_get(iv).inspect}"
|
158
|
+
end
|
159
|
+
}.join(', ')
|
160
|
+
|
161
|
+
"#<#{self.class}:0x#{(self.object_id*2).to_s(16)} " << str << ">"
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
# Ensure that the user/password has been set
|
167
|
+
def validate_data
|
168
|
+
unless @user
|
169
|
+
raise Error, "no user found associated with #{@database}"
|
170
|
+
end
|
171
|
+
|
172
|
+
unless @password
|
173
|
+
raise Error, "password not defined for #{@user}@#{@database}"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
# Converts strings that should be numbers into actual numbers
|
178
|
+
def convert_numeric_strings
|
179
|
+
@interval = @interval.to_i if @interval
|
180
|
+
@timeout = @timeout.to_i if @timeout
|
181
|
+
@maximum_reconnects = @maximum_reconnects.to_i if @maximum_reconnects
|
182
|
+
end
|
183
|
+
|
184
|
+
# Create the dsn string if the driver is defined
|
185
|
+
def create_dsn_string
|
186
|
+
@dsn = "dbi:#{@driver}:#{@database}" if @driver
|
187
|
+
end
|
188
|
+
|
189
|
+
# Check ownership and permissions
|
190
|
+
def check_file(file=@dbrc_file)
|
191
|
+
File.open(file){ |f|
|
192
|
+
# Permissions must be set to 600 or better on Unix systems.
|
193
|
+
# Must be hidden on Win32 systems.
|
194
|
+
if @@windows
|
195
|
+
unless File.hidden?(file)
|
196
|
+
raise Error, "The .dbrc file must be hidden"
|
197
|
+
end
|
198
|
+
else
|
199
|
+
unless (f.stat.mode & 077) == 0
|
200
|
+
raise Error, "Bad .dbrc file permissions"
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
# Only the owner may use it
|
205
|
+
unless f.stat.owned?
|
206
|
+
raise Error, "Not owner of .dbrc file"
|
207
|
+
end
|
208
|
+
}
|
209
|
+
end
|
210
|
+
|
211
|
+
# Parse the text out of the .dbrc file. This is the only method you
|
212
|
+
# need to redefine if writing your own config handler.
|
213
|
+
def parse_dbrc_config_file(file=@dbrc_file)
|
214
|
+
IO.foreach(file){ |line|
|
215
|
+
next if line =~ /^#/ # Ignore comments
|
216
|
+
db, user, pwd, driver, timeout, max, interval = line.split
|
217
|
+
|
218
|
+
next unless @database == db
|
219
|
+
|
220
|
+
if @user
|
221
|
+
next unless @user == user
|
222
|
+
end
|
223
|
+
|
224
|
+
@user = user
|
225
|
+
@password = pwd
|
226
|
+
@driver = driver
|
227
|
+
@timeout = timeout
|
228
|
+
@maximum_reconnects = max
|
229
|
+
@interval = interval
|
230
|
+
return
|
231
|
+
}
|
232
|
+
|
233
|
+
# If we reach here it means the database and/or user wasn't found
|
234
|
+
if @user
|
235
|
+
err = "no record found for #{@user}@#{@database}"
|
236
|
+
else
|
237
|
+
err = "no record found for #{@database}"
|
238
|
+
end
|
239
|
+
|
240
|
+
raise Error, err
|
241
|
+
end
|
242
|
+
|
243
|
+
alias_method(:db, :database)
|
244
|
+
alias_method(:db=, :database=)
|
245
|
+
alias_method(:passwd, :password)
|
246
|
+
alias_method(:passwd=, :password=)
|
247
|
+
alias_method(:max_reconn, :maximum_reconnects)
|
248
|
+
alias_method(:max_reconn=, :maximum_reconnects=)
|
249
|
+
alias_method(:time_out, :timeout)
|
250
|
+
alias_method(:time_out=, :timeout=)
|
251
|
+
alias_method(:host, :database)
|
252
|
+
end
|
253
|
+
|
254
|
+
# A subclass of DBRC designed to handle .dbrc files in XML format. The
|
255
|
+
# public methods of this class are identical to DBRC.
|
256
|
+
class XML < DBRC
|
257
|
+
require "rexml/document"
|
258
|
+
include REXML
|
259
|
+
|
260
|
+
private
|
261
|
+
|
262
|
+
def parse_dbrc_config_file(file=@dbrc_file)
|
263
|
+
doc = Document.new(File.new(file))
|
264
|
+
fields = %w/user password driver interval timeout maximum_reconnects/
|
265
|
+
doc.elements.each("/dbrc/database"){ |element|
|
266
|
+
next unless element.attributes["name"] == database
|
267
|
+
if @user
|
268
|
+
next unless element.elements["user"].text == @user
|
269
|
+
end
|
270
|
+
fields.each{ |field|
|
271
|
+
val = element.elements[field]
|
272
|
+
unless val.nil?
|
273
|
+
send("#{field}=",val.text)
|
274
|
+
end
|
275
|
+
}
|
276
|
+
return
|
277
|
+
}
|
278
|
+
# If we reach here it means the database and/or user wasn't found
|
279
|
+
raise Error, "No record found for #{@user}@#{@database}"
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
# A subclass of DBRC designed to handle .dbrc files in YAML format. The
|
284
|
+
# public methods of this class are identical to DBRC.
|
285
|
+
class YML < DBRC
|
286
|
+
require "yaml"
|
287
|
+
|
288
|
+
private
|
289
|
+
|
290
|
+
def parse_dbrc_config_file(file=@dbrc_file)
|
291
|
+
config = YAML.load(File.open(file))
|
292
|
+
config.each{ |hash|
|
293
|
+
hash.each{ |db,info|
|
294
|
+
next unless db == @database
|
295
|
+
next unless @user == info["user"] if @user
|
296
|
+
@user = info["user"]
|
297
|
+
@password = info["password"]
|
298
|
+
@driver = info["driver"]
|
299
|
+
@interval = info["interval"]
|
300
|
+
@timeout = info["timeout"]
|
301
|
+
@maximum_reconnects = info["max_reconn"]
|
302
|
+
return
|
303
|
+
}
|
304
|
+
}
|
305
|
+
# If we reach this point, it means the database wasn't found
|
306
|
+
raise Error, "No entry found for #{@user}@#{@database}"
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
data/test/test_dbi_dbrc.rb
CHANGED
@@ -12,190 +12,190 @@ require 'test/unit'
|
|
12
12
|
include DBI
|
13
13
|
|
14
14
|
class TC_DBI_DBRC < Test::Unit::TestCase
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
15
|
+
def self.startup
|
16
|
+
@@windows = File::ALT_SEPARATOR
|
17
|
+
end
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@dir = File.join(Dir.pwd, 'examples/plain')
|
21
|
+
@file = File.join(@dir, '.dbrc')
|
22
|
+
@db1 = 'foo'
|
23
|
+
@db2 = 'bar'
|
24
|
+
@user1 = 'user1'
|
25
|
+
@user2 = 'user2'
|
26
|
+
@db_bad = 'blah' # Doesn't exist
|
27
|
+
@user_bad = 'user8' # Doesn't exist
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
if @@windows && File.respond_to?(:set_attr)
|
30
|
+
File.set_attr(@file, File::HIDDEN)
|
31
|
+
else
|
32
|
+
File.chmod(0600, @file)
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
35
|
+
@dbrc = DBRC.new(@db1, nil, @dir)
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_version
|
39
|
+
assert_equal('1.1.8', DBRC::VERSION)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_bad_dbrc_properties
|
43
|
+
if @@windows
|
44
|
+
File.unset_attr(@file, File::HIDDEN)
|
45
|
+
assert_raises(DBRC::Error){ DBRC.new(@db1, @user1, @dir) }
|
46
|
+
else
|
47
|
+
File.chmod(0555,@file)
|
48
|
+
assert_raises(DBRC::Error){ DBRC.new(@db1, @user1, @dir) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_constructor
|
53
|
+
assert_raises(ArgumentError){ DBRC.new }
|
54
|
+
assert_nothing_raised{ DBRC.new(@db1, @user1, @dir) }
|
55
|
+
assert_nothing_raised{ DBRC.new(@db1, nil, @dir) }
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_bad_database
|
59
|
+
assert_raise(DBRC::Error){ DBRC.new(@db_bad, nil, @dir) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_bad_user
|
63
|
+
assert_raise(DBRC::Error){ DBRC.new(@db1, @user_bad, @dir) }
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_bad_dir
|
67
|
+
assert_raise(DBI::DBRC::Error){ DBI::DBRC.new(@db1, @user1, '/bogusXX') }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_database
|
71
|
+
assert_respond_to(@dbrc, :database)
|
72
|
+
assert_respond_to(@dbrc, :database=)
|
73
|
+
assert_respond_to(@dbrc, :db)
|
74
|
+
assert_respond_to(@dbrc, :db=)
|
75
|
+
assert_kind_of(String, @dbrc.db)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_host_alias
|
79
|
+
assert_respond_to(@dbrc, :host)
|
80
|
+
assert_equal(true, @dbrc.method(:host) == @dbrc.method(:database))
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_dbrc_dir
|
84
|
+
assert_respond_to(@dbrc, :dbrc_dir)
|
85
|
+
assert_equal(@dir, @dbrc.dbrc_dir)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_dbrc_file
|
89
|
+
assert_respond_to(@dbrc, :dbrc_file)
|
90
|
+
assert_equal('.dbrc', File.basename(@dbrc.dbrc_file))
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_dsn
|
94
|
+
assert_respond_to(@dbrc, :dsn)
|
95
|
+
assert_respond_to(@dbrc, :dsn=)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_user
|
99
|
+
assert_respond_to(@dbrc, :user)
|
100
|
+
assert_respond_to(@dbrc, :user=)
|
101
|
+
assert_kind_of(String, @dbrc.user)
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_password
|
105
|
+
assert_respond_to(@dbrc, :password)
|
106
|
+
assert_respond_to(@dbrc, :password=)
|
107
|
+
assert_respond_to(@dbrc, :passwd)
|
108
|
+
assert_respond_to(@dbrc, :passwd=)
|
109
|
+
assert_kind_of(String, @dbrc.password)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_driver
|
113
|
+
assert_respond_to(@dbrc, :driver)
|
114
|
+
assert_respond_to(@dbrc, :driver=)
|
115
|
+
assert_kind_of(String, @dbrc.driver)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_interval
|
119
|
+
assert_respond_to(@dbrc, :interval)
|
120
|
+
assert_respond_to(@dbrc, :interval=)
|
121
|
+
assert_kind_of(Fixnum, @dbrc.interval)
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_timeout
|
125
|
+
assert_respond_to(@dbrc, :timeout)
|
126
|
+
assert_respond_to(@dbrc, :timeout=)
|
127
|
+
assert_respond_to(@dbrc, :time_out)
|
128
|
+
assert_respond_to(@dbrc, :time_out=)
|
129
|
+
assert_kind_of(Fixnum, @dbrc.timeout)
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_max_reconn
|
133
|
+
assert_respond_to(@dbrc, :max_reconn)
|
134
|
+
assert_respond_to(@dbrc, :max_reconn=)
|
135
|
+
assert_respond_to(@dbrc, :maximum_reconnects)
|
136
|
+
assert_respond_to(@dbrc, :maximum_reconnects=)
|
137
|
+
assert_kind_of(Fixnum, @dbrc.maximum_reconnects)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_sample_values
|
141
|
+
assert_equal("foo", @dbrc.database)
|
142
|
+
assert_equal("user1", @dbrc.user)
|
143
|
+
assert_equal("pwd1", @dbrc.passwd)
|
144
|
+
assert_equal("Oracle", @dbrc.driver)
|
145
|
+
assert_equal(60, @dbrc.interval)
|
146
|
+
assert_equal(40, @dbrc.timeout)
|
147
|
+
assert_equal(3, @dbrc.max_reconn)
|
148
|
+
assert_equal("dbi:Oracle:foo", @dbrc.dsn)
|
149
|
+
end
|
150
|
+
|
151
|
+
# Same database, different user
|
152
|
+
def test_duplicate_database
|
153
|
+
db = DBRC.new("foo", "user2", @dir)
|
154
|
+
assert_equal("user2", db.user)
|
155
|
+
assert_equal("pwd2", db.passwd)
|
156
|
+
assert_equal("OCI8", db.driver)
|
157
|
+
assert_equal(60, db.interval)
|
158
|
+
assert_equal(60, db.timeout)
|
159
|
+
assert_equal(4, db.max_reconn)
|
160
|
+
assert_equal("dbi:OCI8:foo", db.dsn)
|
161
|
+
end
|
162
|
+
|
163
|
+
# Different database, different user
|
164
|
+
def test_different_database
|
165
|
+
db = DBRC.new("bar", "user1", @dir)
|
166
|
+
assert_equal("user1", db.user)
|
167
|
+
assert_equal("pwd3", db.passwd)
|
168
|
+
assert_equal("Oracle", db.driver)
|
169
|
+
assert_equal(30, db.interval)
|
170
|
+
assert_equal(30, db.timeout)
|
171
|
+
assert_equal(2, db.max_reconn)
|
172
|
+
assert_equal("dbi:Oracle:bar", db.dsn)
|
173
|
+
end
|
174
|
+
|
175
|
+
# A database with only a couple fields defined
|
176
|
+
def test_nil_values
|
177
|
+
db = DBRC.new("baz", "user3", @dir)
|
178
|
+
assert_equal("user3", db.user)
|
179
|
+
assert_equal("pwd4", db.passwd)
|
180
|
+
assert_nil(db.driver)
|
181
|
+
assert_nil(db.interval)
|
182
|
+
assert_nil(db.timeout)
|
183
|
+
assert_nil(db.max_reconn)
|
184
|
+
assert_nil(db.dsn)
|
185
|
+
end
|
186
|
+
|
187
|
+
def teardown
|
188
|
+
@dir = nil
|
189
|
+
@db1 = nil
|
190
|
+
@db2 = nil
|
191
|
+
@user1 = nil
|
192
|
+
@user2 = nil
|
193
|
+
@db_bad = nil
|
194
|
+
@user_bad = nil
|
195
|
+
@dbrc = nil
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.shutdown
|
199
|
+
@@windows = nil
|
200
|
+
end
|
201
201
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbi-dbrc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 8
|
10
|
+
version: 1.1.8
|
11
11
|
platform: x86-mingw32
|
12
12
|
authors:
|
13
13
|
- Daniel Berger
|