Skip to content

Commit

Permalink
Server accepts TYPE, CDUP
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Saxby committed Feb 20, 2011
1 parent 7832764 commit bf59584
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/fake_ftp/server.rb
Expand Up @@ -6,7 +6,7 @@ class Server

attr_accessor :directory, :port

CMDS = %w[acct cwd pass pasv pwd quit user]
CMDS = %w[acct cwd cdup pass pasv pwd quit type user]
LNBK = "\r\n"

def initialize(port = 21, options = {})
Expand Down Expand Up @@ -76,6 +76,7 @@ def acct(*args)
def cwd(*args)
'250 OK!'
end
alias :cdup :cwd

def pass(*args)
'230 logged in'
Expand All @@ -93,6 +94,17 @@ def quit(*args)
'221 OMG bye!'
end

def type(type = 'A')
case type.to_s
when 'A'
'200 Type set to A.'
when 'I'
'200 Type set to I.'
else
'504 We don\'t allow those'
end
end

def user(name = '')
(name.to_s == 'anonymous') ? '230 logged in' : '331 send your password'
end
Expand Down
33 changes: 32 additions & 1 deletion spec/models/fake_ftp/server_spec.rb
Expand Up @@ -146,11 +146,14 @@ module Rails; end
@client.gets.should == "257 \"/tmp\" is current directory\r\n"
end

it "says OK to any CWD, without doing anything" do
it "says OK to any CWD, CDUP, without doing anything" do
directory = @server.directory
@client.puts "CWD somewhere/else"
@client.gets.should == "250 OK!\r\n"
@server.directory.should == directory
@client.puts "CDUP"
@client.gets.should == "250 OK!\r\n"
@server.directory.should == directory
end

it "does not respond to MKD" do
Expand All @@ -159,6 +162,34 @@ module Rails; end
end
end

context 'file commands' do
before :each do
@client.gets
end
it "accepts TYPE ascii" do
@client.puts "TYPE A"
@client.gets.should == "200 Type set to A.\r\n"
end

it "accepts TYPE image" do
@client.puts "TYPE I"
@client.gets.should == "200 Type set to I.\r\n"
end

it "does not accept TYPEs other than ascii or image" do
@client.puts "TYPE E"
@client.gets.should == "504 We don't allow those\r\n"
@client.puts "TYPE N"
@client.gets.should == "504 We don't allow those\r\n"
@client.puts "TYPE T"
@client.gets.should == "504 We don't allow those\r\n"
@client.puts "TYPE C"
@client.gets.should == "504 We don't allow those\r\n"
@client.puts "TYPE L"
@client.gets.should == "504 We don't allow those\r\n"
end
end

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

0 comments on commit bf59584

Please sign in to comment.