# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe StatusMessagesHelper do
it "should not allow basic XSS/HTML" do
make_links("").should == "<script>alert('XSS is evil')</script>"
end
it "should recognize basic http links (1/3)" do
proto="http"
url="bugs.joindiaspora.com/issues/332"
make_links(proto+"://"+url).should == ""+url+""
end
it "should recognize basic http links (2/3)" do
proto="http"
url="webmail.example.com?~()!*/"
make_links(proto+"://"+url).should == ""+url+""
end
it "should recognize basic http links (3/3)" do
proto="http"
url="127.0.0.1:3000/users/sign_in"
make_links(proto+"://"+url).should == ""+url+""
end
it "should recognize secure https links" do
proto="https"
url="127.0.0.1:3000/users/sign_in"
make_links(proto+"://"+url).should == ""+url+""
end
it "should recognize youtube links" do
proto="http"
videoid = "0x__dDWdf23"
url="www.youtube.com/watch?v="+videoid+"&a=GxdCwVVULXdvEBKmx_f5ywvZ0zZHHHDU&list=ML&playnext=1"
title = "UP & down & UP & down &"
mock_http = mock("http")
Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http)
mock_http.should_receive(:get).with('/feeds/api/videos/'+videoid+'?v=2', nil).and_return([nil, 'Foobar
'+title+' hallo welt dsd'])
res = make_links(proto+'://'+url)
res.should == "Youtube: "+title+""
end
it "should recognize a bunch of different links" do
message = "http:// Hello World, this is for www.joindiaspora.com and not for http://www.google.com though their Youtube service is neat, take http://www.youtube.com/watch?v=foobar or www.youtube.com/watch?foo=bar&v=BARFOO&whatever=related It is a good idea we finally have youtube, so enjoy this video http://www.youtube.com/watch?v=rickrolld"
mock_http = mock("http")
Net::HTTP.stub!(:new).with('gdata.youtube.com', 80).and_return(mock_http)
mock_http.should_receive(:get).with('/feeds/api/videos/foobar?v=2', nil).and_return([nil, 'Foobar F 007 - the bar is not enough hallo welt dsd'])
mock_http.should_receive(:get).with('/feeds/api/videos/BARFOO?v=2', nil).and_return([nil, 'Foobar BAR is the new FOO hallo welt dsd'])
mock_http.should_receive(:get).with('/feeds/api/videos/rickrolld?v=2', nil).and_return([nil, 'Foobar Never gonne give you up hallo welt dsd'])
res = make_links(message)
res.should == "http:// Hello World, this is for www.joindiaspora.com and not for www.google.com though their Youtube service is neat, take Youtube: F 007 - the bar is not enough or Youtube: BAR is the new FOO It is a good idea we finally have youtube, so enjoy this video Youtube: Never gonne give you up"
end
it "should recognize basic ftp links" do
proto="ftp"
url="ftp.uni-kl.de/CCC/26C3/mp4/26c3-3540-en-a_hackers_utopia.mp4"
# I did not watch that one, but the title sounds nice :P
make_links(proto+"://"+url).should == ""+url+""
end
it "should recognize www links" do
url="www.joindiaspora.com"
make_links(url).should == ""+url+""
end
describe "markdown" do
describe "weak emphasis" do
it "should be recognized (1/2)" do
message = "*some text* some text *some text* some text"
make_links(message).should == "some text some text some text some text"
end
it "should be recognized (2/2)" do
message = "_some text_ some text _some text_ some text"
make_links(message).should == "some text some text some text some text"
end
end
describe "strong emphasis" do
it "should be recognized (1/2)" do
message = "**some text** some text **some text** some text"
make_links(message).should == "some text some text some text some text"
end
it "should be recognized (2/2)" do
message = "__some text__ some text __some text__ some text"
make_links(message).should == "some text some text some text some text"
end
end
describe "imbricated weak and strong emphasis" do
it "should be rendered correctly" do
message = "__this is _some_ text__"
make_links(message).should == "this is some text"
message = "*this is **some** text*"
make_links(message).should == "this is some text"
message = "___some text___"
make_links(message).should == "some text"
end
end
it "should allow escaping" do
message = '*some text* \\*some text* \\**some text* _some text_ \\_some text_ \\__some text_'
make_links(message).should == "some text *some text *some text some text _some text _some text"
end
end
end