-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix UTF-8 invalid byte sequence exceptions in
web/email_address
(cl…
…oses #141). * This allows `web/email_address` to scan response bodies of images for email addresses.
- Loading branch information
1 parent
7f0adb2
commit e9b16c5
Showing
2 changed files
with
43 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,23 @@ | |
describe "#process" do | ||
context "when URL #body exists" do | ||
context "and email is present" do | ||
let(:email_address1) { '[email protected]' } | ||
let(:email_address2) { '[email protected]' } | ||
let(:body) do | ||
<<~HTML | ||
<html> | ||
<body> | ||
<p>[email protected]</p> | ||
<p>[email protected]</p> | ||
<p>#{email_address1}</p> | ||
<p>#{email_address2}</p> | ||
</body> | ||
</html> | ||
HTML | ||
end | ||
let(:url) { Ronin::Recon::Values::URL.new("example.com", body: body) } | ||
let(:expected_emails) do | ||
[ | ||
Ronin::Recon::Values::EmailAddress.new("[email protected]"), | ||
Ronin::Recon::Values::EmailAddress.new("[email protected]") | ||
Ronin::Recon::Values::EmailAddress.new(email_address1), | ||
Ronin::Recon::Values::EmailAddress.new(email_address2) | ||
] | ||
end | ||
|
||
|
@@ -33,6 +35,36 @@ | |
|
||
expect(yielded_values).to eq(expected_emails) | ||
end | ||
|
||
context "but the URL #body is binary data" do | ||
let(:body) { super().encode(Encoding::ASCII_8BIT) } | ||
|
||
it "must convert the #body into a UTF-8 String" do | ||
yielded_values = [] | ||
|
||
subject.process(url) do |value| | ||
yielded_values << value | ||
end | ||
|
||
expect(yielded_values).to eq(expected_emails) | ||
end | ||
|
||
context "and it contains invalid UTF-8 byte-sequences" do | ||
let(:body) do | ||
"\xfe\xff#{email_address1}\xfe\xff#{email_address2}\xfe\xff".b | ||
end | ||
|
||
it "must ignore any invalid UTF-8 byte sequences and only yield email address values" do | ||
yielded_values = [] | ||
|
||
subject.process(url) do |value| | ||
yielded_values << value | ||
end | ||
|
||
expect(yielded_values).to eq(expected_emails) | ||
end | ||
end | ||
end | ||
end | ||
|
||
context "and email is not present" do | ||
|