1 require File.dirname(__FILE__) + '/../test_helper'
4 class CvsValidationTest < Scm::Test
6 [ nil, "", "foo", "http:/", "http:://", "http://", "http://a",
7 ":pserver", # that's not enough
8 ":pserver:anonymous", #still not enough
9 ":pserver:anonymous:@ipodder.cvs.sourceforge.net", # missing the path
10 ":pserver:anonymous:::@ipodder.cvs.sourceforge.net:/cvsroot/ipodder", # too many colons
11 ":pserver@ipodder.cvs.sourceforge.net:/cvsroot/ipodder", # not enough colons
12 ":pserver:anonymous:@ipodder.cvs.sourceforge.net/cvsroot/ipodder", # hostname and path not separated by colon
13 ":pserver:anonymous:@ipodder.cvs.source/forge.net:/cvsroot/ipodder", # slash in hostname
14 ":pserver:anonymous:ipodder.cvs.sourceforge.net:/cvsroot/ipodder", # missing @
15 ":pserver:anonymous:@ipodder.cvs.sourceforge.net:cvsroot/ipodder", # path does not begin at root
16 ":pserver:anonymous:@ipodder.cvs.sourceforge.net:/cvsr%23oot/ipodder", # no encoded chars allowed
17 ":pserver:anonymous:@ipodder.cvs.sourceforge.net:/cvsroot/ipodder;asdf", # no ; in url
18 ":pserver:anonymous:@ipodder.cvs.sourceforge.net:/cvsroot/ipodder malicious code", # spaces not allowed
19 "sourceforge.net/svn/project/trunk", # missing a protocol prefix
20 "file:///home/robin/cvs", # file protocol is not allowed
21 "http://svn.sourceforge.net", # http protocol is not allowed
22 "git://kernel.org/whatever/linux.git" # git protocol is not allowed
24 # Rejected for both internal and public use
25 [true, false].each do |p|
26 cvs = CvsAdapter.new(:url => url, :public_urls_only => p)
27 assert cvs.validate_url
32 def test_accepted_urls
33 [ ":pserver:anonymous:@ipodder.cvs.sourceforge.net:/cvsroot/ipodder",
34 ":pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot",
35 ":pserver:anonymous:@cvs-mirror.mozilla.org:/cvsroot",
36 ":pserver:guest:@cvs.dev.java.net:/shared/data/ccvs/repository",
37 ":pserver:anoncvs:password@anoncvs.postgresql.org:/projects/cvsroot",
38 ":pserver:anonymous:@rubyeclipse.cvs.sourceforge.net:/cvsroot/rubyeclipse",
39 ":pserver:cvs:cvs@cvs.winehq.org:/home/wine",
40 ":pserver:tcpdump:anoncvs@cvs.tcpdump.org:/tcpdump/master",
41 ":pserver:anonymous:@user-mode-linux.cvs.sourceforge.net:/cvsroot/user-mode-linux",
42 ":pserver:anonymous:@sc2.cvs.sourceforge.net:/cvsroot/sc2",
43 ":pserver:cool-dev:@sc2.cvs.sourceforge.net:/cvsroot/sc2", # Hyphen should be OK in username
44 ":pserver:cvs_anon:@cvs.scms.waikato.ac.nz:/usr/local/global-cvs/ml_cvs", # Underscores should be ok in path
45 ":pserver:anonymous:freefem++@idared.ann.jussieu.fr:/Users/pubcvs/cvs" # Pluses should be OK
47 # Valid for both internal and public use
48 [true, false].each do |p|
49 cvs = CvsAdapter.new(:url => url, :public_urls_only => p)
50 assert !cvs.validate_url
55 # Local files not accepted for public URLs
56 def test_local_file_url
57 cvs = CvsAdapter.new(:url => "/root")
58 assert !cvs.validate_url
60 cvs = CvsAdapter.new(:url => "/root", :public_urls_only => true)
61 assert cvs.validate_url
64 def test_rejected_module_names
65 [nil,"","%",";","&","\n","\t"].each do |x|
66 cvs = CvsAdapter.new(:url => ":pserver:cvs:cvs@cvs.test.org:/test", :module_name => x)
68 assert cvs.errors.first[0] = :module_name
72 def test_accepted_module_names
73 ["myproject","my/project","my/project/2.0","my_project","0","My .Net Module", "my-module", "my-module++"].each do |x|
74 cvs = CvsAdapter.new(:url => ":pserver:cvs:cvs@cvs.test.org:/test", :module_name => x)
79 def test_symlink_fixup
80 cvs = CvsAdapter.new(:url => ":pserver:anoncvs:@cvs.netbeans.org:/cvs")
81 assert_equal ":pserver:anoncvs:@cvs.netbeans.org:/shared/data/ccvs/repository", cvs.normalize.url
83 cvs = CvsAdapter.new(:url => ":pserver:anoncvs:@cvs.netbeans.org:/cvs/")
84 assert_equal ":pserver:anoncvs:@cvs.netbeans.org:/shared/data/ccvs/repository", cvs.normalize.url
86 cvs = CvsAdapter.new(:url => ":pserver:anoncvs:@cvs.dev.java.net:/cvs")
87 assert_equal ":pserver:anoncvs:@cvs.dev.java.net:/shared/data/ccvs/repository", cvs.normalize.url
89 cvs = CvsAdapter.new(:url => ":PSERVER:ANONCVS:@CVS.DEV.JAVA.NET:/cvs")
90 assert_equal ":PSERVER:ANONCVS:@CVS.DEV.JAVA.NET:/shared/data/ccvs/repository", cvs.normalize.url
92 cvs = CvsAdapter.new(:url => ":pserver:anonymous:@cvs.gna.org:/cvs/eagleusb")
93 assert_equal ":pserver:anonymous:@cvs.gna.org:/var/cvs/eagleusb", cvs.normalize.url
96 def test_sync_pserver_username_password
97 # Pull username only from url
98 cvs = CvsAdapter.new(:url => ":pserver:guest:@ohloh.net:/test")
100 assert_equal ':pserver:guest:@ohloh.net:/test', cvs.url
101 assert_equal 'guest', cvs.username
102 assert_equal '', cvs.password
104 # Pull username and password from url
105 cvs = CvsAdapter.new(:url => ":pserver:guest:secret@ohloh.net:/test")
107 assert_equal ':pserver:guest:secret@ohloh.net:/test', cvs.url
108 assert_equal 'guest', cvs.username
109 assert_equal 'secret', cvs.password
111 # Apply username and password to url
112 cvs = CvsAdapter.new(:url => ":pserver::@ohloh.net:/test", :username => "guest", :password => "secret")
114 assert_equal ':pserver:guest:secret@ohloh.net:/test', cvs.url
115 assert_equal 'guest', cvs.username
116 assert_equal 'secret', cvs.password
118 # Passwords disagree, use :password attribute
119 cvs = CvsAdapter.new(:url => ":pserver:guest:old@ohloh.net:/test", :username => "guest", :password => "new")
121 assert_equal ':pserver:guest:new@ohloh.net:/test', cvs.url
122 assert_equal 'guest', cvs.username
123 assert_equal 'new', cvs.password
127 cvs = CvsAdapter.new(:url => nil)
128 assert_equal nil, cvs.guess_forge
130 cvs = CvsAdapter.new(:url => "garbage_in_garbage_out")
131 assert_equal nil, cvs.guess_forge
133 cvs = CvsAdapter.new(:url => ':pserver:guest:@cvs.dev.java.net:/cvs')
134 assert_equal 'java.net', cvs.guess_forge
136 cvs = CvsAdapter.new(:url => ":PSERVER:ANONCVS:@CVS.DEV.JAVA.NET:/cvs")
137 assert_equal 'java.net', cvs.guess_forge