def test_generate_link_and_create_realm(self) -> None:
        email = "*****@*****.**"
        generated_link = generate_realm_creation_url(by_admin=True)

        # Get realm creation page
        result = self.client_get(generated_link)
        self.assert_in_success_response(["Create a new Zulip organization"],
                                        result)

        # Enter email
        with self.assertRaises(Realm.DoesNotExist):
            get_realm("test")
        result = self.client_post(generated_link, {"email": email})
        self.assertEqual(result.status_code, 302)
        self.assertTrue(
            re.search(r"/accounts/do_confirm/\w+$", result["Location"]))

        # Bypass sending mail for confirmation, go straight to creation form
        result = self.client_get(result["Location"])
        self.assert_in_response('action="/accounts/register/"', result)

        # Original link is now dead
        result = self.client_get(generated_link)
        self.assert_in_success_response(
            ["The organization creation link has expired or is not valid."],
            result)
    def test_generate_link_and_create_realm(self) -> None:
        email = "*****@*****.**"
        generated_link = generate_realm_creation_url()

        with self.settings(OPEN_REALM_CREATION=False):
            # Check realm creation page is accessible
            result = self.client_get(generated_link)
            self.assert_in_success_response(
                [u"Create a new Zulip organization"], result)

            # Create Realm with generated link
            self.assertIsNone(get_realm('test'))
            result = self.client_post(generated_link, {'email': email})
            self.assertEqual(result.status_code, 302)
            self.assertTrue(result["Location"].endswith(
                "/accounts/send_confirm/%s" % (email, )))
            result = self.client_get(result["Location"])
            self.assert_in_response("Check your email so we can get started.",
                                    result)

            # Generated link used for creating realm
            result = self.client_get(generated_link)
            self.assert_in_success_response([
                "The organization creation link has expired or is not valid."
            ], result)
    def test_generate_link_and_create_realm(self):
        # type: () -> None
        username = "******"
        domain = "test.com"
        email = "*****@*****.**"
        generated_link = generate_realm_creation_url()

        with self.settings(OPEN_REALM_CREATION=False):
            # Check realm creation page is accessible
            result = self.client_get(generated_link)
            self.assertEquals(result.status_code, 200)
            self.assert_in_response(u"Let's get started…", result)

            # Create Realm with generated link
            self.assertIsNone(get_realm(domain))
            result = self.client_post(generated_link, {'email': email})
            self.assertEquals(result.status_code, 302)
            self.assertTrue(result["Location"].endswith(
                    "/accounts/send_confirm/%s@%s" % (username, domain)))
            result = self.client_get(result["Location"])
            self.assert_in_response("Check your email so we can get started.", result)

            # Generated link used for creating realm
            result = self.client_get(generated_link)
            self.assertEquals(result.status_code, 200)
            self.assert_in_response("The organization creation link has been expired or is not valid.", result)
 def handle(self, *args, **options):
     # type: (*Any, **Any) -> None
     url = generate_realm_creation_url()
     self.stdout.write("\033[1;92mOne time organization creation link generated\033[0m")
     self.stdout.write(
         "\033[1;92m=> Please visit \033[4m%s\033[0m \033[1;92mto " "create the organization\033[0m" % (url)
     )
Example #5
0
 def handle(self, *args, **options):
     # type: (*Any, **Any) -> None
     url = generate_realm_creation_url()
     self.stdout.write(
         "\033[1;92mOne time organization creation link generated\033[0m")
     self.stdout.write(
         "\033[1;92m=> Please visit \033[4m%s\033[0m \033[1;92mto "
         "create the organization\033[0m" % (url))
Example #6
0
 def handle(self, *args, **options):
     # type: (*Any, **Any) -> None
     url = generate_realm_creation_url()
     self.stdout.write(
         "\033[1;92mPlease visit the following secure single-use link to register your ")
     self.stdout.write("new Zulip organization:\033[0m")
     self.stdout.write("")
     self.stdout.write("    \033[1;92m%s\033[0m" % (url,))
     self.stdout.write("")
    def test_realm_creation_with_expired_link(self) -> None:
        generated_link = generate_realm_creation_url(by_admin=True)
        key = generated_link[-24:]
        # Manually expire the link by changing the date of creation
        obj = RealmCreationKey.objects.get(creation_key=key)
        obj.date_created = obj.date_created - timedelta(days=settings.REALM_CREATION_LINK_VALIDITY_DAYS + 1)
        obj.save()

        result = self.client_get(generated_link)
        self.assert_in_success_response(["The organization creation link has expired or is not valid."], result)
