1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.transport;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.assertTrue;
48
49 import org.eclipse.jgit.lib.Config;
50 import org.junit.Before;
51 import org.junit.Test;
52
53
54
55
56
57 public class HttpConfigTest {
58
59 private static final String DEFAULT = "[http]\n" + "\tpostBuffer = 1\n"
60 + "\tsslVerify= true\n" + "\tfollowRedirects = true\n"
61 + "\tmaxRedirects = 5\n\n";
62
63 private Config config;
64
65 @Before
66 public void setUp() {
67 config = new Config();
68 }
69
70 @Test
71 public void testDefault() throws Exception {
72 HttpConfig http = new HttpConfig(config,
73 new URIish("http://example.com/path/repo.git"));
74 assertEquals(1024 * 1024, http.getPostBuffer());
75 assertTrue(http.isSslVerify());
76 assertEquals(HttpConfig.HttpRedirectMode.INITIAL,
77 http.getFollowRedirects());
78 }
79
80 @Test
81 public void testMatchSuccess() throws Exception {
82 config.fromText(DEFAULT + "[http \"http://example.com\"]\n"
83 + "\tpostBuffer = 1024\n");
84 HttpConfig http = new HttpConfig(config,
85 new URIish("http://example.com/path/repo.git"));
86 assertEquals(1024, http.getPostBuffer());
87 http = new HttpConfig(config,
88 new URIish("https://example.com/path/repo.git"));
89 assertEquals(1, http.getPostBuffer());
90 http = new HttpConfig(config,
91 new URIish("http://example.org/path/repo.git"));
92 assertEquals(1, http.getPostBuffer());
93 http = new HttpConfig(config,
94 new URIish("http://example.com:80/path/repo.git"));
95 assertEquals(1024, http.getPostBuffer());
96 http = new HttpConfig(config,
97 new URIish("http://example.com:8080/path/repo.git"));
98 assertEquals(1, http.getPostBuffer());
99 }
100
101 @Test
102 public void testMatchWithOnlySchemeInConfig() throws Exception {
103 config.fromText(
104 DEFAULT + "[http \"http://\"]\n" + "\tpostBuffer = 1024\n");
105 HttpConfig http = new HttpConfig(config,
106 new URIish("http://example.com/path/repo.git"));
107 assertEquals(1, http.getPostBuffer());
108 }
109
110 @Test
111 public void testMatchWithPrefixUriInConfig() throws Exception {
112 config.fromText(DEFAULT + "[http \"http://example\"]\n"
113 + "\tpostBuffer = 1024\n");
114 HttpConfig http = new HttpConfig(config,
115 new URIish("http://example.com/path/repo.git"));
116 assertEquals(1, http.getPostBuffer());
117 }
118
119 @Test
120 public void testMatchCaseSensitivity() throws Exception {
121 config.fromText(DEFAULT + "[http \"http://exAMPle.com\"]\n"
122 + "\tpostBuffer = 1024\n");
123 HttpConfig http = new HttpConfig(config,
124 new URIish("http://example.com/path/repo.git"));
125 assertEquals(1024, http.getPostBuffer());
126 }
127
128 @Test
129 public void testMatchWithInvalidUriInConfig() throws Exception {
130 config.fromText(
131 DEFAULT + "[http \"///\"]\n" + "\tpostBuffer = 1024\n");
132 HttpConfig http = new HttpConfig(config,
133 new URIish("http://example.com/path/repo.git"));
134 assertEquals(1, http.getPostBuffer());
135 }
136
137 @Test
138 public void testMatchWithInvalidAndValidUriInConfig() throws Exception {
139 config.fromText(DEFAULT + "[http \"///\"]\n" + "\tpostBuffer = 1024\n"
140 + "[http \"http://example.com\"]\n" + "\tpostBuffer = 2048\n");
141 HttpConfig http = new HttpConfig(config,
142 new URIish("http://example.com/path/repo.git"));
143 assertEquals(2048, http.getPostBuffer());
144 }
145
146 @Test
147 public void testMatchWithHostEndingInSlash() throws Exception {
148 config.fromText(DEFAULT + "[http \"http://example.com/\"]\n"
149 + "\tpostBuffer = 1024\n");
150 HttpConfig http = new HttpConfig(config,
151 new URIish("http://example.com/path/repo.git"));
152 assertEquals(1024, http.getPostBuffer());
153 }
154
155 @Test
156 public void testMatchWithUser() throws Exception {
157 config.fromText(DEFAULT + "[http \"http://example.com/path\"]\n"
158 + "\tpostBuffer = 1024\n"
159 + "[http \"http://example.com/path/repo\"]\n"
160 + "\tpostBuffer = 2048\n"
161 + "[http \"http://user@example.com/path\"]\n"
162 + "\tpostBuffer = 4096\n");
163 HttpConfig http = new HttpConfig(config,
164 new URIish("http://example.com/path/repo.git"));
165 assertEquals(1024, http.getPostBuffer());
166 http = new HttpConfig(config,
167 new URIish("http://user@example.com/path/repo.git"));
168 assertEquals(4096, http.getPostBuffer());
169 http = new HttpConfig(config,
170 new URIish("http://user@example.com/path/repo/foo.git"));
171 assertEquals(2048, http.getPostBuffer());
172 http = new HttpConfig(config,
173 new URIish("http://user@example.com/path/foo.git"));
174 assertEquals(4096, http.getPostBuffer());
175 http = new HttpConfig(config,
176 new URIish("http://example.com/path/foo.git"));
177 assertEquals(1024, http.getPostBuffer());
178 http = new HttpConfig(config,
179 new URIish("http://User@example.com/path/repo/foo.git"));
180 assertEquals(2048, http.getPostBuffer());
181 http = new HttpConfig(config,
182 new URIish("http://User@example.com/path/foo.git"));
183 assertEquals(1024, http.getPostBuffer());
184 }
185
186 @Test
187 public void testMatchLonger() throws Exception {
188 config.fromText(DEFAULT + "[http \"http://example.com/path\"]\n"
189 + "\tpostBuffer = 1024\n"
190 + "[http \"http://example.com/path/repo\"]\n"
191 + "\tpostBuffer = 2048\n");
192 HttpConfig http = new HttpConfig(config,
193 new URIish("http://example.com/path/repo.git"));
194 assertEquals(1024, http.getPostBuffer());
195 http = new HttpConfig(config,
196 new URIish("http://example.com/foo/repo.git"));
197 assertEquals(1, http.getPostBuffer());
198 http = new HttpConfig(config,
199 new URIish("https://example.com/path/repo.git"));
200 assertEquals(1, http.getPostBuffer());
201 http = new HttpConfig(config,
202 new URIish("http://example.com/path/repo/.git"));
203 assertEquals(2048, http.getPostBuffer());
204 http = new HttpConfig(config, new URIish("http://example.com/path"));
205 assertEquals(1024, http.getPostBuffer());
206 http = new HttpConfig(config,
207 new URIish("http://user@example.com/path"));
208 assertEquals(1024, http.getPostBuffer());
209 }
210 }