auth mandatory and allowping test case is added
@@ -31,6 +31,16 @@ def get_machine_detail():
class TestCommon:
+ def do_restart(self, foglamp_url):
+ conn = http.client.HTTPConnection(foglamp_url)
+ conn.request("PUT", '/foglamp/restart')
+ r = conn.getresponse()
+ assert 200 == r.status
+ r = r.read().decode()
+ jdoc = json.loads(r)
+ assert len(jdoc), "No data found"
+ assert 'FogLAMP restart has been scheduled.' == jdoc['message']
+
def test_ping_default(self, reset_and_start_foglamp, foglamp_url):
conn = http.client.HTTPConnection(foglamp_url)
conn.request("GET", '/foglamp/ping')
@@ -52,20 +62,17 @@ class TestCommon:
assert jdoc['authenticationOptional'] is True
assert jdoc['safeMode'] is False
- @pytest.mark.skip(reason='Not Implemented yet')
- def test_ping_when_auth_mandatory(self):
- # TODO: Its a bit tricky to automate user input on shell when foglamp start
- pass
-
- def test_restart(self, foglamp_url, wait_time):
+ def test_ping_when_auth_mandatory_allow_ping_true(self, foglamp_url, wait_time):
conn = http.client.HTTPConnection(foglamp_url)
- conn.request("PUT", '/foglamp/restart')
+ payload = {"allowPing": "true", "authentication": "mandatory"}
+ conn.request("PUT", '/foglamp/category/rest_api', body=json.dumps(payload))
r = conn.getresponse()
assert 200 == r.status
r = r.read().decode()
jdoc = json.loads(r)
assert len(jdoc), "No data found"
- assert 'FogLAMP restart has been scheduled.' == jdoc['message']
+
+ self.do_restart(foglamp_url)
time.sleep(wait_time * 2)
conn = http.client.HTTPConnection(foglamp_url)
@@ -78,7 +85,31 @@ class TestCommon:
assert 1 < jdoc['uptime']
assert isinstance(jdoc['uptime'], int)
- def test_shutdown(self, foglamp_url, wait_time):
+ def test_ping_when_auth_mandatory_allow_ping_false(self, reset_and_start_foglamp, foglamp_url, wait_time):
+ # reset_and_start_foglamp fixture needed to get default settings back
+ conn = http.client.HTTPConnection(foglamp_url)
+ payload = {"allowPing": "false", "authentication": "mandatory"}
+ conn.request("PUT", '/foglamp/category/rest_api', body=json.dumps(payload))
+ r = conn.getresponse()
+ assert 200 == r.status
+ r = r.read().decode()
+ jdoc = json.loads(r)
+ assert len(jdoc), "No data found"
+
+ self.do_restart(foglamp_url)
+
+ time.sleep(wait_time * 2)
+ conn = http.client.HTTPConnection(foglamp_url)
+ conn.request("GET", '/foglamp/ping')
+ r = conn.getresponse()
+ assert 403 == r.status
+ assert 'Forbidden' == r.reason
+
+ def test_restart(self):
+ assert 1, "Already verified in test_ping_when_auth_mandatory_allow_ping_true"
+
+ def test_shutdown(self, reset_and_start_foglamp, foglamp_url, wait_time):
+ # reset_and_start_foglamp fixture needed to get default settings back
conn = http.client.HTTPConnection(foglamp_url)
conn.request("PUT", '/foglamp/shutdown')
r = conn.getresponse()
