el_finder 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,23 +1,8 @@
1
- require 'test/unit'
2
- require 'el_finder'
3
- require 'pp'
1
+ require 'el_finder_test_case'
4
2
 
5
3
  class TestElFinder < Test::Unit::TestCase
6
4
 
7
- def setup
8
- @vroot = '/tmp/elfinder'
9
- FileUtils.mkdir_p(@vroot)
10
- FileUtils.cp_r "#{File.dirname(__FILE__)}/files/.", @vroot
11
- @elfinder = ElFinder::Connector.new({
12
- :root => @vroot,
13
- :url => '/elfinder',
14
- :original_filename_method => lambda {|file| File.basename(file.path)}
15
- })
16
- end
17
-
18
- def teardown
19
- FileUtils.rm_rf(@vroot)
20
- end
5
+ include ElFinderTestCase
21
6
 
22
7
  ################################################################################
23
8
 
@@ -62,18 +47,6 @@ class TestElFinder < Test::Unit::TestCase
62
47
 
63
48
  ################################################################################
64
49
 
65
- def test_to_hash_method
66
- assert_equal Base64.encode64('foo/bar').chomp, @elfinder.to_hash(ElFinder::Pathname.new_with_root(@vroot, 'foo/bar'))
67
- assert_equal Base64.encode64('/').chomp, @elfinder.to_hash(ElFinder::Pathname.new_with_root(@vroot))
68
- end
69
-
70
- def test_from_hash_method
71
- assert_equal File.join(@vroot, 'foo/bar'), @elfinder.from_hash(Base64.encode64('foo/bar').chomp).to_s
72
- assert_equal @vroot, @elfinder.from_hash(Base64.encode64('').chomp).to_s
73
- end
74
-
75
- ################################################################################
76
-
77
50
  def test_init_via_open
78
51
  h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
79
52
  assert_not_nil r[:cwd]
@@ -254,367 +227,4 @@ class TestElFinder < Test::Unit::TestCase
254
227
 
255
228
  ################################################################################
256
229
 
