diff options
| author | Luke Kanies <luke@madstop.com> | 2007-10-17 11:44:03 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-10-17 11:44:03 -0500 |
| commit | d0bd48cc50cf90440429569e748877ab6e23491f (patch) | |
| tree | f7dadaa96bb2fce07bf9efaef2b610d890c59b89 /spec | |
| parent | a815f7888b021a46332c23450795f057533d0093 (diff) | |
| download | puppet-d0bd48cc50cf90440429569e748877ab6e23491f.tar.gz puppet-d0bd48cc50cf90440429569e748877ab6e23491f.tar.xz puppet-d0bd48cc50cf90440429569e748877ab6e23491f.zip | |
Adding the first pass at modifying file serving
to work with indirection. I've split the
fileserver handler into four pieces: Mount (which so
far I've just copied wholesale), Configuration (responsible
for reading the configuration file and determining what's allowed),
Metadata (retrieves information about the files), and Content
(retrieves the actual file content).
I haven't added the indirection tests yet, and the configuration
tests are still all stubs.
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/file_serving/configuration.rb | 65 | ||||
| -rwxr-xr-x | spec/unit/file_serving/content.rb | 44 | ||||
| -rwxr-xr-x | spec/unit/file_serving/metadata.rb | 68 | ||||
| -rwxr-xr-x | spec/unit/file_serving/mount.rb | 145 |
4 files changed, 322 insertions, 0 deletions
diff --git a/spec/unit/file_serving/configuration.rb b/spec/unit/file_serving/configuration.rb new file mode 100755 index 000000000..caff0fd14 --- /dev/null +++ b/spec/unit/file_serving/configuration.rb @@ -0,0 +1,65 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/file_serving/configuration' + +describe Puppet::FileServing::Configuration do + it "should work without a configuration file" +end + +describe Puppet::FileServing::Configuration, " when initializing" do + it "should make :new a private method" do + pending "Not implemented yet" + #proc { Puppet::FileServing::Configuration }.should raise_error + end + + it "should return the same configuration each time :create is called" do + pending "Not implemented yet" + #Puppet::FileServing::Configuration.create.should equal(Puppet::FileServing::Configuration.create) + end +end + +describe Puppet::FileServing::Configuration, " when parsing the configuration file" do + it "should not raise exceptions" + + it "should not replace the mount list until the file is entirely parsed successfully" + + it "should skip comments" + + it "should skip blank lines" + + it "should create a new mount for each section in the configuration" + + it "should only allow mount names that are alphanumeric plus dashes" + + it "should set the mount path to the path attribute from that section" + + it "should refuse to allow a path for the modules mount" + + it "should tell the mount to allow any allow values from the section" + + it "should tell the mount to deny any deny values from the section" + + it "should fail on any attributes other than path, allow, and deny" +end + +describe Puppet::FileServing::Configuration, " when finding file metadata" do + it "should require authorization" + + it "should return nil if the mount cannot be found" + + it "should use the mount object to return a Metadata instance if the mount exists" +end + +describe Puppet::FileServing::Configuration, " when finding file content" do + it "should require authorization" + + it "should return nil if the mount cannot be found" + + it "should use the mount object to return a Content instance if the mount exists" +end + +describe Puppet::FileServing::Configuration, " when authorizing" do + it "should reparse the configuration file when it has changed" +end diff --git a/spec/unit/file_serving/content.rb b/spec/unit/file_serving/content.rb new file mode 100755 index 000000000..3882659b9 --- /dev/null +++ b/spec/unit/file_serving/content.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/file_serving/content' + +describe Puppet::FileServing::Content, " when initializing" do + before do + @path = "/my/file" + end + + it "should accept a file path" do + FileTest.expects(:exists?).with(@path).returns(true) + Puppet::FileServing::Content.new(@path).path.should == @path + end + + it "should require a fully qualified file path" do + proc { Puppet::FileServing::Content.new("unqualified") }.should raise_error(ArgumentError) + end + + it "should require the path to exist" do + FileTest.expects(:exists?).with(@path).returns(false) + proc { Puppet::FileServing::Content.new(@path) }.should raise_error(ArgumentError) + end + + it "should not read the file" do + FileTest.expects(:exists?).with(@path).returns(true) + File.expects(:read).with(@path).never + Puppet::FileServing::Content.new(@path) + end +end + +describe Puppet::FileServing::Content, " when converting to yaml" do + before do + @path = "/my/file" + FileTest.expects(:exists?).with(@path).returns(true) + @content = Puppet::FileServing::Content.new(@path) + end + + it "should return the file contents" do + File.expects(:read).with(@path).returns("mycontent") + @content.to_yaml.should == "mycontent" + end +end diff --git a/spec/unit/file_serving/metadata.rb b/spec/unit/file_serving/metadata.rb new file mode 100755 index 000000000..1af1fff18 --- /dev/null +++ b/spec/unit/file_serving/metadata.rb @@ -0,0 +1,68 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +require 'puppet/file_serving/metadata' + +describe Puppet::FileServing::Metadata, " when initializing" do + it "should require a fully qualified file path" do + proc { Puppet::FileServing::Metadata.new("unqualified") }.should raise_error(ArgumentError) + end + + it "should require the path to exist" do + FileTest.expects(:exists?).with("/no/such/path").returns(false) + proc { Puppet::FileServing::Metadata.new("/no/such/path") }.should raise_error(ArgumentError) + end +end + +describe Puppet::FileServing::Metadata do + before do + @path = "/my/file" + @stat = mock 'stat', :uid => 10, :gid => 20, :mode => 0755 + File.stubs(:stat).returns(@stat) + @filehandle = mock 'filehandle' + @filehandle.expects(:each_line).yields("some content\n") + File.stubs(:open).with(@path, 'r').yields(@filehandle) + @checksum = Digest::MD5.hexdigest("some content\n") + FileTest.expects(:exists?).with(@path).returns(true) + @metadata = Puppet::FileServing::Metadata.new(@path) + end + + it "should accept a file path" do + @metadata.path.should == @path + end + + # LAK:FIXME This should actually change at some point + it "should set the owner by id" do + @metadata.owner.should be_instance_of(Fixnum) + end + + # LAK:FIXME This should actually change at some point + it "should set the group by id" do + @metadata.group.should be_instance_of(Fixnum) + end + + it "should set the owner to the file's current owner" do + @metadata.owner.should == 10 + end + + it "should set the group to the file's current group" do + @metadata.group.should == 20 + end + + it "should set the mode to a string version of the mode in octal" do + @metadata.mode.should == "755" + end + + it "should set the mode to the file's current mode" do + @metadata.mode.should == "755" + end + + it "should set the checksum to the file's current checksum" do + @metadata.checksum.should == "{md5}" + @checksum + end + + it "should default to a checksum of type MD5" do + @metadata.checksum.should == "{md5}" + @checksum + end +end diff --git a/spec/unit/file_serving/mount.rb b/spec/unit/file_serving/mount.rb new file mode 100755 index 000000000..cf658fe61 --- /dev/null +++ b/spec/unit/file_serving/mount.rb @@ -0,0 +1,145 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' +require 'puppet/file_serving/mount' + +describe Puppet::FileServing::Mount, " when initializing" do + it "should fail on non-alphanumeric name" do + proc { Puppet::FileServing::Mount.new("non alpha") }.should raise_error(ArgumentError) + end + + it "should allow dashes in its name" do + Puppet::FileServing::Mount.new("non-alpha").name.should == "non-alpha" + end + + it "should allow an optional path" do + Puppet::FileServing::Mount.new("name", "/").path.should == "/" + end +end + +describe Puppet::FileServing::Mount, " when setting the path" do + before do + @mount = Puppet::FileServing::Mount.new("test") + @dir = "/this/path/does/not/exist" + end + + it "should fail if the path does not exist" do + FileTest.expects(:exists?).returns(false) + proc { @mount.path = @dir }.should raise_error(ArgumentError) + end + + it "should fail if the path is not a directory" do + FileTest.expects(:exists?).returns(true) + FileTest.expects(:directory?).returns(false) + proc { @mount.path = @dir }.should raise_error(ArgumentError) + end + + it "should fail if the path is not readable" do + FileTest.expects(:exists?).returns(true) + FileTest.expects(:directory?).returns(true) + FileTest.expects(:readable?).returns(false) + proc { @mount.path = @dir }.should raise_error(ArgumentError) + end +end + +describe Puppet::FileServing::Mount, " when finding files" do + before do + FileTest.stubs(:exists?).returns(true) + FileTest.stubs(:directory?).returns(true) + FileTest.stubs(:readable?).returns(true) + @mount = Puppet::FileServing::Mount.new("test") + @host = "host.domain.com" + end + + it "should fail if the mount path has not been set" do + proc { @mount.file_path("/blah") }.should raise_error(ArgumentError) + end + + it "should replace incidences of %h in the path with the client's short name" do + @mount.path = "/dir/%h/yay" + @mount.path(@host).should == "/dir/host/yay" + end + + it "should replace incidences of %H in the path with the client's fully qualified name" do + @mount.path = "/dir/%H/yay" + @mount.path(@host).should == "/dir/host.domain.com/yay" + end + + it "should replace incidences of %d in the path with the client's domain name" do + @mount.path = "/dir/%d/yay" + @mount.path(@host).should == "/dir/domain.com/yay" + end + + it "should perform all necessary replacements" do + @mount.path = "/%h/%d/%H" + @mount.path(@host).should == "/host/domain.com/host.domain.com" + end + + it "should perform replacements on the base path" do + @mount.path = "/blah/%h" + @mount.file_path("/my/stuff", @host).should == "/blah/host/my/stuff" + end + + it "should not perform replacements on the per-file path" do + @mount.path = "/blah" + @mount.file_path("/%h/stuff", @host).should == "/blah/%h/stuff" + end + + it "should look for files relative to its base directory" do + @mount.path = "/blah" + @mount.file_path("/my/stuff", @host).should == "/blah/my/stuff" + end + + it "should use local host information if no client data is provided" do + Facter.stubs(:value).with("hostname").returns("myhost") + Facter.stubs(:value).with("domain").returns("mydomain.com") + @mount.path = "/%h/%d/%H" + @mount.path().should == "/myhost/mydomain.com/myhost.mydomain.com" + end + + it "should ignore links by default" + + it "should follow links when asked" +end + +describe Puppet::FileServing::Mount, " when providing metadata" do + before do + FileTest.stubs(:exists?).returns(true) + FileTest.stubs(:directory?).returns(true) + FileTest.stubs(:readable?).returns(true) + @mount = Puppet::FileServing::Mount.new("test", "/mount") + @host = "host.domain.com" + end + + it "should return nil if the file is absent" do + Puppet::FileServing::Metadata.expects(:new).never + FileTest.stubs(:exists?).returns(false) + @mount.metadata("/my/path").should be_nil + end + + it "should return a Metadata instance if the file is present" do + Puppet::FileServing::Metadata.expects(:new).returns(:myobj) + @mount.metadata("/my/path").should == :myobj + end +end + +describe Puppet::FileServing::Mount, " when providing content" do + before do + FileTest.stubs(:exists?).returns(true) + FileTest.stubs(:directory?).returns(true) + FileTest.stubs(:readable?).returns(true) + @mount = Puppet::FileServing::Mount.new("test", "/mount") + @host = "host.domain.com" + end + + it "should return nil if the file is absent" do + Puppet::FileServing::Content.expects(:new).never + FileTest.stubs(:exists?).returns(false) + @mount.content("/my/path").should be_nil + end + + it "should return a Content instance if the file is present" do + Puppet::FileServing::Content.expects(:new).returns(:myobj) + @mount.content("/my/path").should == :myobj + end +end |
