Tests: added getjson() helper.
This commit is contained in:
@@ -70,6 +70,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
|
||||||
w.Write(data)
|
w.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class TestGoIsolation(TestApplicationGo):
|
|||||||
def test_isolation_values(self):
|
def test_isolation_values(self):
|
||||||
self.load('ns_inspect')
|
self.load('ns_inspect')
|
||||||
|
|
||||||
obj = self.isolation.parsejson(self.get()['body'])
|
obj = self.getjson()['body']
|
||||||
|
|
||||||
for ns, ns_value in self.available['features']['isolation'].items():
|
for ns, ns_value in self.available['features']['isolation'].items():
|
||||||
if ns.upper() in obj['NS']:
|
if ns.upper() in obj['NS']:
|
||||||
@@ -54,7 +54,7 @@ class TestGoIsolation(TestApplicationGo):
|
|||||||
except:
|
except:
|
||||||
group_id = grp.getgrnam('nobody').gr_gid
|
group_id = grp.getgrnam('nobody').gr_gid
|
||||||
|
|
||||||
obj = self.isolation.parsejson(self.get()['body'])
|
obj = self.getjson()['body']
|
||||||
|
|
||||||
self.assertTrue(obj['UID'] != 0, 'uid not zero')
|
self.assertTrue(obj['UID'] != 0, 'uid not zero')
|
||||||
self.assertTrue(obj['GID'] != 0, 'gid not zero')
|
self.assertTrue(obj['GID'] != 0, 'gid not zero')
|
||||||
@@ -68,7 +68,7 @@ class TestGoIsolation(TestApplicationGo):
|
|||||||
|
|
||||||
self.conf_isolation({"namespaces": {"credential": True}})
|
self.conf_isolation({"namespaces": {"credential": True}})
|
||||||
|
|
||||||
obj = self.isolation.parsejson(self.get()['body'])
|
obj = self.getjson()['body']
|
||||||
|
|
||||||
# default uid and gid maps current user to nobody
|
# default uid and gid maps current user to nobody
|
||||||
self.assertEqual(obj['UID'], user_id, 'uid nobody')
|
self.assertEqual(obj['UID'], user_id, 'uid nobody')
|
||||||
@@ -86,7 +86,7 @@ class TestGoIsolation(TestApplicationGo):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
obj = self.isolation.parsejson(self.get()['body'])
|
obj = self.getjson()['body']
|
||||||
|
|
||||||
self.assertEqual(obj['UID'], user_id, 'uid match')
|
self.assertEqual(obj['UID'], user_id, 'uid match')
|
||||||
self.assertEqual(obj['GID'], group_id, 'gid match')
|
self.assertEqual(obj['GID'], group_id, 'gid match')
|
||||||
@@ -105,7 +105,7 @@ class TestGoIsolation(TestApplicationGo):
|
|||||||
{"namespaces": {"mount": True, "credential": True}}
|
{"namespaces": {"mount": True, "credential": True}}
|
||||||
)
|
)
|
||||||
|
|
||||||
obj = self.isolation.parsejson(self.get()['body'])
|
obj = self.getjson()['body']
|
||||||
|
|
||||||
# all but user and mnt
|
# all but user and mnt
|
||||||
allns = list(self.available['features']['isolation'].keys())
|
allns = list(self.available['features']['isolation'].keys())
|
||||||
@@ -139,7 +139,7 @@ class TestGoIsolation(TestApplicationGo):
|
|||||||
self.load('ns_inspect')
|
self.load('ns_inspect')
|
||||||
self.conf_isolation({"namespaces": {"pid": True, "credential": True}})
|
self.conf_isolation({"namespaces": {"pid": True, "credential": True}})
|
||||||
|
|
||||||
obj = self.isolation.parsejson(self.get()['body'])
|
obj = self.getjson()['body']
|
||||||
|
|
||||||
self.assertEqual(obj['PID'], 1, 'pid of container is 1')
|
self.assertEqual(obj['PID'], 1, 'pid of container is 1')
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ class TestGoIsolation(TestApplicationGo):
|
|||||||
|
|
||||||
self.conf_isolation({"namespaces": namespaces})
|
self.conf_isolation({"namespaces": namespaces})
|
||||||
|
|
||||||
obj = self.isolation.parsejson(self.get()['body'])
|
obj = self.getjson()['body']
|
||||||
|
|
||||||
for ns in allns:
|
for ns in allns:
|
||||||
if ns.upper() in obj['NS']:
|
if ns.upper() in obj['NS']:
|
||||||
|
|||||||
@@ -82,6 +82,3 @@ class TestFeatureIsolation(TestApplicationProto):
|
|||||||
data = int(os.readlink(nspath)[len(nstype) + 2 : -1])
|
data = int(os.readlink(nspath)[len(nstype) + 2 : -1])
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def parsejson(self, data):
|
|
||||||
return json.loads(data)
|
|
||||||
|
|||||||
@@ -122,6 +122,9 @@ class TestHTTP(TestUnit):
|
|||||||
encoding
|
encoding
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if 'json' in kwargs:
|
||||||
|
resp = self._parse_json(resp)
|
||||||
|
|
||||||
if 'start' not in kwargs:
|
if 'start' not in kwargs:
|
||||||
sock.close()
|
sock.close()
|
||||||
return resp
|
return resp
|
||||||
@@ -230,6 +233,23 @@ class TestHTTP(TestUnit):
|
|||||||
|
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
def _parse_json(self, resp):
|
||||||
|
headers = resp['headers']
|
||||||
|
|
||||||
|
self.assertIn('Content-Type', headers, 'Content-Type header set')
|
||||||
|
self.assertEqual(
|
||||||
|
headers['Content-Type'],
|
||||||
|
'application/json',
|
||||||
|
'Content-Type header is application/json',
|
||||||
|
)
|
||||||
|
|
||||||
|
resp['body'] = json.loads(resp['body'])
|
||||||
|
|
||||||
|
return resp
|
||||||
|
|
||||||
|
def getjson(self, **kwargs):
|
||||||
|
return self.get(json=True, **kwargs)
|
||||||
|
|
||||||
def waitforsocket(self, port):
|
def waitforsocket(self, port):
|
||||||
ret = False
|
ret = False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user