257
- def test_default_permissions
258
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
259
-
260
- assert_equal true, r[:cwd][:read]
261
- assert_equal true, r[:cwd][:write]
262
- assert_equal false, r[:cwd][:rm]
263
-
264
- r[:cdc].each do |e|
265
- assert_equal true, e[:read]
266
- assert_equal true, e[:write]
267
- assert_equal true, e[:rm]
268
- end
269
- end
270
-
271
- def test_custom_permissions_on_root
272
- @elfinder.options = {
273
- :perms => {
274
- '.' => {:read => false},
275
- }
276
- }
277
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
278
- assert_match(/access denied/i, r[:error])
279
- end
280
-
281
- def test_custom_permissions
282
- @elfinder.options = {
283
- :perms => {
284
- 'foo' => {:rm => false},
285
- /.*.png$/ => {:rm => false},
286
- /^pjkh/ => {:read => false},
287
- 'README.txt' => {:write => false},
288
- }
289
- }
290
-
291
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
292
-
293
- r[:cdc].each do |e|
294
- case e[:name]
295
- when 'elfinder.png'
296
- assert_equal true, e[:read]
297
- assert_equal true, e[:write]
298
- assert_equal false, e[:rm]
299
- when 'foo'
300
- assert_equal true, e[:read]
301
- assert_equal true, e[:write]
302
- assert_equal false, e[:rm]
303
- when 'pjkh.png'
304
- assert_equal false, e[:read]
305
- assert_equal true, e[:write]
306
- assert_equal false, e[:rm]
307
- when 'README.txt'
308
- assert_equal true, e[:read]
309
- assert_equal false, e[:write]
310
- assert_equal true, e[:rm]
311
- end
312
- end
313
- end
314
-
315
- def test_custom_permissions_multiple_matches_prefers_false
316
- @elfinder.options = {
317
- :perms => {
318
- 'pjkh.png' => {:read => false},
319
- /pjkh/ => {:read => true},
320
- }
321
- }
322
-
323
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
324
-
325
- r[:cdc].each do |e|
326
- case e[:name]
327
- when 'pjkh.png'
328
- assert_equal false, e[:read]
329
- assert_equal true, e[:write]
330
- assert_equal true, e[:rm]
331
- else
332
- assert_equal true, e[:read]
333
- assert_equal true, e[:write]
334
- assert_equal true, e[:rm]
335
- end
336
- end
337
- end
338
-
339
- def test_custom_permissions_in_subdirectories
340
- @elfinder.options = {
341
- :perms => {
342
- %r{foo/s.*} => {:read => false}
343
- }
344
- }
345
-
346
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
347
- h, r = @elfinder.run(:cmd => 'open', :target => r[:cdc].find{|e| e[:name] == 'foo'}[:hash])
348
-
349
- r[:cdc].each do |e|
350
- case e[:name]
351
- when 'sandy.txt', 'sam.txt'
352
- assert_equal false, e[:read]
353
- else
354
- assert_equal true, e[:read]
355
- end
356
- end
357
- end
358
-
359
- def test_open_permissions
360
- @elfinder.options = {
361
- :perms => {
362
- 'foo' => {:read => false}
363
- }
364
- }
365
-
366
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
367
- target = r[:cdc].find{|e| e[:name] == 'foo'}
368
- h1, r = @elfinder.run(:cmd => 'open', :target => target[:hash])
369
- assert_match(/access denied/i, r[:error])
370
- end
371
-
372
- def test_mkdir_permissions
373
- @elfinder.options = {
374
- :perms => {
375
- 'foo' => {:write => false}
376
- }
377
- }
378
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
379
- target = r[:cdc].find{|e| e[:name] == 'foo'}
380
- h1, r = @elfinder.run(:cmd => 'open', :target => target[:hash])
381
-
382
- h, r = @elfinder.run(:cmd => 'mkdir', :current => r[:cwd][:hash], :name => 'dir1')
383
- assert !File.directory?(File.join(@vroot, 'foo', 'dir1'))
384
- assert_nil r[:select]
385
- assert_match(/access denied/i, r[:error])
386
- end
387
-
388
- def test_mkfile_permissions
389
- @elfinder.options = {
390
- :perms => {
391
- 'foo' => {:write => false}
392
- }
393
- }
394
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
395
- target = r[:cdc].find{|e| e[:name] == 'foo'}
396
- h1, r = @elfinder.run(:cmd => 'open', :target => target[:hash])
397
-
398
- h, r = @elfinder.run(:cmd => 'mkfile', :current => r[:cwd][:hash], :name => 'file1')
399
- assert !File.file?(File.join(@vroot, 'foo', 'file1'))
400
- assert_nil r[:select]
401
- assert_match(/access denied/i, r[:error])
402
- end
403
-
404
- def test_rename_permissions_file_rm_false
405
- @elfinder.options = {
406
- :perms => {
407
- 'README.txt' => {:rm => false}
408
- }
409
- }
410
-
411
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
412
- target = r[:cdc].find{|e| e[:name] == 'README.txt'}
413
- h1, r = @elfinder.run(:cmd => 'rename', :target => target[:hash], :current => r[:cwd][:hash], :name => 'file1')
414
- assert File.file?(File.join(@vroot, 'README.txt'))
415
- assert !File.file?(File.join(@vroot, 'file1'))
416
- assert_nil r[:select]
417
- assert_match(/access denied/i, r[:error])
418
- end
419
-
420
- def test_rename_permissions_dir_write_false
421
- @elfinder.options = {
422
- :perms => {
423
- '.' => {:write => false}
424
- }
425
- }
426
-
427
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
428
- target = r[:cdc].find{|e| e[:name] == 'README.txt'}
429
- h1, r = @elfinder.run(:cmd => 'rename', :target => target[:hash], :current => r[:cwd][:hash], :name => 'file1')
430
- assert File.file?(File.join(@vroot, 'README.txt'))
431
- assert !File.file?(File.join(@vroot, 'file1'))
432
- assert_nil r[:select]
433
- assert_match(/access denied/i, r[:error])
434
- end
435
-
436
- def test_upload_permissions
437
- @elfinder.options = {
438
- :perms => {
439
- '.' => {:write => false}
440
- }
441
- }
442
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
443
- uploads = []
444
- uploads << File.open(File.join(@vroot, 'foo/philip.txt'))
445
- h, r = @elfinder.run(:cmd => 'upload', :upload => uploads, :current => r[:cwd][:hash])
446
- assert !File.exist?(File.join(@vroot, 'philip.txt'))
447
- assert_nil r[:select]
448
- assert_match(/access denied/i, r[:error])
449
- end
450
-
451
- def test_paste_permissions_on_dst
452
- @elfinder.options = {
453
- :perms => {
454
- 'foo' => {:write => false}
455
- }
456
- }
457
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
458
- targets = r[:cdc].select{|e| e[:mime] != 'directory'}
459
- dst = r[:cdc].find{|e| e[:name] == 'foo'}
460
-
461
- h, r = @elfinder.run(:cmd => 'paste', :targets => targets.map{|e| e[:hash]}, :dst => dst[:hash])
462
- assert_match(/access denied/i, r[:error])
463
- assert !File.exist?(File.join(@vroot, 'foo', 'README.txt'))
464
- assert !File.exist?(File.join(@vroot, 'foo', 'pjkh.png'))
465
- assert !File.exist?(File.join(@vroot, 'foo', 'elfinder.png'))
466
- end
467
-
468
- def test_paste_permissions_on_target
469
- @elfinder.options = {
470
- :perms => {
471
- 'README.txt' => {:read => false}
472
- }
473
- }
474
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
475
- targets = r[:cdc].select{|e| e[:mime] != 'directory'}
476
- dst = r[:cdc].find{|e| e[:name] == 'foo'}
477
-
478
- h, r = @elfinder.run(:cmd => 'paste', :targets => targets.map{|e| e[:hash]}, :dst => dst[:hash])
479
- assert !File.exist?(File.join(@vroot, 'foo', 'README.txt'))
480
- assert File.exist?(File.join(@vroot, 'foo', 'pjkh.png'))
481
- assert File.exist?(File.join(@vroot, 'foo', 'elfinder.png'))
482
- end
483
-
484
- def test_rm_permissions_file_rm_false
485
- @elfinder.options = {
486
- :perms => {
487
- /.*\.png/ => {:rm => false}
488
- }
489
- }
490
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
491
- h, r = @elfinder.run(:cmd => 'rm', :targets => r[:cdc].map{|e| e[:hash]})
492
-
493
- assert !File.exist?(File.join(@vroot, 'README.txt'))
494
- assert File.exist?(File.join(@vroot, 'pjkh.png'))
495
- assert File.exist?(File.join(@vroot, 'elfinder.png'))
496
- assert !File.exist?(File.join(@vroot, 'foo'))
497
-
498
- assert_match(/unable to be removed/i, r[:error])
499
- assert_match(/access denied/i, r[:errorData].to_s)
500
- end
501
-
502
- def test_rm_permissions_chmod_perm_hack
503
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
504
- File.unlink(File.join(@vroot, 'pjkh.png'))
505
- h, r = @elfinder.run(:cmd => 'rm', :targets => r[:cdc].map{|e| e[:hash]})
506
-
507
- assert_match(/unable to be removed/i, r[:error])
508
- assert_match(/pjkh.png.*remove failed/i, r[:errorData].to_s)
509
- end
510
-
511
- def test_duplicate_permissions_file
512
- @elfinder.options = {
513
- :perms => {
514
- 'README.txt' => {:read => false}
515
- }
516
- }
517
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
518
- duplicate = r[:cdc].find{|e| e[:name] == 'README.txt'}
519
- h, r = @elfinder.run(:cmd => 'duplicate', :target => duplicate[:hash])
520
- assert !File.exist?(File.join(@vroot, 'README copy 1.txt'))
521
- assert_match(/access denied/i, r[:error])
522
- assert_match(/unable to read/i, r[:errorData].to_s)
523
- end
524
-
525
- def test_duplicate_permissions_directory
526
- @elfinder.options = {
527
- :perms => {
528
- '.' => {:write => false}
529
- }
530
- }
531
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
532
- duplicate = r[:cdc].find{|e| e[:name] == 'README.txt'}
533
- h, r = @elfinder.run(:cmd => 'duplicate', :target => duplicate[:hash])
534
- assert !File.exist?(File.join(@vroot, 'README copy 1.txt'))
535
- assert_match(/access denied/i, r[:error])
536
- assert_match(/unable to write/i, r[:errorData].to_s)
537
- end
538
-
539
-
540
- def test_read_file_permissions
541
- @elfinder.options = {
542
- :perms => {
543
- 'README.txt' => {:read => false}
544
- }
545
- }
546
-
547
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
548
- target = r[:cdc].find{|e| e[:name] == 'README.txt'}
549
- h, r = @elfinder.run(:cmd => 'read', :target => target[:hash])
550
-
551
- assert_nil r[:content]
552
- assert_match(/access denied/i, r[:error])
553
- end
554
-
555
- def test_edit_permissions_write
556
- @elfinder.options = {
557
- :perms => {
558
- 'README.txt' => {:write => false}
559
- }
560
- }
561
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
562
- file = r[:cdc].find{|e| e[:name] == 'README.txt'}
563
- h, r = @elfinder.run(:cmd => 'edit', :target => file[:hash], :content => 'Hello')
564
- assert_match(/access denied/i, r[:error])
565
- assert_not_equal 'Hello', File.read(File.join(@vroot, 'README.txt'))
566
- end
567
-
568
- def test_edit_permissions_read
569
- @elfinder.options = {
570
- :perms => {
571
- 'README.txt' => {:read => false}
572
- }
573
- }
574
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
575
- file = r[:cdc].find{|e| e[:name] == 'README.txt'}
576
- h, r = @elfinder.run(:cmd => 'edit', :target => file[:hash], :content => 'Hello')
577
- assert_match(/access denied/i, r[:error])
578
- assert_not_equal 'Hello', File.read(File.join(@vroot, 'README.txt'))
579
- end
580
-
581
- def test_resize_permissions_write
582
- @elfinder.options = {
583
- :perms => {
584
- 'pjkh.png' => {:write => false}
585
- }
586
- }
587
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
588
- file = r[:cdc].find{|e| e[:name] == 'pjkh.png'}
589
- h, r = @elfinder.run(:cmd => 'resize', :target => file[:hash], :current => r[:cwd][:hash], :width => '50', :height => '25')
590
- assert_match(/access denied/i, r[:error])
591
- assert File.exist?(File.join(@vroot, 'pjkh.png'))
592
- assert_equal '100x100', ElFinder::ImageSize.for(File.join(@vroot, 'pjkh.png')).to_s
593
- end
594
-
595
- def test_resize_permissions_read
596
- @elfinder.options = {
597
- :perms => {
598
- 'pjkh.png' => {:read => false}
599
- }
600
- }
601
- h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
602
- file = r[:cdc].find{|e| e[:name] == 'pjkh.png'}
603
- h, r = @elfinder.run(:cmd => 'resize', :target => file[:hash], :current => r[:cwd][:hash], :width => '50', :height => '25')
604
- assert_match(/access denied/i, r[:error])
605
- assert File.exist?(File.join(@vroot, 'pjkh.png'))
606
- assert_equal '100x100', ElFinder::ImageSize.for(File.join(@vroot, 'pjkh.png')).to_s
607
- end
608
-
609
230
  end
