root/test/tftp/tftp_test.rb @ 5f7fd34c
eda861b3 | Ohad Levy | require 'test_helper'
|
|
038fa6cf | Dmitri Dolguikh | require 'tftp/tftp_plugin'
|
|
require "tftp/server"
|
|||
e09de9d9 | Ohad Levy | ||
class TftpTest < Test::Unit::TestCase
|
|||
def setup
|
|||
038fa6cf | Dmitri Dolguikh | @tftp = Proxy::TFTP::Server.new
|
|
7b1b5967 | Dmitri Dolguikh | Proxy::TFTP::Plugin.load_test_settings(:tftproot => "/some/root")
|
|
e09de9d9 | Ohad Levy | end
|
|
def test_should_have_a_logger
|
|||
assert_respond_to @tftp, :logger
|
|||
end
|
|||
c4a245d5 | Dmitri Dolguikh | def test_path_to_tftp_directory_without_tftproot_setting
|
|
7b1b5967 | Dmitri Dolguikh | Proxy::TFTP::Plugin.load_test_settings({})
|
|
038fa6cf | Dmitri Dolguikh | assert_equal "/var/lib/tftpboot", @tftp.send(:path)
|
|
c4a245d5 | Dmitri Dolguikh | end
|
|
def test_path_to_tftp_directory_with_tftproot_setting
|
|||
7b1b5967 | Dmitri Dolguikh | assert_equal "/some/root", @tftp.send(:path)
|
|
e09de9d9 | Ohad Levy | end
|
|
c4a245d5 | Dmitri Dolguikh | def test_path_to_tftp_directory_with_relative_tftproot_setting
|
|
7b1b5967 | Dmitri Dolguikh | Proxy::TFTP::Plugin.load_test_settings(:tftproot => "./some/root")
|
|
038fa6cf | Dmitri Dolguikh | assert_equal Pathname.new(__FILE__).join("..", "..", "..", "modules","tftp","some","root").to_s, @tftp.send(:path)
|
|
c4a245d5 | Dmitri Dolguikh | end
|
|
854ab557 | Greg Sutcliffe | ||
def test_paths_inside_tftp_directory_dont_raise_errors
|
|||
5f7fd34c | Lukas Zapletal | ::Proxy::HttpDownload.any_instance.stubs(:start).returns(true)
|
|
854ab557 | Greg Sutcliffe | FileUtils.stubs(:mkdir_p).returns(true)
|
|
d44cdd95 | Dmitri Dolguikh | ||
854ab557 | Greg Sutcliffe | assert Proxy::TFTP.send(:fetch_boot_file,'/some/root/boot/file','http://localhost/file')
|
|
end
|
|||
def test_paths_outside_tftp_directory_raise_errors
|
|||
5f7fd34c | Lukas Zapletal | ::Proxy::HttpDownload.any_instance.stubs(:start).returns(true)
|
|
854ab557 | Greg Sutcliffe | FileUtils.stubs(:mkdir_p).returns(true)
|
|
d44cdd95 | Dmitri Dolguikh | ||
854ab557 | Greg Sutcliffe | assert_raises RuntimeError do
|
|
Proxy::TFTP.send(:fetch_boot_file,'/other/root/boot/file','http://localhost/file')
|
|||
end
|
|||
end
|
|||
a7297466 | Dmitri Dolguikh | def test_boot_filename_has_no_dash_when_prefix_ends_with_slash
|
|
assert_equal "a/b/c/somefile", Proxy::TFTP.boot_filename('a/b/c/', '/d/somefile')
|
|||
end
|
|||
def test_boot_filename_uses_dash_when_prefix_does_not_end_with_slash
|
|||
assert_equal "a/b/c-somefile", Proxy::TFTP.boot_filename('a/b/c', '/d/somefile')
|
|||
end
|
|||
e09de9d9 | Ohad Levy | end
|