Example #1
0
 def get_users_and_groups(self, args):
     """
     Called by the app to get users and groups.  This method is usually overwritten.
     :param args: Passed in arguments.
     :type args: argparse.Namespace
     :return: Users and groups that were read.
     :rtype: UsersAndGroups
     """
     sync = SyncUserAndGroups(tsurl=args.ts_url, username=args.username,
                              password=args.password, disable_ssl=args.disable_ssl)
     ugs = sync.get_all_users_and_groups()
     #print(ugs.to_json())
     return ugs
Example #2
0
    def test_syncing_user_and_groups_without_password(self):
        """
        Tests adding users and groups to ThoughtSpot.
        """

        auag = UsersAndGroups()

        auag.add_group(
            Group(
                name="Group 1",
                display_name="This is Group 1",
                description="A group for testing.",
                group_names=[],
            )
        )
        auag.add_group(
            Group(
                name="Group 2",
                display_name="This is Group 2",
                description="Another group for testing.",
                group_names=["Group 1"],
            )
        )

        auag.add_user(
            User(
                name="User1",
                password="******",
                display_name="User 1",
                mail="*****@*****.**",
                group_names=["Group 1"],
            )
        )
        auag.add_user(
            User(
                name="User2",
                password="******",
                mail="*****@*****.**",
                display_name="User 2",
                group_names=["Group 1", "Group 2"],
            )
        )

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            global_password="******",
            disable_ssl=True,
        )
        sync.sync_users_and_groups(auag)
    def test_delete_one_group(self):
        """Tests deleting a single groups."""

        self.create_common_users_and_groups()

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        sync.delete_group(groupname="Group1")
        auag = sync.get_all_users_and_groups()
        self.assertFalse(auag.has_group("Group1"))
        self.assertTrue(auag.has_group("Group2"))
        self.assertTrue(auag.has_group('Group"3"'))
    def test_delete_user_list(self):
        """Tests deleting of a list of users."""

        self.create_common_users_and_groups()

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        sync.delete_users(usernames=["User1", "User2", "UserX"])
        auag = sync.get_all_users_and_groups()
        self.assertFalse(auag.has_user("User1"))
        self.assertFalse(auag.has_user("User2"))
        self.assertTrue(auag.has_user('User"3"'))
Example #5
0
 def write_user_and_groups(self, args, ugs):
     """
     Writes the users and groups.
     :param args: Command line arguments for writing.
     :type args: argparse.Namespace
     :param ugs: Users and groups to write.
     :type ugs: UsersAndGroups
     :return:  None
     """
     sync = SyncUserAndGroups(tsurl=args.ts_url, username=args.username,
                              password=args.password,
                              disable_ssl=args.disable_ssl)
     sync.sync_users_and_groups(users_and_groups=ugs,
                                apply_changes=args.apply_changes,
                                remove_deleted=args.remove_deleted,
                                batch_size=args.batch_size, merge_groups=args.merge_groups)
Example #6
0
    def test_getting_all(self):
        """
        Tests getting all users from the server.
        """

        self.create_common_users_and_groups()

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        auag = sync.get_all_users_and_groups()

        # There are four constant users, tsadmin, guest, su, system
        self.assertEqual(9, auag.number_users())
        # There are two constant groups, Administrator and System
        self.assertEqual(10, auag.number_groups())
Example #7
0
    def test_syncing_user_and_groups(self):
        """
        Tests adding users and groups to ThoughtSpot.
        """

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        auag = sync.get_all_users_and_groups()

        group1 = auag.get_group("Group 1")
        self.assertEqual("Group 1", group1.name)
        self.assertEqual("This is Group 1", group1.displayName)
        self.assertEqual("A group for testing.", group1.description)
        self.assertEqual([], group1.groupNames)
        self.assertEqual(Visibility.DEFAULT, group1.visibility)

        group2 = auag.get_group("Group 2")
        self.assertEqual("Group 2", group2.name)
        self.assertEqual("This is Group 2", group2.displayName)
        self.assertEqual("Another group for testing.", group2.description)
        self.assertEqual(["Group 1"], group2.groupNames)
        self.assertEqual(Visibility.NON_SHAREABLE, group2.visibility)

        user1 = auag.get_user("User1")
        self.assertEqual("User1", user1.name)
        self.assertEqual("User 1", user1.displayName)
        self.assertEquals(["Group 1", "All"], user1.groupNames)
        self.assertEqual(Visibility.DEFAULT, user1.visibility)

        user2 = auag.get_user("User2")
        self.assertEqual("User2", user2.name)
        self.assertEqual("User 2", user2.displayName)
        self.assertEqual(
            sorted(["All", "Group 1", "Group 2"]), sorted(user2.groupNames)
        )
        self.assertEqual(Visibility.NON_SHAREABLE, user2.visibility)
