Ejemplo n.º 1
0
def test_openldap_hashers():
    VECTORS = map(
        str.split, '''\
coin {SHA}NHj+acfc68FPYrMipEBZ3t8ABGY=
250523 {SHA}4zuJhPW1w0upqG7beAlxDcvtBj0=
coin {SSHA}zLPxfZ3RSNkIwVdHWEyB4Tpr6fT9LiVX
coin {SMD5}+x9QkU2T/wlPp6NK3bfYYxPYwaE=
coin {MD5}lqlRm4/d0X6MxLugQI///Q=='''.splitlines())
    for password, oldap_hash in VECTORS:
        dj_hash = hashers.olap_password_to_dj(oldap_hash)
        assert check_password(password, dj_hash)
Ejemplo n.º 2
0
 def handle(self, dn, entry):
     User = get_user_model()
     if self.object_class not in entry['objectClass']:
         if self.verbosity >= 2:
             self.command.stdout.write('Ignoring entry %r' % dn)
     u = User()
     a = []
     m = []
     d = {'dn': dn}
     for key in entry:
         v = entry[key][0]
         v = v.decode('utf-8')
         for attribute in ('first_name', 'last_name', 'username', 'email', 'password'):
             if key != self.options[attribute]:
                 continue
             if attribute == 'password':
                 v = olap_password_to_dj(v)
             elif attribute == 'username' and self.options['realm']:
                 v += '@%s' % self.options['realm']
             setattr(u, attribute, v)
             d[attribute] = v
         for attribute in self.options['extra_attribute']:
             if key != attribute:
                 continue
             attribute = self.options['extra_attribute'][attribute]
             a.append((attribute, v))
             d[attribute.name] = v
     if self.callback:
         m.extend(self.callback(u, dn, entry, self.options, d))
     if 'username' not in d:
         self.log.warning('cannot load dn %s, username cannot be initialized from the field %s',
                 dn, self.options['username'])
         return
     try:
         old = User.objects.get(username=d['username'])
         u.id = old.id
     except User.DoesNotExist:
         pass
     self.log.debug('loaded user %r from ldif', d)
     self.json.append(d)
     self.users.append((u, a, m))
Ejemplo n.º 3
0
 def handle(self, dn, entry):
     User = get_user_model()
     if self.object_class not in entry['objectClass']:
         if self.verbosity >= 2:
             self.command.stdout.write('Ignoring entry %r' % dn)
     u = User()
     a = []
     m = []
     d = {'dn': dn}
     for key in entry:
         v = entry[key][0]
         v = v.decode('utf-8')
         for attribute in ('first_name', 'last_name', 'username', 'email', 'password'):
             if key != self.options[attribute]:
                 continue
             if attribute == 'password':
                 v = olap_password_to_dj(v)
             elif attribute == 'username' and self.options['realm']:
                 v += '@%s' % self.options['realm']
             setattr(u, attribute, v)
             d[attribute] = v
         for attribute in self.options['extra_attribute']:
             if key != attribute:
                 continue
             attribute = self.options['extra_attribute'][attribute]
             a.append((attribute, v))
             d[attribute.name] = v
     if self.callback:
         m.extend(self.callback(u, dn, entry, self.options, d))
     if 'username' not in d:
         self.log.warning('cannot load dn %s, username cannot be initialized from the field %s',
                 dn, self.options['username'])
         return
     try:
         old = User.objects.get(username=d['username'])
         u.id = old.id
     except User.DoesNotExist:
         pass
     self.log.debug('loaded user %r from ldif', d)
     self.json.append(d)
     self.users.append((u, a, m))