610
-
611
- __END__
612
- /Users/philip/Desktop/el_finder/test/files
613
- 14615625 16 -rw-r--r-- 1 philip staff 7718 Oct 15 14:19 ./elfinder.png
614
- 14569851 0 drwxr-xr-x 6 philip staff 204 Oct 15 11:19 ./foo
615
- 14605469 8 -rw-r--r-- 1 philip staff 7 Oct 15 11:19 ./foo/philip.txt
616
- 14605474 8 -rw-r--r-- 1 philip staff 4 Oct 15 11:19 ./foo/sam.txt
617
- 14605479 8 -rw-r--r-- 1 philip staff 6 Oct 15 11:19 ./foo/sandy.txt
618
- 14605486 8 -rw-r--r-- 1 philip staff 4 Oct 15 11:19 ./foo/tom.txt
619
- 14569820 8 -rw-r--r-- 1 philip staff 1142 Dec 6 2007 ./pjkh.png
620
- 14605515 8 -rw-r--r-- 1 philip staff 186 Oct 15 11:20 ./README.txt
@@ -0,0 +1,106 @@
1
+ require 'el_finder_test_case'
2
+
3
+ class TestElFinderExtractors < Test::Unit::TestCase
4
+
5
+ include ElFinderTestCase
6
+
7
+ ################################################################################
8
+
9
+ def test_archive_is_empty_by_default
10
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
11
+ assert_equal [], r[:params][:archives]
12
+ end
13
+
14
+ def test_archive_is_correct_when_set
15
+ @elfinder.options = {
16
+ :archivers => {
17
+ 'application/zip' => ['.zip', 'zip', '-qr9'],
18
+ 'application/x-tar' => ['.tar', 'tar', '-cf'],
19
+ 'application/x-gzip' => ['.tgz', 'tar', '-czf'],
20
+ 'application/x-bzip2' => ['.tbz', 'tar', '-cjf'],
21
+ }
22
+ }
23
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
24
+ assert_equal 4, r[:params][:archives].size
25
+ assert r[:params][:archives].include? 'application/zip'
26
+ assert r[:params][:archives].include? 'application/x-tar'
27
+ assert r[:params][:archives].include? 'application/x-gzip'
28
+ assert r[:params][:archives].include? 'application/x-bzip2'
29
+ end
30
+
31
+ def test_no_archiver_available
32
+ @elfinder.options = { :archivers => { 'application/zip' => ['zip', '-qr9'] } }
33
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
34
+ files = r[:cdc].select{|e| e[:name] =~ /\.png$/}
35
+ h, r = @elfinder.run(:cmd => 'archive', :type => 'bogus/archiver', :targets => files.map{|f| f[:hash]}, :current => r[:cwd][:hash])
36
+ assert_match(/no archiver available/i, r[:error])
37
+ end
38
+
39
+ def test_bogus_target
40
+ @elfinder.options = { :archivers => { 'application/zip' => ['zip', '-qr9'] } }
41
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
42
+ h, r = @elfinder.run(:cmd => 'archive', :type => 'application/zip', :targets => ['INVALID'], :current => r[:cwd][:hash])
43
+ assert_match(/invalid parameters/i, r[:error])
44
+ end
45
+
46
+ def test_bogus_current
47
+ @elfinder.options = { :archivers => { 'application/zip' => ['.zip', 'zip', '-qr9'] } }
48
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
49
+ files = r[:cdc].select{|e| e[:name] =~ /\.png$/}
50
+ h, r = @elfinder.run(:cmd => 'archive', :type => 'application/zip', :targets => files.map{|f| f[:hash]}, :current => 'INVALID')
51
+ assert_match(/invalid parameters/i, r[:error])
52
+ end
53
+
54
+ def test_permissions_no_read_on_target
55
+ @elfinder.options = {
56
+ :perms => { 'pjkh.png' => {:read => false} },
57
+ :archivers => { 'application/zip' => ['.zip', 'zip', '-qr9'] }
58
+ }
59
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
60
+ files = r[:cdc].select{|e| e[:name] =~ /\.png$/}
61
+ h, r = @elfinder.run(:cmd => 'archive', :type => 'application/zip', :targets => files.map{|f| f[:hash]}, :current => r[:cwd][:hash])
62
+ assert_match(/access denied/i, r[:error])
63
+ end
64
+
65
+ def test_permissions_no_write_on_current
66
+ @elfinder.options = {
67
+ :perms => { '.' => {:write => false} },
68
+ :archivers => { 'application/zip' => ['.zip', 'zip', '-qr9'] }
69
+ }
70
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
71
+ files = r[:cdc].select{|e| e[:name] =~ /\.png$/}
72
+ h, r = @elfinder.run(:cmd => 'archive', :type => 'application/zip', :targets => files.map{|f| f[:hash]}, :current => r[:cwd][:hash])
73
+ assert_match(/access denied/i, r[:error])
74
+ end
75
+
76
+ def test_successful_archive
77
+ raise "Unable to find 'zip' in your PATH. This test requires zip to run." if `which zip`.chomp.empty?
78
+ @elfinder.options = { :archivers => { 'application/zip' => ['.zip', 'zip', '-qr9'] } }
79
+
80
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
81
+ files = r[:cdc].select{|e| e[:name] =~ /\.png$/}
82
+ h, r = @elfinder.run(:cmd => 'archive', :name => 'Archive', :type => 'application/zip', :targets => files.map{|f| f[:hash]}, :current => r[:cwd][:hash])
83
+
84
+ assert File.exist?(File.join(@vroot, 'Archive.zip'))
85
+ assert_not_nil r[:select]
86
+ assert_nil r[:error]
87
+ end
88
+
89
+ def test_successful_archive_with_default_name
90
+ raise "Unable to find 'zip' in your PATH. This test requires zip to run." if `which zip`.chomp.empty?
91
+ @elfinder.options = { :archivers => { 'application/zip' => ['.zip', 'zip', '-qr9'] } }
92
+
93
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
94
+ files = r[:cdc].select{|e| e[:name] =~ /\.png$/}
95
+ h, r = @elfinder.run(:cmd => 'archive', :type => 'application/zip', :targets => files.map{|f| f[:hash]}, :current => r[:cwd][:hash])
96
+
97
+ assert File.exist?(File.join(@vroot, "#{files.first[:name].chomp('.png')}.zip"))
98
+ assert_not_nil r[:select]
99
+ assert_nil r[:error]
100
+ end
101
+
102
+
103
+ ################################################################################
104
+
105
+
106
+ end
@@ -0,0 +1,102 @@
1
+ require 'el_finder_test_case'
2
+
3
+ class TestElFinderExtractors < Test::Unit::TestCase
4
+
5
+ include ElFinderTestCase
6
+
7
+ ################################################################################
8
+
9
+ def test_extract_is_empty_by_default
10
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
11
+ assert_equal [], r[:params][:extract]
12
+ end
13
+
14
+ def test_extract_is_correct_when_set
15
+ @elfinder.options = {
16
+ :extractors => {
17
+ 'application/zip' => ['unzip'],
18
+ 'application/x-tar' => ['tar', '-xf'],
19
+ 'application/x-gzip' => ['tar', '-xzf'],
20
+ 'application/x-bzip2' => ['tar', '-xjf'],
21
+ }
22
+ }
23
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
24
+ assert_equal 4, r[:params][:extract].size
25
+ assert r[:params][:extract].include? 'application/zip'
26
+ assert r[:params][:extract].include? 'application/x-tar'
27
+ assert r[:params][:extract].include? 'application/x-gzip'
28
+ assert r[:params][:extract].include? 'application/x-bzip2'
29
+ end
30
+
31
+ def test_no_extractor_available
32
+ @elfinder.options = { :extractors => { 'application/zip' => ['unzip'] } }
33
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
34
+ file = r[:cdc].find{|e| e[:name] == 'pjkh.png'}
35
+ h, r = @elfinder.run(:cmd => 'extract', :target => file[:hash], :current => r[:cwd][:hash])
36
+ assert_match(/no extractor available/i, r[:error])
37
+ end
38
+
39
+ def test_bogus_target
40
+ @elfinder.options = {
41
+ :extractors => { 'application/zip' => ['unzip'] }
42
+ }
43
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
44
+ h, r = @elfinder.run(:cmd => 'extract', :target => 'INVALID', :current => r[:cwd][:hash])
45
+ assert_match(/invalid parameters/i, r[:error])
46
+ end
47
+
48
+ def test_bogus_current
49
+ @elfinder.options = {
50
+ :extractors => { 'application/zip' => ['unzip'] }
51
+ }
52
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
53
+ file = r[:cdc].find{|e| e[:name] == 'sample.zip'}
54
+ h, r = @elfinder.run(:cmd => 'extract', :target => file[:hash], :current => 'INVALID')
55
+ assert_match(/invalid parameters/i, r[:error])
56
+ end
57
+
58
+ def test_permissions_no_read_on_target
59
+ @elfinder.options = {
60
+ :perms => { 'sample.zip' => {:read => false} },
61
+ :extractors => { 'application/zip' => ['unzip'] }
62
+ }
63
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
64
+ file = r[:cdc].find{|e| e[:name] == 'sample.zip'}
65
+ h, r = @elfinder.run(:cmd => 'extract', :target => file[:hash], :current => r[:cwd][:hash])
66
+ assert_match(/access denied/i, r[:error])
67
+ end
68
+
69
+ def test_permissions_no_write_on_current
70
+ @elfinder.options = {
71
+ :perms => { '.' => {:write => false} },
72
+ :extractors => { 'application/zip' => ['unzip'] }
73
+ }
74
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
75
+ file = r[:cdc].find{|e| e[:name] == 'sample.zip'}
76
+ h, r = @elfinder.run(:cmd => 'extract', :target => file[:hash], :current => r[:cwd][:hash])
77
+ assert_match(/access denied/i, r[:error])
78
+ end
79
+
80
+ def test_successful_extraction
81
+ raise "Unable to find 'unzip' in your PATH. This test requires unzip to run." if `which unzip`.chomp.empty?
82
+ @elfinder.options = { :extractors => { 'application/zip' => ['unzip', '-qq', '-o'] } }
83
+
84
+ h, r = @elfinder.run(:cmd => 'open', :init => 'true', :target => '')
85
+ file = r[:cdc].find{|e| e[:name] == 'sample.zip'}
86
+ h, r = @elfinder.run(:cmd => 'extract', :target => file[:hash], :current => r[:cwd][:hash])
87
+
88
+ assert File.directory?(File.join(@vroot, 'unzipped'))
89
+ assert File.exist?(File.join(@vroot, 'unzipped/one'))
90
+ assert File.exist?(File.join(@vroot, 'unzipped/two'))
91
+ assert File.directory?(File.join(@vroot, 'unzipped/subdir'))
92
+ assert File.exist?(File.join(@vroot, 'unzipped/subdir/three'))
93
+ assert_not_nil r[:tree]
94
+ assert_nil r[:error]
95
+ end
96
+
97
+
98
+
99
+ ################################################################################
100
+
101
+
102
+ end
@@ -0,0 +1,19 @@
1
+ require 'el_finder_test_case'
2
+
3
+ class TestElFinder < Test::Unit::TestCase
4
+
5
+ include ElFinderTestCase
6
+
7
+ ################################################################################
8
+
9
+ def test_to_hash_method
10
+ assert_equal Base64.encode64('foo/bar').chomp, @elfinder.to_hash(ElFinder::Pathname.new_with_root(@vroot, 'foo/bar'))
11
+ assert_equal Base64.encode64('/').chomp, @elfinder.to_hash(ElFinder::Pathname.new_with_root(@vroot))
12
+ end
13
+
14
+ def test_from_hash_method
15
+ assert_equal File.join(@vroot, 'foo/bar'), @elfinder.from_hash(Base64.encode64('foo/bar').chomp).to_s
16
+ assert_equal @vroot, @elfinder.from_hash(Base64.encode64('').chomp).to_s
17
+ end
18
+
19
+ end