예제 #1
0
 def test_save_multiple_userinfo(self):
     '''
   check if we can hold multiple user accounts
   '''
     self.new_userinfo.save_userinfo()
     test_userinfo = Userinfo("andrew", "password")
     test_userinfo.save_userinfo()
     self.assertEqual(len(Userinfo.userinfo_list), 2)
 def test_save_multiple_userinfo(self):
     '''
         test_save_multiple_userinfo to check if we can save multiple users
         objects to our users_list
         '''
     self.new_userinfo.save_userinfo()
     test_userinfo = Userinfo("clement", "125")  # new contact
     test_userinfo.save_userinfo()
     self.assertEqual(len(Userinfo.users_list), 2)
예제 #3
0
    def test_delete_userinfo(self):
        '''
      test_delete_user to test if we can remove a user from our user list
      '''
        self.new_userinfo.save_userinfo()
        test_userinfo = Userinfo("michael", "password")
        test_userinfo.save_userinfo()

        self.new_userinfo.delete_userinfo()
        self.assertEqual(len(Userinfo.userinfo_list), 1)
    def test_userinfo_exists(self):
        '''
        test to check if we can return a Boolean  if we cannot find the user.
        '''

        self.new_userinfo.save_userinfo()
        test_userinfo = Userinfo("clement", "125")  # new contact
        test_userinfo.save_userinfo()

        userinfo_exists = Userinfo.userinfo_exist("clement")

        self.assertTrue(userinfo_exists)
    def test_find_user_by_user_name(self):
        '''
        test to check if we can find a user by username  and display information
        '''

        self.new_userinfo.save_userinfo()
        test_userinfo = Userinfo("clement", "125")  # new contact
        test_userinfo.save_userinfo()

        found_userinfo = Userinfo.find_by_user_name("clement")

        self.assertEqual(found_userinfo.password, test_userinfo.password)
예제 #6
0
def get_add_other_info(task_detail):
    tw_mail_account = task_detail['tw_mail_account']
    tw_phone_account = task_detail['tw_phone_account']
    if tw_mail_account:
        account_name = tw_mail_account
    else:
        account_name = tw_phone_account
    password = task_detail['password']
    nick_name = str(task_detail['nick_name'])
    try:
        user = Userinfo(account_name, password)
        info_dict = user.getUserinfo()
    except Exception,e:
        print e
        return 'account error'
예제 #7
0
def create_userinfo(username, password):
    '''
    Function to create a new user
    '''
    new_userinfo = Userinfo(username, password)
    return new_userinfo
예제 #8
0
    def add_users(self, rootcmd):
        userinfo = Userinfo(self.profile_dir)
        userlist = []
        for user in userinfo.allusers():
            # Only include if the user does not yet exist
            if runcmd('bash -c "grep \"^%s\" %s/etc/passwd || echo -"'
                    % (user, self.installation_dir))[1][0] != '-':
                comment("(WARNING): User '%s' exists already" % user)
            else:
                userlist.append(user)

        # Only continue if there are new users in the list
        if rootcmd:
            clist = [('root', rootcmd + ' %s')]
        else:
            if userlist == []:
                return True
            clist = []

        # Save system files and replace them by the overlay versions
        savedir = self.larchify_dir + '/save_etc'
        runcmd('rm -rf %s' % savedir)
        runcmd('mkdir -p %s/default' % savedir)
        savelist = 'group,gshadow,passwd,shadow,login.defs,skel'
        runcmd('bash -c "cp -a %s/etc/{%s} %s"'
                % (self.installation0, savelist, savedir))
        runcmd('cp -a %s/etc/default/useradd %s/default'
                % (self.installation0, savedir))
        for f in ('group', 'gshadow', 'passwd', 'shadow', 'login.defs'):
            if os.path.isfile(self.overlay + '/etc/%s'):
                runcmd('cp %s/etc/%s %s/etc'
                        % (self.overlay, f, self.installation0))
        if os.path.isfile(self.overlay + '/etc/default/useradd'):
            runcmd('cp %s/etc/default/useradd %s/etc/default'
                    % (self.overlay, self.installation0))
        if os.path.isdir(self.overlay + '/etc/skel'):
            runcmd('cp -r %s/etc/skel %s/etc'
                    % (self.overlay, self.installation0))

        # Build the useradd command
        userdir0 = '/users'
        userdir = self.larchify_dir + userdir0
        userdirs = []
        runcmd('mkdir -p %s/home' % self.overlay)
        for u in userlist:
            cline = 'useradd -m'
            pgroup = userinfo.get(u, 'maingroup')
            if pgroup:
                cline += ' -g ' + pgroup
            uid = userinfo.get(u, 'uid')
            if uid:
                cline += ' -u ' + uid
            pw = userinfo.get(u, 'pw')
            if (pw == ''):
                # Passwordless login
                pwcrypt = ''
            else:
                # Normal MD5 password
                pwcrypt = encryptPW(pw)
            cline += " -p '%s'" % pwcrypt
            skeldir = userinfo.get(u, 'skel')
            if skeldir:
                # Custom home initialization directories in the profile
                # always start with 'skel_'
                skel = 'skel_' + skeldir
                if skel not in userdirs:
                    userdirs.append(skel)
                cline += ' -k %s/%s' % (CHROOT_DIR_LARCHIFY + userdir0,
                        skel)
            # Allow for expert tweaking
            cline += ' ' + userinfo.get(u, 'expert')
            # The user and the command to be run
            clist.append((u, cline + ' %s'))
            xgroups = userinfo.get(u, 'xgroups')
            if xgroups:
                xgl = []
                for g in xgroups.split(','):
                    clist.append((u, 'usermod -a -G %s %%s' % g))

        if userdirs:
            # Copy custom 'skel' directories to build space
            runcmd('rm -rf %s' % userdir)
            runcmd('mkdir -p %s' % userdir)
            for ud in userdirs:
                runcmd('cp -r %s/%s %s/%s' %
                        (self.profile_dir, ud, userdir, ud))

        nfail = 0
        ok = True
        for u, cmd in clist:
            if not chroot(self.installation0, cmd % u):
                nfail += 1
                # Errors adding users to groups are not fatal:
                if not cmd.startswith('usermod -a -G'):
                    ok = False
            if os.path.isdir('%s/home/%s' % (self.installation0, u)):
                runcmd('mv %s/home/%s %s/home'
                        % (self.installation0, u, self.overlay))

        if nfail > 0:
            errout(_("%d user account operation(s) failed") % nfail, 0)
        # Move changed /etc/{group,gshadow,passwd,shadow} to overlay
        runcmd('bash -c "mv %s/etc/{group,gshadow,passwd,shadow} %s/etc"'
                % (self.installation0, self.overlay))
        # Restore system files in base installation
        runcmd('rm -rf %s/etc/skel' % self.installation0)
        runcmd('bash -c "cp -a %s/* %s/etc"'
                % (savedir, self.installation0))
        return ok
 def setUp(self):
     '''
     Set up method to run before each test cases.
     '''
     self.new_userinfo = Userinfo("clemence",
                                  "125")  # create contact object
예제 #10
0
    def setUp(self):

        self.new_userinfo = Userinfo("michael",
                                     "password")  # create user object
예제 #11
0
파일: project.py 프로젝트: cjchung/main
 def newUserinfo(self):
     self.userInfo = Userinfo(self.profile_path)
     return (True, None)