em-ftpd-fsd 0.1.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.
- data/.simplecov +3 -0
- data/COPYING +674 -0
- data/Gemfile +12 -0
- data/README.md +21 -0
- data/Rakefile +34 -0
- data/VERSION +1 -0
- data/em-ftpd-fsd.gemspec +71 -0
- data/lib/em-ftpd-fsd.rb +23 -0
- data/lib/em-ftpd-fsd/authentication/plain.rb +46 -0
- data/lib/em-ftpd-fsd/base.rb +144 -0
- data/lib/em-ftpd-fsd/directory_item.rb +52 -0
- data/lib/em-ftpd-fsd/file_operations.rb +98 -0
- data/lib/em-ftpd-fsd/hooks.rb +69 -0
- data/spec/base_spec.rb +18 -0
- data/spec/file_operations/authentication_spec.rb +35 -0
- data/spec/file_operations/bytes_spec.rb +33 -0
- data/spec/file_operations/change_dir_spec.rb +31 -0
- data/spec/file_operations/delete_dir_spec.rb +45 -0
- data/spec/file_operations/delete_file_spec.rb +45 -0
- data/spec/file_operations/dir_contents_spec.rb +45 -0
- data/spec/file_operations/get_file_spec.rb +31 -0
- data/spec/file_operations/make_dir_spec.rb +47 -0
- data/spec/file_operations/put_file_spec.rb +56 -0
- data/spec/file_operations/rename_spec.rb +76 -0
- data/spec/hooks_spec.rb +37 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/files_helper.rb +36 -0
- metadata +110 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
describe EM::FTPD::FSD::Base do
|
2
|
+
let( :driver ){ BasicDriver.new( DriverConfig ) }
|
3
|
+
|
4
|
+
describe "#rename" do
|
5
|
+
context "when the source file exist" do
|
6
|
+
before do
|
7
|
+
ensure_file_exist( "/test_file" )
|
8
|
+
end
|
9
|
+
|
10
|
+
context "when the destination file does not exist" do
|
11
|
+
before do
|
12
|
+
ensure_file_does_not_exist( "/renamed" )
|
13
|
+
end
|
14
|
+
|
15
|
+
it "yield true" do
|
16
|
+
expect{ |b| driver.rename( "/test_file", "/renamed", &b ) }.to yield_with_args( true )
|
17
|
+
end
|
18
|
+
|
19
|
+
it "renames the source file to destination file" do
|
20
|
+
driver.rename( "/test_file", "/renamed" ){ |value| }
|
21
|
+
File.exist?( FTPRoot + "/test_file" ).should be_false
|
22
|
+
File.exist?( FTPRoot + "/renamed" ).should be_true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when the destination file do exist" do
|
27
|
+
before do
|
28
|
+
ensure_file_exist( "/renamed" )
|
29
|
+
end
|
30
|
+
|
31
|
+
it "yield true" do
|
32
|
+
expect{ |b| driver.rename( "/test_file", "/renamed", &b ) }.to yield_with_args( true )
|
33
|
+
end
|
34
|
+
|
35
|
+
it "renames the source file" do
|
36
|
+
driver.rename( "/test_file", "/renamed" ){ |value| }
|
37
|
+
File.exist?( FTPRoot + "/test_file" ).should be_false
|
38
|
+
File.exist?( FTPRoot + "/renamed" ).should be_true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "when the source file does not exist" do
|
44
|
+
before do
|
45
|
+
ensure_file_does_not_exist( "/test_file" )
|
46
|
+
ensure_file_does_not_exist( "/renamed" )
|
47
|
+
end
|
48
|
+
|
49
|
+
it "yield false" do
|
50
|
+
expect{ |b| driver.rename( "/test_file", "/renamed", &b ) }.to yield_with_args( false )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when source path is out of ftp folder" do
|
55
|
+
before do
|
56
|
+
ensure_file_exist( "/../out_of_ftp_file" )
|
57
|
+
ensure_file_does_not_exist( "/renamed" )
|
58
|
+
end
|
59
|
+
|
60
|
+
it "yield false" do
|
61
|
+
expect{ |b| driver.rename( "/../out_of_ftp_file", "/renamed", &b ) }.to yield_with_args( false )
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when destination path is out of ftp folder" do
|
66
|
+
before do
|
67
|
+
ensure_file_exist( "/tets_file" )
|
68
|
+
ensure_file_does_not_exist( "/../out_of_ftp_file" )
|
69
|
+
end
|
70
|
+
|
71
|
+
it "yield false" do
|
72
|
+
expect{ |b| driver.rename( "/test_file", "/../out_of_ftp_file", &b ) }.to yield_with_args( false )
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/spec/hooks_spec.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EM::FTPD::FSD::Base do
|
4
|
+
class BasicDriver
|
5
|
+
before :delete_file, :some_method
|
6
|
+
after :make_dir, :some_other
|
7
|
+
|
8
|
+
def some_method( file )
|
9
|
+
end
|
10
|
+
|
11
|
+
def some_other( dir, value )
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
let( :driver ){ BasicDriver.new( DriverConfig ) }
|
16
|
+
|
17
|
+
describe "Hooks" do
|
18
|
+
context "when a before hooked ftp command is called" do
|
19
|
+
it "also calls the given method with passed arguments" do
|
20
|
+
ensure_file_exist( "/test_file" )
|
21
|
+
|
22
|
+
driver.should_receive( :some_method ).with( File.expand_path( FTPRoot + "/test_file" ) )
|
23
|
+
driver.delete_file( "/test_file" ){ |value| }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when an after hooked ftp command is called" do
|
28
|
+
it "also calls the given method with passed arguments and yielded value" do
|
29
|
+
ensure_dir_does_not_exist( "/test_dir" )
|
30
|
+
|
31
|
+
driver.should_receive( :some_other ).with( File.expand_path( FTPRoot + "/test_dir" ), true )
|
32
|
+
driver.make_dir( "/test_dir" ){ |value| }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# Require code coverage using .simplecov file
|
2
|
+
require 'simplecov'
|
3
|
+
|
4
|
+
# REquire the gem itself
|
5
|
+
require 'em-ftpd-fsd'
|
6
|
+
|
7
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
8
|
+
# in spec/support/ and its subdirectories.
|
9
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f }
|
10
|
+
|
11
|
+
# Set up FTP folder
|
12
|
+
FTPRoot = "#{File.dirname( __FILE__ )}/support/ftp_root"
|
13
|
+
|
14
|
+
# Basic driver configuration
|
15
|
+
DriverConfig = {
|
16
|
+
base_path: FTPRoot,
|
17
|
+
authentication: {
|
18
|
+
plain: {
|
19
|
+
user: "admin",
|
20
|
+
password: "root"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
# Dummy class to do the testing
|
26
|
+
class BasicDriver
|
27
|
+
include EM::FTPD::FSD::Base
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.include FilesHelper
|
32
|
+
|
33
|
+
# Prepare the file system for test
|
34
|
+
config.before :suite do
|
35
|
+
Dir.mkdir( FTPRoot ) unless File.directory?( FTPRoot )
|
36
|
+
end
|
37
|
+
|
38
|
+
config.after :suite do
|
39
|
+
File.delete( FTPRoot + "/../out_of_ftp_file" ) if File.exist?( FTPRoot + "/../out_of_ftp_file" )
|
40
|
+
FileUtils.rm_rf( FTPRoot + "/../out_of_ftp_dir" ) if File.exist?( FTPRoot + "/../out_of_ftp_dir" )
|
41
|
+
FileUtils.rm_rf( FTPRoot )
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module FilesHelper
|
2
|
+
def ensure_file_exist( path )
|
3
|
+
ensure_entity( path, :file )
|
4
|
+
end
|
5
|
+
|
6
|
+
def ensure_file_does_not_exist( path )
|
7
|
+
ensure_entity( path, :file, false )
|
8
|
+
end
|
9
|
+
|
10
|
+
def ensure_dir_exist( path )
|
11
|
+
ensure_entity( path, :dir )
|
12
|
+
end
|
13
|
+
|
14
|
+
def ensure_dir_does_not_exist( path )
|
15
|
+
ensure_entity( path, :dir, false )
|
16
|
+
end
|
17
|
+
|
18
|
+
def ensure_entity( relative_path, type, existence = true )
|
19
|
+
path = FTPRoot + relative_path
|
20
|
+
|
21
|
+
case type
|
22
|
+
when :file
|
23
|
+
FileUtils.touch( path ) if( existence and not File.exist?( path ) )
|
24
|
+
File.delete( path ) if( File.exist?( path ) and not existence )
|
25
|
+
|
26
|
+
File.exist?( path ).should( existence ? be_true : be_false )
|
27
|
+
when :dir
|
28
|
+
Dir.mkdir( path ) if( existence and not File.directory?( path ) )
|
29
|
+
FileUtils.rm_rf( path ) if( File.directory?( path ) and not existence )
|
30
|
+
|
31
|
+
File.directory?( path ).should( existence ? be_true : be_false )
|
32
|
+
else
|
33
|
+
fail "Object have to be either file or directory"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-ftpd-fsd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Luis Ciudad
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yard
|
16
|
+
requirement: &4528020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.2.1
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *4528020
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: redcarpet
|
27
|
+
requirement: &4526820 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.2.2
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *4526820
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: jeweler
|
38
|
+
requirement: &4544280 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.8.4
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *4544280
|
47
|
+
description: Very simple file system driver for EM-FTPD server; including common FTP
|
48
|
+
commands, authentication and before and after operation hooks.
|
49
|
+
email: lciudad@nosolosoftware.biz
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files:
|
53
|
+
- README.md
|
54
|
+
files:
|
55
|
+
- .simplecov
|
56
|
+
- COPYING
|
57
|
+
- Gemfile
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- em-ftpd-fsd.gemspec
|
62
|
+
- lib/em-ftpd-fsd.rb
|
63
|
+
- lib/em-ftpd-fsd/authentication/plain.rb
|
64
|
+
- lib/em-ftpd-fsd/base.rb
|
65
|
+
- lib/em-ftpd-fsd/directory_item.rb
|
66
|
+
- lib/em-ftpd-fsd/file_operations.rb
|
67
|
+
- lib/em-ftpd-fsd/hooks.rb
|
68
|
+
- spec/base_spec.rb
|
69
|
+
- spec/file_operations/authentication_spec.rb
|
70
|
+
- spec/file_operations/bytes_spec.rb
|
71
|
+
- spec/file_operations/change_dir_spec.rb
|
72
|
+
- spec/file_operations/delete_dir_spec.rb
|
73
|
+
- spec/file_operations/delete_file_spec.rb
|
74
|
+
- spec/file_operations/dir_contents_spec.rb
|
75
|
+
- spec/file_operations/get_file_spec.rb
|
76
|
+
- spec/file_operations/make_dir_spec.rb
|
77
|
+
- spec/file_operations/put_file_spec.rb
|
78
|
+
- spec/file_operations/rename_spec.rb
|
79
|
+
- spec/hooks_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- spec/support/files_helper.rb
|
82
|
+
homepage: https://github.com/nanocity/em-ftpd-fsd
|
83
|
+
licenses:
|
84
|
+
- GPLv3
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
hash: -3903833410681499953
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.8.10
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: File System Driver for EM-FTPD server
|
110
|
+
test_files: []
|