Remove SslRequirement and associated logic
[gitorious:mainline.git] / test / micro / gitorious / mount_point_test.rb
1 # encoding: utf-8
2 #--
3 #   Copyright (C) 2012 Gitorious AS
4 #
5 #   This program is free software: you can redistribute it and/or modify
6 #   it under the terms of the GNU Affero General Public License as published by
7 #   the Free Software Foundation, either version 3 of the License, or
8 #   (at your option) any later version.
9 #
10 #   This program is distributed in the hope that it will be useful,
11 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #   GNU Affero General Public License for more details.
14 #
15 #   You should have received a copy of the GNU Affero General Public License
16 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #++
18 require "minitest/autorun"
19 require "gitorious/mount_point"
20
21 class MountPointTest < MiniTest::Spec
22   describe Gitorious::HttpMountPoint do
23     it "does not use ssl by default" do
24       mp = Gitorious::HttpMountPoint.new("gitorious.here")
25
26       refute mp.ssl?
27     end
28
29     it "uses ssl" do
30       mp = Gitorious::HttpMountPoint.new("gitorious.here", 443, "https")
31
32       assert mp.ssl?
33     end
34
35     it "defaults to http on port 80" do
36       mp = Gitorious::HttpMountPoint.new("gitorious.here")
37
38       assert_equal "http://gitorious.here/somewhere", mp.url("/somewhere")
39     end
40
41     it "generates url for non-80 port" do
42       mp = Gitorious::HttpMountPoint.new("gitorious.here", 81)
43
44       assert_equal "http://gitorious.here:81/somewhere", mp.url("/somewhere")
45     end
46
47     it "generates url for ssl on port 443" do
48       mp = Gitorious::HttpMountPoint.new("gitorious.here", 443, "https")
49
50       assert_equal "https://gitorious.here/somewhere", mp.url("/somewhere")
51     end
52
53     it "generates url for ssl on non-443 port" do
54       mp = Gitorious::HttpMountPoint.new("gitorious.here", 1918, "https")
55
56       assert_equal "https://gitorious.here:1918/somewhere", mp.url("/somewhere")
57     end
58
59     it "considers gitorious.org a valid fqdn" do
60       mp = Gitorious::HttpMountPoint.new("gitorious.org")
61
62       assert mp.valid_fqdn?
63     end
64
65     it "considers host names without dots invalid fqdns" do
66       mp = Gitorious::HttpMountPoint.new("localhost")
67
68       refute mp.valid_fqdn?
69     end
70
71     describe "#can_share_cookies?" do
72       it "can share on same host" do
73         mp = Gitorious::HttpMountPoint.new("gitorious.org")
74         assert mp.can_share_cookies?("gitorious.org")
75       end
76
77       it "can share with subdomains" do
78         mp = Gitorious::HttpMountPoint.new("gitorious.org")
79         assert mp.can_share_cookies?("qt.gitorious.org")
80       end
81
82       it "cannot share with different domain" do
83         mp = Gitorious::HttpMountPoint.new("gitorious.org")
84         refute mp.can_share_cookies?("gitorious.com")
85       end
86
87       it "cannot share cookies if not a fully qualified domain name" do
88         mp = Gitorious::HttpMountPoint.new("gitorious")
89         refute mp.can_share_cookies?("gitorious")
90       end
91
92       it "can share with same subdomain" do
93         mp = Gitorious::HttpMountPoint.new("git.gitorious.org")
94         assert mp.can_share_cookies?("git.gitorious.org")
95         assert mp.can_share_cookies?("other.git.gitorious.org")
96       end
97     end
98   end
99
100   describe Gitorious::GitMountPoint do
101     it "generates git urls" do
102       mp = Gitorious::GitMountPoint.new("gitorious.org")
103       url = mp.url("/gitorious/mainline.git")
104
105       assert_equal "git://gitorious.org/gitorious/mainline.git", url
106     end
107
108     it "generates git urls for non-default" do
109       mp = Gitorious::GitMountPoint.new("gitorious.org", 9417)
110       url = mp.url("/gitorious/mainline.git")
111
112       assert_equal "git://gitorious.org:9417/gitorious/mainline.git", url
113     end
114   end
115 end