diff --git a/accounts/templates/common/components/footer.html b/accounts/templates/common/components/footer.html index e82e052..4b6f4ba 100644 --- a/accounts/templates/common/components/footer.html +++ b/accounts/templates/common/components/footer.html @@ -13,6 +13,11 @@   About + | +   Terms of Service + +
diff --git a/dash/tests.py b/dash/tests.py index 899adea..cdf6e8b 100644 --- a/dash/tests.py +++ b/dash/tests.py @@ -77,7 +77,7 @@ def infra_custom_config(test_name: str): def create_instance_util( t: TestCase, c: Client, instance_name: str, config: InstanceConfiguration ): - payload = {"name": instance_name, "configuration": config.name} + payload = {"name": instance_name, "configuration": config.name, "tos": "agreed"} resp = c.post(reverse("dash.instances.new"), payload) t.assertEqual(resp.status_code, 302) @@ -298,3 +298,36 @@ class CreateInstance(TestCase): ).exists(), False, ) + + def test_tos_agreement_check(self): + c = Client() + login_util(self, c, "accounts.home") + urls = [(reverse("dash.instances.new"), "Instance Configuration")] + for (url, test) in urls: + print(f"[*] Testing URI: {url}") + resp = c.get(url) + self.assertEqual(resp.status_code, 200) + self.assertEqual(b"Billing" in resp.content, True) + self.assertEqual(b"Support" in resp.content, True) + self.assertEqual(b"Logout" in resp.content, True) + self.assertEqual(str.encode(test) in resp.content, True) + + # create instance + payload = { + "name": "test_tos_agreement_check", + "configuration": self.instance_config[0].name, + } + + self.assertEqual(Instance.objects.filter(name=payload["name"]).exists(), False) + resp = c.post(reverse("dash.instances.new"), payload) + self.assertEqual(resp.status_code, 400) + + self.assertEqual( + b"created without agreeing to the terms and conditions" in resp.content, + True, + ) + + instance_name = "test_create_instance_renders" + create_instance_util( + t=self, c=c, instance_name=instance_name, config=self.instance_config[0] + ) diff --git a/dash/views.py b/dash/views.py index 383a072..3e2c904 100644 --- a/dash/views.py +++ b/dash/views.py @@ -80,6 +80,21 @@ def create_instance(request): ctx = get_ctx() return render(request, "dash/instances/new/index.html", context=ctx) + if "tos" not in request.POST: + ctx = get_ctx() + ctx["error"] = { + "title": "Can't create instance", + "reason": "Hostea instance can't be created without agreeing to the terms and conditions", + } + return render(request, "dash/instances/new/index.html", status=400, context=ctx) + if str.strip(request.POST["tos"]) != "agreed": + ctx = get_ctx() + ctx["error"] = { + "title": "Can't create instance", + "reason": "Hostea instance can't be created without agreeing to the terms and conditions", + } + return render(request, "dash/instances/new/index.html", status=400, context=ctx) + name = request.POST["name"] configuration = request.POST["configuration"] try: