Merge pull request 'refs #2818 sincronización quitada en test' (!1120) from 2818-sincronizar-usuarios into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #1120
Reviewed-by: Juan Ferrer <juan@verdnatura.es>
This commit is contained in:
Alexandre Riera 2022-11-03 07:41:17 +00:00
commit 06f9cf8a40
2 changed files with 26 additions and 14 deletions

View File

@ -5,6 +5,8 @@ const crypto = require('crypto');
const nthash = require('smbhash').nthash;
module.exports = Self => {
const shouldSync = process.env.NODE_ENV !== 'test';
Self.getSynchronizer = async function() {
return await Self.findOne({
fields: [
@ -30,6 +32,7 @@ module.exports = Self => {
},
async syncUser(userName, info, password) {
let {
client,
accountConfig
@ -130,12 +133,13 @@ module.exports = Self => {
}));
}
if (changes.length)
if (shouldSync && changes.length)
await client.modify(dn, changes);
} else
} else if (shouldSync)
await client.add(dn, newEntry);
} else {
try {
if (shouldSync)
await client.del(dn);
console.log(` -> User '${userName}' removed from LDAP`);
} catch (e) {
@ -196,10 +200,12 @@ module.exports = Self => {
for (let group of groups) {
try {
let dn = `cn=${group},${groupDn}`;
if (shouldSync) {
await client.modify(dn, new ldap.Change({
operation,
modification: {memberUid: userName}
}));
}
} catch (err) {
if (err.name !== 'NoSuchObjectError')
throw err;
@ -266,8 +272,10 @@ module.exports = Self => {
filter: 'objectClass=posixGroup'
};
let reqs = [];
await client.searchForeach(this.groupDn, opts,
o => reqs.push(client.del(o.dn)));
await client.searchForeach(this.groupDn, opts, object => {
if (shouldSync)
reqs.push(client.del(object.dn));
});
await Promise.all(reqs);
// Recreate roles
@ -291,6 +299,7 @@ module.exports = Self => {
}
let dn = `cn=${role.name},${this.groupDn}`;
if (shouldSync)
reqs.push(client.add(dn, newEntry));
}
await Promise.all(reqs);

View File

@ -71,6 +71,9 @@ module.exports = Self => {
let isEnabled = sambaUser
&& !(sambaUser.userAccountControl & UserAccountControlFlags.ACCOUNTDISABLE);
if (process.env.NODE_ENV === 'test')
return;
if (info.hasAccount) {
if (!sambaUser) {
await sshClient.exec('samba-tool user create', [