diff options
author | Russ Allbery <rra@stanford.edu> | 2008-02-09 02:07:53 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2008-02-09 02:07:53 +0000 |
commit | 9feb152a52ec8b28231fdbb2590e0544e683d956 (patch) | |
tree | 23d280a9469d82214edc4657dd86bfd8f509efab /perl | |
parent | b415b347328e7db0f41f0294c06060c6dd156b3d (diff) |
Actually implement FILE_MAX_SIZE.
Diffstat (limited to 'perl')
-rw-r--r-- | perl/Wallet/Object/File.pm | 7 | ||||
-rwxr-xr-x | perl/t/file.t | 18 |
2 files changed, 24 insertions, 1 deletions
diff --git a/perl/Wallet/Object/File.pm b/perl/Wallet/Object/File.pm index 2b18bb2..b4e23f8 100644 --- a/perl/Wallet/Object/File.pm +++ b/perl/Wallet/Object/File.pm @@ -104,6 +104,13 @@ sub store { $self->error ("cannot store $id: object is locked"); return; } + if ($Wallet::Config::FILE_MAX_SIZE) { + my $max = $Wallet::Config::FILE_MAX_SIZE; + if (length ($data) > $max) { + $self->error ("data exceeds maximum of $max bytes"); + return; + } + } my $path = $self->file_path; return unless $path; unless (open (FILE, '>', $path)) { diff --git a/perl/t/file.t b/perl/t/file.t index 8783d7b..8eaa0f1 100755 --- a/perl/t/file.t +++ b/perl/t/file.t @@ -9,7 +9,7 @@ # See LICENSE for licensing terms. use POSIX qw(strftime); -use Test::More tests => 50; +use Test::More tests => 56; use Wallet::Admin; use Wallet::Config; @@ -83,6 +83,22 @@ is ($object->store ("bar\n\0baz\n", @trace), 1, ' but storing again works'); ok (-f 'test-files/09/test', ' and the file exists'); is (contents ('test-files/09/test'), 'bar', ' with the right contents'); is ($object->get (@trace), "bar\n\0baz\n", ' and get returns correctly'); + +# Try exceeding the store size. +$Wallet::Config::FILE_MAX_SIZE = 1024; +is ($object->store ('x' x 1024, @trace), 1, + ' and storing exactly 1024 characters works'); +is ($object->get (@trace), 'x' x 1024, ' and get returns the right thing'); +is ($object->store ('x' x 1025, @trace), undef, + ' but storing 1025 characters fails'); +is ($object->error, 'data exceeds maximum of 1024 bytes', + ' with the right error'); + +# Try storing the empty data object. +is ($object->store ('', @trace), 1, 'Storing the empty object works'); +is ($object->get (@trace), '', ' and get returns the right thing'); + +# Test destruction. is ($object->destroy (@trace), 1, 'Destroying the object works'); ok (! -f 'test-files/09/test', ' and the file is gone'); |