def test001_add_record(self): """ TFGW-006 *Test case for adding a record to (coredns and tcprouter) and try to access a website through them. * **Test Scenario:** #. Create a coredns record. #. Create a tcprouter record. #. Try to access the website(facebook), should success. """ self.log("Create a coredns record.") coredns.create_a_record("facebook", [{"ip": "127.0.0.1"}]) self.log("Create a tcprouter record.") tcprouter.create_service(name="facebook", sni="facebook.bots.grid.tf", addr="102.132.97.35:443") time.sleep(11) self.log("Try to access the website(facebook), should success.") with self.assertRaises(requests.exceptions.SSLError) as e: requests.get("https://facebook.bots.grid.tf") error = e.exception.args[0].args[0] self.assertIn("facebook.com", error)
def setUpClass(cls): self = cls() cls.backup = self.backup_file(path="/etc/resolv.conf") self.wirte_file(path="/etc/resolv.conf", content="nameserver localhost") os.system("tmux new-session -d -s redis 'redis-server';") time.sleep(2) coredns.create_a_record("facebook", [{"ip": "127.0.0.1"}]) os.system( "tmux new-session -d -s coredns '/usr/bin/coredns -conf corefile';" ) os.system("tmux new-session -d -s tcprouter 'tcprouter router.toml';") time.sleep(5)
def test006_catch_all_record(self): """ TFGW-011 * Test case for catch_all record of tcprouter. * **Test Scenario:** #. Create (coredns and tcprouter) records for bing. #. Create coredns record for facebook. #. Create catch_all tcprouter record for facebook. #. Try to access facebook using any subdomain, should success. #. Try to access bing, should be accessed not facebook. """ self.log("Create (coredns and tcprouter) records for bing.") coredns.create_a_record("bing", [{"ip": "127.0.0.1"}]) tcprouter.create_service(name="bing", sni="bing.bots.grid.tf", addr="13.107.21.200:443") self.log("Create coredns record for facebook.") coredns.create_a_record("facebook", [{"ip": "127.0.0.1"}]) self.log("Create catch_all tcprouter record for facebook.") tcprouter.create_service(name="CATCH_ALL", sni="CATCH_ALL", addr="102.132.97.35:443") time.sleep(11) self.log("Try to access facebook using any subdomain, should success.") with self.assertRaises(requests.exceptions.SSLError) as e: requests.get("https://facebook.bots.grid.tf") error = e.exception.args[0].args[0] self.assertIn("facebook.com", error) self.log("Try to access bing, should be accessed not facebook.") with self.assertRaises(requests.exceptions.SSLError) as e: requests.get("https://bing.bots.grid.tf") error = e.exception.args[0].args[0] self.assertIn("bing.com", error)
def test003_modify_records(self): """ TFGW-008 *Test case for modifying tcprouter records and try to access websites through them* **Test Scenario:** #. Create a tcprouter record for google. #. Try to access google, should success. #. Modify google tcprouter record with facebook ip. #. Try to access facebook through google record, should success. """ self.log("Create a tcprouter record for google.") coredns.create_a_record("google", [{"ip": "127.0.0.1"}]) tcprouter.create_service(name="google", sni="google.bots.grid.tf", addr="172.217.19.46:443") time.sleep(11) self.log("Try to access google, should success.") with self.assertRaises(requests.exceptions.SSLError) as e: requests.get("https://google.bots.grid.tf") error = e.exception.args[0].args[0] self.assertIn("google.com", error) self.log("Modify google tcprouter record with facebook ip.") tcprouter.create_service(name="google", sni="google.bots.grid.tf", addr="102.132.97.35:443") time.sleep(11) self.log( "Try to access facebook through google record, should success.") with self.assertRaises(requests.exceptions.SSLError) as e: requests.get("https://google.bots.grid.tf") error = e.exception.args[0].args[0] self.assertIn("facebook.com", error)
def test005_delete_coredns_records(self): """ TFGW-010 * Test case for deleting coredns records and making sure that websites can't be accessed. * **Test Scenario:** #. Create (coredns and tcprouter) records for facebook. #. Create (coredns and tcprouter) records for bing. #. Create (coredns and tcprouter) records for google. #. Delete google and facebook records from self. #. Try to access facebook or google, should fail. #. Try to access bing, should success. """ self.log("Create (coredns and tcprouter) records for facebook.") coredns.create_a_record("facebook", [{"ip": "127.0.0.1"}]) tcprouter.create_service(name="facebook", sni="facebook.bots.grid.tf", addr="102.132.97.35:443") self.log("Create (coredns and tcprouter) records for bing.") coredns.create_a_record("bing", [{"ip": "127.0.0.1"}]) tcprouter.create_service(name="bing", sni="bing.bots.grid.tf", addr="13.107.21.200:443") self.log("Create (coredns and tcprouter) records for google.") coredns.create_a_record("google", [{"ip": "127.0.0.1"}]) tcprouter.create_service(name="google", sni="google.bots.grid.tf", addr="172.217.19.46:443") time.sleep(11) self.log("Delete google and facebook records from tcprouter.") self.delete_coredns_record("facebook") self.delete_coredns_record("google") time.sleep(11) self.log("Try to access facebook or google, should fail.") with self.assertRaises(requests.exceptions.ConnectionError): requests.get("https://facebook.bots.grid.tf", timeout=10) with self.assertRaises(requests.exceptions.ConnectionError): requests.get("https://google.bots.grid.tf", timeout=10) self.log("Try to access bing, should success.") with self.assertRaises(requests.exceptions.SSLError) as e: requests.get("https://bing.bots.grid.tf") error = e.exception.args[0].args[0] self.assertIn("bing.com", error)
def test002_add_more_records(self): """ TFGW-007 *Test case for adding records to (coredns and tcprouter) and try to access websites through them. * **Test Scenario:** #. Create (coredns and tcprouter) records for facebook. #. Create (coredns and tcprouter) records for bing. #. Create (coredns and tcprouter) records for google. #. Try to access facebook, bing and google through (coredns and tcprouter) records, should success. """ self.log("Create (coredns and tcprouter) records for facebook.") coredns.create_a_record("facebook", [{"ip": "127.0.0.1"}]) tcprouter.create_service(name="facebook", sni="facebook.bots.grid.tf", addr="102.132.97.35:443") self.log("Create (coredns and tcprouter) records for bing.") coredns.create_a_record("bing", [{"ip": "127.0.0.1"}]) tcprouter.create_service(name="bing", sni="bing.bots.grid.tf", addr="13.107.21.200:443") self.log("Create (coredns and tcprouter) records for google.") coredns.create_a_record("google", [{"ip": "127.0.0.1"}]) tcprouter.create_service(name="google", sni="google.bots.grid.tf", addr="172.217.19.46:443") time.sleep(11) self.log( "Try to access facebook, bing and google through tcprouter records, should success." ) with self.assertRaises(requests.exceptions.SSLError) as e: requests.get("https://facebook.bots.grid.tf") error = e.exception.args[0].args[0] self.assertIn("facebook.com", error) with self.assertRaises(requests.exceptions.SSLError) as e: requests.get("https://bing.bots.grid.tf") error = e.exception.args[0].args[0] self.assertIn("bing.com", error) with self.assertRaises(requests.exceptions.SSLError) as e: requests.get("https://google.bots.grid.tf") error = e.exception.args[0].args[0] self.assertIn("google.com", error)