Example #8
0
    def test_realm_creation_with_expired_link(self) -> None:
        generated_link = generate_realm_creation_url(by_admin=True)
        key = generated_link[-24:]
        # Manually expire the link by changing the date of creation
        obj = RealmCreationKey.objects.get(creation_key=key)
        obj.date_created = obj.date_created - timedelta(days=settings.REALM_CREATION_LINK_VALIDITY_DAYS + 1)
        obj.save()

        result = self.client_get(generated_link)
        self.assert_in_success_response(["The organization creation link has expired or is not valid."], result)
    def test_realm_creation_with_expired_link(self):
        # type: () -> None
        with self.settings(OPEN_REALM_CREATION=False):
            generated_link = generate_realm_creation_url()
            key = generated_link[-40:]
            # Manually expire the link by changing the date of creation
            obj = RealmCreationKey.objects.get(creation_key=key)
            obj.date_created = obj.date_created - timedelta(days=settings.REALM_CREATION_LINK_VALIDITY_DAYS + 1)
            obj.save()

            result = self.client_get(generated_link)
            self.assertEquals(result.status_code, 200)
            self.assert_in_response("The organization creation link has been expired or is not valid.", result)
    def test_generate_link_confirm_email(self) -> None:
        email = "*****@*****.**"
        generated_link = generate_realm_creation_url(by_admin=False)

        result = self.client_post(generated_link, {'email': email})
        self.assertEqual(result.status_code, 302)
        self.assertTrue(re.search('/accounts/new/send_confirm/{}$'.format(email),
                                  result["Location"]))
        result = self.client_get(result["Location"])
        self.assert_in_response("Check your email so we can get started", result)

        # Original link is now dead
        result = self.client_get(generated_link)
        self.assert_in_success_response(["The organization creation link has expired or is not valid."], result)
Example #11
0
    def test_generate_link_confirm_email(self) -> None:
        email = "*****@*****.**"
        generated_link = generate_realm_creation_url(by_admin=False)

        result = self.client_post(generated_link, {'email': email})
        self.assertEqual(result.status_code, 302)
        self.assertTrue(re.search('/accounts/send_confirm/{}$'.format(email),
                                  result["Location"]))
        result = self.client_get(result["Location"])
        self.assert_in_response("Check your email so we can get started", result)

        # Original link is now dead
        result = self.client_get(generated_link)
        self.assert_in_success_response(["The organization creation link has expired or is not valid."], result)
    def handle(self, *args: Any, **options: Any) -> None:
        try:
            # first check if the db has been initalized
            Realm.objects.first()
        except ProgrammingError:
            print("The Zulip database does not appear to exist. Have you run initialize-database?")
            sys.exit(1)

        url = generate_realm_creation_url()
        self.stdout.write(self.style.SUCCESS("Please visit the following secure single-use link to register your "))
        self.stdout.write(self.style.SUCCESS("new Zulip organization:\033[0m"))
        self.stdout.write("")
        self.stdout.write(self.style.SUCCESS("    \033[1;92m%s\033[0m" % (url,)))
        self.stdout.write("")
    def handle(self, *args: Any, **options: Any) -> None:
        try:
            # first check if the db has been initalized
            Realm.objects.first()
        except ProgrammingError:
            print("The Zulip database does not appear to exist. Have you run initialize-database?")
            sys.exit(1)

        url = generate_realm_creation_url()
        self.stdout.write(self.style.SUCCESS("Please visit the following secure single-use link to register your "))
        self.stdout.write(self.style.SUCCESS("new Zulip organization:\033[0m"))
        self.stdout.write("")
        self.stdout.write(self.style.SUCCESS("    \033[1;92m%s\033[0m" % (url,)))
        self.stdout.write("")
    def handle(self, *args: Any, **options: Any) -> None:
        try:
            # first check if the db has been initialized
            Realm.objects.first()
        except ProgrammingError:
            raise CommandError("The Zulip database does not appear to exist. "
                               "Have you run initialize-database?")

        url = generate_realm_creation_url(by_admin=True)
        self.stdout.write(self.style.SUCCESS("Please visit the following "
                                             "secure single-use link to register your "))
        self.stdout.write(self.style.SUCCESS("new Zulip organization:\033[0m"))
        self.stdout.write("")
        self.stdout.write(self.style.SUCCESS(f"    \033[1;92m{url}\033[0m"))
        self.stdout.write("")
    def test_generate_link_and_create_realm(self) -> None:
        email = "*****@*****.**"
        generated_link = generate_realm_creation_url(by_admin=True)

        # Get realm creation page
        result = self.client_get(generated_link)
        self.assert_in_success_response([u"Create a new Zulip organization"], result)

        # Enter email
        self.assertIsNone(get_realm('test'))
        result = self.client_post(generated_link, {'email': email})
        self.assertEqual(result.status_code, 302)
        self.assertTrue(re.search(r'/accounts/do_confirm/\w+$', result["Location"]))

        # Bypass sending mail for confirmation, go straight to creation form
        result = self.client_get(result["Location"])
        self.assert_in_response('action="/accounts/register/"', result)

        # Original link is now dead
        result = self.client_get(generated_link)
        self.assert_in_success_response(["The organization creation link has expired or is not valid."], result)
    def test_generate_link_and_create_realm(self) -> None:
        email = "*****@*****.**"
        generated_link = generate_realm_creation_url()

        with self.settings(OPEN_REALM_CREATION=False):
            # Check realm creation page is accessible
            result = self.client_get(generated_link)
            self.assert_in_success_response([u"Create a new Zulip organization"], result)

            # Create Realm with generated link
            self.assertIsNone(get_realm('test'))
            result = self.client_post(generated_link, {'email': email})
            self.assertEqual(result.status_code, 302)
            self.assertTrue(result["Location"].endswith(
                "/accounts/send_confirm/%s" % (email,)))
            result = self.client_get(result["Location"])
            self.assert_in_response("Check your email so we can get started.", result)

            # Generated link used for creating realm
            result = self.client_get(generated_link)
            self.assert_in_success_response(["The organization creation link has expired or is not valid."], result)