spec/security_spec.rb in prawn-0.15.0 vs spec/security_spec.rb in prawn-1.0.0.rc1
- old
+ new
@@ -1,9 +1,9 @@
# encoding: utf-8
require "tempfile"
-require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
+require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")
describe "Document encryption" do
describe "Password padding" do
@@ -29,13 +29,13 @@
padded.length.should == 32
padded.should == Prawn::Document::Security::PasswordPadding
end
end
-
+
describe "Setting permissions" do
-
+
def doc_with_permissions(permissions)
pdf = Prawn::Document.new
class << pdf
# Make things easier to test
@@ -64,14 +64,14 @@
should == 0b1111_1111_1111_1111_1111_1111_1110_1111
doc_with_permissions(:modify_annotations => false).permissions_value.
should == 0b1111_1111_1111_1111_1111_1111_1101_1111
end
- it "should raise_error ArgumentError if invalid option is provided" do
+ it "should raise ArgumentError if invalid option is provided" do
lambda {
doc_with_permissions(:modify_document => false)
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
describe "Encryption keys" do
@@ -87,11 +87,11 @@
@pdf.encrypt_document :user_password => 'foo', :owner_password => 'bar',
:permissions => { :print_document => false }
end
it "should calculate the correct owner hash" do
- @pdf.owner_password_hash.unpack("H*").first.should match(/^61CA855012/i)
+ @pdf.owner_password_hash.unpack("H*").first.should.match(/^61CA855012/i)
end
it "should calculate the correct user hash" do
@pdf.user_password_hash.unpack("H*").first.should =~ /^6BC8C51031/i
end
@@ -104,55 +104,23 @@
end
describe "EncryptedPdfObject" do
it "should delegate to PdfObject for simple types" do
- PDF::Core::EncryptedPdfObject(true, nil, nil, nil).should == "true"
- PDF::Core::EncryptedPdfObject(42, nil, nil, nil).should == "42"
+ Prawn::Core::EncryptedPdfObject(true, nil, nil, nil).should == "true"
+ Prawn::Core::EncryptedPdfObject(42, nil, nil, nil).should == "42"
end
it "should encrypt strings properly" do
- PDF::Core::EncryptedPdfObject("foo", "12345", 123, 0).should == "<4ad6e3>"
+ Prawn::Core::EncryptedPdfObject("foo", "12345", 123, 0).should == "<4ad6e3>"
end
- it "should encrypt literal strings properly" do
- PDF::Core::EncryptedPdfObject(PDF::Core::LiteralString.new("foo"), "12345", 123, 0).should == bin_string("(J\xD6\xE3)")
- PDF::Core::EncryptedPdfObject(PDF::Core::LiteralString.new("lhfbqg3do5u0satu3fjf"), nil, 123, 0).should == bin_string("(\xF1\x8B\\(\b\xBB\xE18S\x130~4*#\\(%\x87\xE7\x8E\\\n)")
- end
-
- it "should encrypt time properly" do
- PDF::Core::EncryptedPdfObject(Time.utc(2050, 04, 26, 10, 17, 10), "12345", 123, 0).should == bin_string("(h\x83\xBE\xDC\xEC\x99\x0F\xD7\\)%\x13\xD4$\xB8\xF0\x16\xB8\x80\xC5\xE91+\xCF)")
- end
-
it "should properly handle compound types" do
- PDF::Core::EncryptedPdfObject({:Bar => "foo"}, "12345", 123, 0).should ==
+ Prawn::Core::EncryptedPdfObject({:Bar => "foo"}, "12345", 123, 0).should ==
"<< /Bar <4ad6e3>\n>>"
- PDF::Core::EncryptedPdfObject(["foo", "bar"], "12345", 123, 0).should ==
+ Prawn::Core::EncryptedPdfObject(["foo", "bar"], "12345", 123, 0).should ==
"[<4ad6e3> <4ed8fe>]"
end
-
- end
-
- describe "Reference#encrypted_object" do
- it "should encrypt references properly" do
- ref = PDF::Core::Reference(1,["foo"])
- ref.encrypted_object(nil).should == "1 0 obj\n[<4fca3f>]\nendobj\n"
- end
-
- it "should encrypt references with streams properly" do
- ref = PDF::Core::Reference(1, {})
- ref << 'foo'
- result = bin_string("1 0 obj\n<< /Length 3\n>>\nstream\nO\xCA?\nendstream\nendobj\n")
- ref.encrypted_object(nil).should == result
- end
- end
-
- describe "String#encrypted_object" do
- it "should encrypt stream properly" do
- stream = PDF::Core::Stream.new
- stream << "foo"
- result = bin_string("stream\nO\xCA?\nendstream\n")
- stream.encrypted_object(nil, 1, 0).should == result
- end
+
end
end