Revision 27a8a190 test/py/ganeti.server.rapi_unittest.py
b/test/py/ganeti.server.rapi_unittest.py | ||
---|---|---|
51 | 51 |
return None |
52 | 52 |
|
53 | 53 |
def _Test(self, method, path, headers, reqbody, |
54 |
user_fn=NotImplemented, luxi_client=NotImplemented): |
|
55 |
rm = rapi.testutils._RapiMock(user_fn, luxi_client) |
|
54 |
user_fn=NotImplemented, luxi_client=NotImplemented, |
|
55 |
reqauth=False): |
|
56 |
rm = rapi.testutils._RapiMock(user_fn, luxi_client, reqauth=reqauth) |
|
56 | 57 |
|
57 | 58 |
(resp_code, resp_headers, resp_body) = \ |
58 | 59 |
rm.FetchResponse(path, method, http.ParseHeaders(StringIO(headers)), |
... | ... | |
70 | 71 |
self.assertEqual(code, http.HTTP_OK) |
71 | 72 |
self.assertTrue(data is None) |
72 | 73 |
|
74 |
def testRootReqAuth(self): |
|
75 |
(code, _, _) = self._Test(http.HTTP_GET, "/", "", None, reqauth=True) |
|
76 |
self.assertEqual(code, http.HttpUnauthorized.code) |
|
77 |
|
|
73 | 78 |
def testVersion(self): |
74 | 79 |
(code, _, data) = self._Test(http.HTTP_GET, "/version", "", None) |
75 | 80 |
self.assertEqual(code, http.HTTP_OK) |
... | ... | |
235 | 240 |
path = "/2/instances/inst1.example.com/console" |
236 | 241 |
|
237 | 242 |
for method in rapi.baserlib._SUPPORTED_METHODS: |
238 |
# No authorization |
|
239 |
(code, _, _) = self._Test(method, path, "", "") |
|
243 |
for reqauth in [False, True]: |
|
244 |
# No authorization |
|
245 |
(code, _, _) = self._Test(method, path, "", "", reqauth=reqauth) |
|
240 | 246 |
|
241 |
if method == http.HTTP_GET:
|
|
242 |
self.assertEqual(code, http.HttpUnauthorized.code) |
|
243 |
else: |
|
244 |
self.assertEqual(code, http.HttpNotImplemented.code) |
|
247 |
if method == http.HTTP_GET or reqauth:
|
|
248 |
self.assertEqual(code, http.HttpUnauthorized.code)
|
|
249 |
else:
|
|
250 |
self.assertEqual(code, http.HttpNotImplemented.code)
|
|
245 | 251 |
|
246 | 252 |
|
247 | 253 |
class _FakeLuxiClientForQuery: |
Also available in: Unified diff