def run_app():
    """Runs the application to delete users and groups."""
    args = get_args()
    if valid_args(args=args):
        sync = SyncUserAndGroups(tsurl=args.ts_url,
                                 username=args.username,
                                 password=args.password,
                                 disable_ssl=args.disable_ssl)

        if args.users:
            delete_users(args, sync)
        if args.groups:
            delete_groups(args, sync)
        if args.user_file:
            delete_users_from_file(args, sync)
        if args.group_file:
            delete_groups_from_file(args, sync)
Example #9
0
    def test_update_password(self):
        """
        Tests updating a user password.
        """

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        auag = UsersAndGroups()
        auag.add_user(
            User(name="userx", mail="*****@*****.**", display_name="User X", password="******")
        )
        # sync updates
        sync.sync_users_and_groups(users_and_groups=auag)
        sync.update_user_password(
            userid="userx", currentpassword=TS_PASSWORD, password="******"
        )
Example #10
0
    def test_update_non_shareable(self):
        """
        Tests updating groups that are non-shareable.
        """
        self.create_common_users_and_groups()
        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        auag = sync.get_all_users_and_groups()

        # Need to remove the common users since they don't have emails.
        auag.remove_user("guest")
        auag.remove_user("su")
        auag.remove_user("system")
        auag.remove_user("tsadmin")

        # Change Group 1 and Group 2 and verify change took.
        group1 = auag.get_group("Group 1")
        group1.visibility = Visibility.NON_SHAREABLE
        group2 = auag.get_group("Group 2")
        group2.visibility = Visibility.DEFAULT

        # sync updates
        sync.sync_users_and_groups(users_and_groups=auag)

        # verify changes
        auag = sync.get_all_users_and_groups()
        self.assertEqual(
            auag.get_group("Group 1").visibility, Visibility.NON_SHAREABLE
        )
        self.assertEqual(
            auag.get_group("Group 2").visibility, Visibility.DEFAULT
        )
        self.assertEqual(
            auag.get_group('Group "3"').visibility, Visibility.NON_SHAREABLE
        )
    def create_common_users_and_groups(self):
        """
        Creates a set of users and groups that can be used in multiple tests.
        """
        auag = UsersAndGroups()

        auag.add_group(
            Group(
                name="Group1",
                display_name="This is Group 1",
                description="A group for testing.",
                group_names=[],
                visibility=Visibility.DEFAULT,
            )
        )
        auag.add_group(
            Group(
                name="Group2",
                display_name="This is Group 2",
                description="Another group for testing.",
                group_names=["Group1"],
                visibility=Visibility.NON_SHAREABLE,
            )
        )
        # Testing for ability to handle embedded quotes.
        auag.add_group(
            Group(
                name='Group"3"',
                display_name='This is Group "3"',
                description='Another "group" for testing.',
                group_names=["Group1"],
                visibility=Visibility.NON_SHAREABLE,
            )
        )

        auag.add_user(
            User(
                name="User1",
                password="******",
                display_name="User 1",
                mail="*****@*****.**",
                group_names=["Group1"],
            )
        )
        auag.add_user(
            User(
                name="User2",
                password="******",
                display_name="User 2",
                mail="*****@*****.**",
                group_names=["Group1", "Group2"],
                visibility=Visibility.NON_SHAREABLE,
            )
        )
        auag.add_user(
            User(
                name='User"3"',
                password="******",
                display_name='User "3"',
                mail="*****@*****.**",
                group_names=['Group"3"'],
            )
        )

        print(auag)

        sync = SyncUserAndGroups(
            tsurl=TS_URL,
            username=TS_USER,
            password=TS_PASSWORD,
            disable_ssl=True,
        )
        sync.sync_users_and_groups(auag)