Skip to content

Commit

Permalink
FTP login sets run successfully, individually
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Saxby committed Feb 19, 2011
1 parent ef62c0c commit 2d8b0d7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 14 deletions.
23 changes: 17 additions & 6 deletions lib/fake_ftp/server.rb
Expand Up @@ -6,7 +6,7 @@ class Server

attr_accessor :directory, :port

CMDS = %w[user pass]
CMDS = %w[acct pass pasv user]
LNBK = "\r\n"

def initialize(port = 21)
Expand All @@ -26,7 +26,9 @@ def start
@client = @server.accept
respond_with('200 Can has FTP?')
@connection = Thread.new(@client) do |socket|
parse(socket.gets)
while !socket.nil? && !socket.closed?
parse(socket.gets)
end
end
end
end
Expand Down Expand Up @@ -62,12 +64,21 @@ def parse(request)
end
end

def user(stuff = '')
'331 send your password'
def user(name = '')
message = (name.to_s == 'anonymous') ? '230 logged in' : '331 send your password'
respond_with message
end

def pass(stuff = '')
'230 logged in'
def pass(*args)
respond_with '230 logged in'
end

def pasv(*args)
respond_with '227 Entering Passive Mode (128,205,32,24,82,127)'
end

def acct(*args)
respond_with '230 WHATEVER!'
end
end
end
56 changes: 48 additions & 8 deletions spec/models/fake_ftp/server_spec.rb
Expand Up @@ -58,6 +58,7 @@

after :each do
@server.stop
@server = nil
end

context 'FTP commands' do
Expand Down Expand Up @@ -85,24 +86,63 @@
@client.gets.should == "331 send your password\r\n"
end

it "accepts anonymous USER" do
@client.gets
@client.puts "USER anonymous"
@client.gets.should == "230 logged in\r\n"
end

it "accepts PASS" do
@client.gets
@client.puts "PASS password"
@client.gets.should == "230 logged in\r\n"
end
end

xit 'should accept ftp connections' do
ftp = Net::FTP.new
proc { ftp.connect('127.0.0.1', 21212) }.should_not raise_error
proc { ftp.close }.should_not raise_error
it "accepts PASV" do
@client.gets
@client.puts "PASV"
@client.gets.should == "227 Entering Passive Mode (128,205,32,24,82,127)\r\n"
end

it "accepts ACCT" do
@client.gets
@client.puts "ACCT"
@client.gets.should == "230 WHATEVER!\r\n"
end

it "should accept multiple commands in one session" do
@client.gets
@client.puts "USER thing"
@client.gets
@client.puts "USER thing"
@client.gets
@client.puts "USER thing"
@client.gets
@client.puts "USER thing"
end
end

it "should allow anonymous authentication"
context 'ftp client' do
before :each do
@ftp = Net::FTP.new
end
it 'should accept ftp connections' do
proc { @ftp.connect('127.0.0.1', 21212) }.should_not raise_error
proc { @ftp.close }.should_not raise_error
end

it "should allow named authentication"
it "should allow anonymous authentication" do
@ftp.connect('127.0.0.1', 21212)
proc {@ftp.login}.should_not raise_error
end

it "should put files to directory store"
it "should allow named authentication" do
@ftp.connect('127.0.0.1', 21212)
proc {@ftp.login('someone', 'password')}.should_not raise_error
end

it "should put files to directory store"
end

end

Expand Down

0 comments on commit 2d8b0d7

Please sign in to comment.