-
Notifications
You must be signed in to change notification settings - Fork 2
/
with_creteinfobase_example.rb
419 lines (329 loc) · 14.4 KB
/
with_creteinfobase_example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
require 'example_helper'
module Examples
module TroublesWithCreateFileinfobase
describe "CREATEINFOBASE doesn't check self argument for valid connection string" do
extend AssLauncher::Api
# 1C:Enterprise thick client runned in CREATEINFOBASE mode
# not veryfies self argument for valid connection string and
# creates default infobase in user profile directory.
# It's buf or feature? I'm suppose it's bug.
conns = cs_file file: File.join(Dir.tmpdir, 'create_default_infobase.ib')
it 'Creates default infobase in user profile' do
command = CLIENTS::THICK.command :createinfobase do
connection_string conns
end
command.args.insert(1, '/L','en')
command.args[0].must_equal 'CREATEINFOBASE'
# Argument for CREATEINFOBASE is /L
command.args[1].must_equal '/L'
command.args[2].must_equal 'en'
# Nex is connection string
command.args[3].must_equal conns.createinfobase_args[0]
skip unless TROUBLES_EXECUTE_CONTROL::SHOW_TROBLES_WITH_CREATEINFOBASE
command.run.wait
# Infobase which we want not exists
File.exist?(conns.file).must_equal false
# But created infobase which we don't want
skip 'It fixed from 1C:Enterprise 8.3.10'
command.process_holder.result.success?.must_equal true
command.process_holder.result.assout =~\
/Creation of infobase \("File\s?=\s?"([^"]+)/i
created = Regexp.last_match[1]
created.must_match(/InfoBase\D?/i)
File.exist?(created).must_equal true
end
it 'Creates infobase which we want' do
command = CLIENTS::THICK.command :createinfobase do
connection_string conns
_L 'en'
end
command.args[0].must_equal 'CREATEINFOBASE'
# Argument for CREATEINFOBASE is connection string
command.args[1].must_equal conns.createinfobase_args[0]
# Nex is other
command.args[2].must_equal '/L'
command.args[3].must_equal 'en'
command.run.wait
# Created infobase which we want
command.process_holder.result.success?.must_equal true
command.process_holder.result.assout =~\
/Creation of infobase \("File\s?=\s?'([^']+)/i
created = Regexp.last_match[1]
command.args[1].must_include created
File.exist?(conns.file).must_equal true
end
after do
FileUtils.rm_rf conns.file if File.exist? conns.file
end
describe 'Solution with AssLauncher' do
it 'ThckClient verifies of argument for CREATEINFOBASE mode' do
e = proc {
CLIENTS::THICK.command(:createinfobase, ['bad connection srtring'])
}.must_raise ArgumentError
e.message.must_match(
/:createinfobase expects file or server connection string/i
)
end
end
end
describe 'CREATEINFOBASE fails if file connection string having double quote' do
infobasedir = File.join(Dir.tmpdir,
'example_connection_string_with_double_quote.ib')
infobasedir = AssLauncher::Support::Platforms\
.path(infobasedir).win_string
before do
FileUtils.rm_rf infobasedir if File.exist? infobasedir
end
it "Fails if connection string double quoted" do
skip 'It fixed from 1C:Enterprise 8.3.10'
conns = "File=\"#{infobasedir}\""
# Path like C:\tempdir\infobase
infobasedir.wont_match(/\//)
# Double quoted path
conns.must_match(/File="(.+)"/i)
command = CLIENTS::THICK.command :createinfobase,
[conns, '/L', 'en']
command.run.wait
command.process_holder.result.exitstatus.wont_equal 0
command.process_holder.result.assout.must_match(
/Invalid path to file '1Cv8\.cdn'/i)
end
it 'Solution with ConnectionString::File' do
# ConnectionString::File converts connection string
# for CREATEINFOBASE mode from double quoted:
# 'File="pat";' to single quoted: "File='path';" string
extend AssLauncher::Api
conns = cs("File=\"#{infobasedir}\"")
# Like File='path'
conns.createinfobase_args[0].must_match(/File\s?=\s?'[^']+/)
command = CLIENTS::THICK.command :createinfobase,
conns.createinfobase_args + ['/L', 'en']
command.run.wait
# Created infobase which we want
command.process_holder.result.success?.must_equal true
command.process_holder.result.assout =~\
/Creation of infobase \("File\s?=\s?'([^']+)/i
created = Regexp.last_match[1]
conns.file.must_equal created
File.exist?(conns.file).must_equal true
end
after do
FileUtils.rm_rf infobasedir if File.exist? infobasedir
end
end
describe "CREATEINFOBASE doesn't understand paths with right slashes" do
# This case doesn't actual in Linux
infobasedir = File.join(Dir.tmpdir,
'example_create_infobase_with_right_slashes.ib')
before do
FileUtils.rm_rf infobasedir if File.exist? infobasedir
end
describe 'Using single quote in connection string' do
conns = "File=\'#{infobasedir}\'"
it 'Fails CREATEINFOBASE' do
skip 'It fixed from 1C:Enterprise 8.3.10'
skip 'Not actual in Linux' if PLATFORM::LINUX
command = CLIENTS::THICK.command :createinfobase,
[conns, '/L', 'en']
command.run.wait
command.process_holder.result.success?.must_equal false
command.process_holder.result.assout.must_match(
/Invalid or missing parameters for connection to the Infobase/i)
end
end
describe 'Using double quote in connection string' do
conns = "File=\"#{infobasedir}\""
it 'Infobase is created not where you need' do
skip 'Not actual in Linux' if PLATFORM::LINUX
# Path like C:/tempdir/infobase
infobasedir.wont_match(/\\/)
command = CLIENTS::THICK.command :createinfobase,
[conns, '/L', 'en']
# This command creates or finds existing infobase files like 1Cv8.1CD
# in a root of the file system.
# On the machine where i'm writing this test, infobase was
# created in root of drive C:!!!
skip unless TROUBLES_EXECUTE_CONTROL::SHOW_TROBLES_WITH_CREATEINFOBASE
command.run.wait
# Exit status and assout:
if command.process_holder.result.exitstatus == 0
# First run test: created new infobase in root filesystem
command.process_holder.result.assout.must_match(
/Creation of infobase \("File=\\;.+\) completed successfully/i)
else
skip 'It fixed from 1C:Enterprise 8.3.10'
# Next runs test: found infobase files in root the file system
command.process_holder.result.assout.must_match(
/The Infobase specified already exists/i)
end
# Realy infobase not exists
File.exist?(infobasedir).must_equal false
end
end
after do
FileUtils.rm_rf infobasedir if File.exist? infobasedir
end
end
describe "CREATEINFOBASE doesn't understand relative paths beginning from `..'" do
require 'pathname'
infobasedir = File.join('..',
'trouble_not_undersnant_relative_path.ib',
)
infobasedir = infobasedir.gsub('/','\\')\
describe 'Using single quoted connection string' do
it 'Infobase is created not where you need' do
conns = "File='#{infobasedir}'"
Pathname.new(infobasedir).relative?.must_equal true
command = CLIENTS::THICK.command :createinfobase,
[conns, '/L', 'en']
skip unless TROUBLES_EXECUTE_CONTROL::SHOW_TROBLES_WITH_CREATEINFOBASE
# This command creates or finds existing infobase
# in a current directory not a parent!.
command.run.wait
# Exit status and assout:
if command.process_holder.result.exitstatus == 0
# First run test: created new infobase in the current directory
skip 'It fixed from 1C:Enterprise 8.3.10'
command.process_holder.result.assout.must_match(
/Creation of infobase \("File='\.\.\\trouble_.+\) \S+ successfully/i)
else
# Next runs test: found infobase files in the current directory
command.process_holder.result.assout.must_match(
/The Infobase specified already exists/i)
end
# Realy infobase not exists
File.exist?(infobasedir).must_equal false
# Infobase created in the current directory created
File.exist?(infobasedir.gsub('..','.')).must_equal true
end
end
describe 'Using double quoted connection string' do
it "Fails if connection string double quoted" do
skip 'It fixed from 1C:Enterprise 8.3.10'
conns = "File=\"#{infobasedir}\""
Pathname.new(infobasedir).relative?.must_equal true
command = CLIENTS::THICK.command :createinfobase,
[conns, '/L', 'en']
command.run.wait
command.process_holder.result.exitstatus.wont_equal 0
command.process_holder.result.assout.must_match(
/Invalid path to file '1Cv8\.cdn'/i)
end
end
it 'Solution with ConnectionString::File' do
require 'pathname'
extend AssLauncher::Api
# ConnectionString::File converts relative path
# to absolute for CREATEINFOBASE argument
conns = cs_file file: infobasedir
Pathname.new(conns.file).relative?.must_equal true
newcs = cs(conns.createinfobase_args[0].tr('\'','"'))
Pathname.new(newcs.file).absolute?.must_equal true
end
after do
FileUtils.rm_rf infobasedir if File.exist? infobasedir
end
end
describe "CREATEINFOBASE doesn't understand paths having `-'" do
extend AssLauncher::Support::Platforms
root = FileUtils.mkdir_p(File.join(Dir.tmpdir,'trouble-create-infobase'))[0]
infobasedir = File.join(root, 'tmp.ib')
infobasedir = AssLauncher::Support::Platforms\
.path(infobasedir).win_string
describe 'Using single quoted connection' do
it 'Fails CREATEINFOBASE' do
skip 'It fixed from 1C:Enterprise 8.3.10'
extend AssLauncher::Api
File.exist?(root).must_equal true
conns = cs_file file: infobasedir
command = CLIENTS::THICK.command :createinfobase,
conns.createinfobase_args + ['/L', 'en']
command.run.wait
command.process_holder.result.success?.must_equal false
command.process_holder.result.assout.must_match(
/Invalid or missing parameters for connection to the Infobase/i)
end
end
describe 'Using double quoted connection string' do
it 'Infobase is created not where you need' do
File.exist?(root).must_equal true
conns = "File=\"#{infobasedir}\""
command = CLIENTS::THICK.command :createinfobase,
[conns, '/L', 'en']
# This command creates or finds existng infobase files like 1Cv8.1CD
# in a root of the file system.
# On the machine where i'm writing this test, infobase was
# created in root of drive C:!!!
skip unless TROUBLES_EXECUTE_CONTROL::SHOW_TROBLES_WITH_CREATEINFOBASE
command.run.wait
# Exit status and assout:
if command.process_holder.result.exitstatus == 0
# First run test: created new infobase in root filesystem
command.process_holder.result.assout.must_match(
/Creation of infobase \("File=\\;.+\) completed successfully/i)
else
skip 'It fixed from 1C:Enterprise 8.3.10'
# Next runs test: found infobase files in root of the file system
command.process_holder.result.assout.must_match(
/The Infobase specified already exists/i)
end
# Realy infobase not exists
File.exist?(infobasedir).must_equal false
end
end
before do
FileUtils.rm_rf infobasedir if File.exist? infobasedir
end
after do
FileUtils.rm_rf infobasedir if File.exist? infobasedir
end
end
describe "CREATEINFOBASE doesn't understand paths having spaces" do
extend AssLauncher::Support::Platforms
root = FileUtils.mkdir_p(File.join(Dir.tmpdir,'trouble create infobase'))[0]
infobasedir = File.join(root, 'tmp.ib')
infobasedir = AssLauncher::Support::Platforms\
.path(infobasedir).win_string
it 'Solution with ConnectionString::File' do
extend AssLauncher::Api
File.exist?(root).must_equal true
# ConnectionString::File converts connection string
# for CREATEINFOBASE mode from double quoted:
# 'File="pat";' to single quoted: "File='path';" string
conns = cs_file file: infobasedir
command = CLIENTS::THICK.command :createinfobase,
conns.createinfobase_args + ['/L', 'en']
command.run.wait
# Created infobase which we want
command.process_holder.result.success?.must_equal true
command.process_holder.result.assout =~\
/Creation of infobase \("File\s?=\s?'([^']+)/i
created = Regexp.last_match[1]
conns.file.must_equal created
File.exist?(conns.file).must_equal true
end
describe 'Using double quoted connection string' do
it 'Fails CREATEINFOBASE' do
File.exist?(root).must_equal true
conns = "File=\"#{infobasedir}\""
command = CLIENTS::THICK.command :createinfobase,
[conns, '/L', 'en']
# This command creates or finds existng infobase files like 1Cv8.1CD
# in a root of the file system.
# On the machine where i'm writing this test, infobase was
# created in root of drive C:!!!
command.run.wait
command.process_holder.result.success?.must_equal false
command.process_holder.result.assout.must_match(
/Invalid or missing parameters for connection to the Infobase/i)
end
end
before do
FileUtils.rm_rf infobasedir if File.exist? infobasedir
end
after do
FileUtils.rm_rf infobasedir if File.exist? infobasedir
end
end
end
end