diff --git a/spec/lib/rex/mime/encoding_spec.rb b/spec/lib/rex/mime/encoding_spec.rb index b002c544a5..85f7a9fc27 100644 --- a/spec/lib/rex/mime/encoding_spec.rb +++ b/spec/lib/rex/mime/encoding_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' require 'rex/mime' -require 'rex/text' describe Rex::MIME::Encoding do diff --git a/spec/lib/rex/mime/header_spec.rb b/spec/lib/rex/mime/header_spec.rb index 282f355e33..e2343fca71 100644 --- a/spec/lib/rex/mime/header_spec.rb +++ b/spec/lib/rex/mime/header_spec.rb @@ -2,7 +2,6 @@ require 'spec_helper' require 'rex/mime' -require 'rex/text' describe Rex::MIME::Header do diff --git a/spec/lib/rex/mime/part_spec.rb b/spec/lib/rex/mime/part_spec.rb new file mode 100644 index 0000000000..1f150f882f --- /dev/null +++ b/spec/lib/rex/mime/part_spec.rb @@ -0,0 +1,92 @@ +# -*- coding:binary -*- +require 'spec_helper' + +require 'rex/mime' + +describe Rex::MIME::Part do + + subject do + described_class.new + end + + describe "#initialize" do + subject(:part_class) do + described_class.allocate + end + + it "initializes the Rex::MIME::Header object" do + part_class.send(:initialize) + expect(part_class.header).to be_a(Rex::MIME::Header) + end + + it "initializes the Rex::MIME::Header with an empty array of headers" do + part_class.send(:initialize) + expect(part_class.header.headers).to be_empty + end + + it "Initializes content with an empty String" do + part_class.send(:initialize) + expect(part_class.content).to be_empty + end + end + + describe "#transfer_encoding" do + it "returns nil if the part hasn't a Content-Transfer-Encoding header" do + expect(subject.transfer_encoding).to be_nil + end + + it "returns the transfer encoding value if a Content-Transfer-Encoding header exists" do + subject.header.add('Content-Transfer-Encoding', 'base64') + expect(subject.transfer_encoding).to eq('base64') + end + end + + describe "#binary_content?" do + it "returns false if transfer encoding isn't defined" do + expect(subject.binary_content?).to be_falsey + end + + it "returns false if transfer encoding isn't binary" do + subject.header.add('Content-Transfer-Encoding', 'base64') + expect(subject.binary_content?).to be_falsey + end + + it "returns true if transfer encoding is binary" do + subject.header.add('Content-Transfer-Encoding', 'binary') + expect(subject.binary_content?).to be_truthy + end + end + + describe "#content_encoded" do + let(:content_test) do + "\rTest1\n" + end + + it "returns the exact content if transfer encoding is binary" do + subject.header.add('Content-Transfer-Encoding', 'binary') + subject.content = content_test + expect(subject.content_encoded).to eq(content_test) + end + + it "returns the content crlf encoded if transfer encoding isn't binary" do + subject.content = content_test + expect(subject.content_encoded).to eq("Test1\r\n") + end + end + + describe "#to_s" do + it "returns headers and content separated by two \\r\\n sequences" do + subject.header.add('var', 'val') + subject.content = 'content' + expect(subject.to_s).to eq("var: val\r\n\r\ncontent\r\n") + end + + it "returns two \\r\\n sequences if part is empty" do + expect(subject.to_s).to eq("\r\n\r\n") + end + + it "ends with \\r\\n sequence" do + expect(subject.to_s).to end_with("\r\n") + end + end +end