<\/div><\/div>/)
end
end
context "html template formatter" do
it "works with an empty string" do
style = Email::Styles.new("")
style.format_html
expect(style.to_html).to be_blank
end
it "attaches a style to h3 tags" do
doc = html_doc("
hello
")
expect(doc.at('h3')['style']).to be_present
end
it "attaches a style to hr tags" do
doc = html_doc("hello
")
expect(doc.at('hr')['style']).to be_present
end
it "attaches a style to a tags" do
doc = html_doc("
wat")
expect(doc.at('a')['style']).to be_present
end
it "attaches a style to a tags" do
doc = html_doc("
wat")
expect(doc.at('a')['style']).to be_present
end
it "attaches a style to ul and li tags" do
doc = html_doc("
")
expect(doc.at('ul')['style']).to be_present
expect(doc.at('li')['style']).to be_present
end
it "converts iframes to links" do
iframe_url = "http://www.youtube.com/embed/7twifrxOTQY?feature=oembed&wmode=opaque"
doc = html_doc("
")
expect(doc.at('iframe')).to be_blank
expect(doc.at('a')).to be_present
expect(doc.at('a')['href']).to eq(iframe_url)
end
it "won't allow non URLs in iframe src, strips them with no link" do
iframe_url = "alert('xss hole')"
doc = html_doc("
")
expect(doc.at('iframe')).to be_blank
expect(doc.at('a')).to be_blank
end
end
context "rewriting protocol relative URLs to the forum" do
it "doesn't rewrite a url to another site" do
doc = html_doc('
hello')
expect(doc.at('a')['href']).to eq("//youtube.com/discourse")
end
context "without https" do
before do
SiteSetting.stubs(:use_https).returns(false)
end
it "rewrites the href to have http" do
doc = html_doc('
hello')
expect(doc.at('a')['href']).to eq("http://test.localhost/discourse")
end
it "rewrites the href for attachment files to have http" do
doc = html_doc('
attachment_file.txt')
expect(doc.at('a')['href']).to eq("http://try-discourse.global.ssl.fastly.net/uploads/default/368/40b610b0aa90cfcf.txt")
end
it "rewrites the src to have http" do
doc = html_doc('
')
expect(doc.at('img')['src']).to eq("http://test.localhost/blah.jpg")
end
end
context "with https" do
before do
SiteSetting.stubs(:use_https).returns(true)
end
it "rewrites the forum URL to have https" do
doc = html_doc('
hello')
expect(doc.at('a')['href']).to eq("https://test.localhost/discourse")
end
it "rewrites the href for attachment files to have https" do
doc = html_doc('
attachment_file.txt')
expect(doc.at('a')['href']).to eq("https://try-discourse.global.ssl.fastly.net/uploads/default/368/40b610b0aa90cfcf.txt")
end
it "rewrites the src to have https" do
doc = html_doc('
')
expect(doc.at('img')['src']).to eq("https://test.localhost/blah.jpg")
end
end
end
context "strip_avatars_and_emojis" do
it "works for lonesome emoji with no title" do
emoji = "
"
style = Email::Styles.new(emoji)
style.strip_avatars_and_emojis
expect(style.to_html).to match_html("#{emoji}")
end
it "works for lonesome emoji with title" do
emoji = "
"
style = Email::Styles.new(emoji)
style.strip_avatars_and_emojis
expect(style.to_html).to match_html("cry_cry")
end
end
end