Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions oxlint-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,42 +122,6 @@
"sourceLine": "entitiesParseFunc: this.parseResourceNamesEntities,",
"fingerprint": "src/gmp/commands/resource-names.ts|typescript(unbound-method)|Avoid referencing unbound methods which may cause unintentional scoping of `this`.|33|entitiesParseFunc: this.parseResourceNamesEntities,"
},
{
"filename": "src/gmp/commands/user.ts",
"code": "typescript(no-useless-default-assignment)",
"message": "Default value is useless because the property has type `string` (not nullish). This default assignment will never be used.",
"location": {
"line": 351,
"column": 15,
"offset": 11386
},
"sourceLine": "comment = '',",
"fingerprint": "src/gmp/commands/user.ts|typescript(no-useless-default-assignment)|Default value is useless because the property has type `string` (not nullish). This default assignment will never be used.|15|comment = '',"
},
{
"filename": "src/gmp/commands/user.ts",
"code": "typescript(no-useless-default-assignment)",
"message": "Default value is useless because the property has type `string` (not nullish). This default assignment will never be used.",
"location": {
"line": 359,
"column": 16,
"offset": 11668
},
"sourceLine": "password = '', // needs to be included in httpPost, should be optional in gsad",
"fingerprint": "src/gmp/commands/user.ts|typescript(no-useless-default-assignment)|Default value is useless because the property has type `string` (not nullish). This default assignment will never be used.|16|password = '', // needs to be included in httpPost, should be optional in gsad"
},
{
"filename": "src/gmp/commands/user.ts",
"code": "typescript(no-useless-default-assignment)",
"message": "Default value is useless because the property has type `string` (not nullish). This default assignment will never be used.",
"location": {
"line": 348,
"column": 20,
"offset": 11282
},
"sourceLine": "access_hosts = '',",
"fingerprint": "src/gmp/commands/user.ts|typescript(no-useless-default-assignment)|Default value is useless because the property has type `string` (not nullish). This default assignment will never be used.|20|access_hosts = '',"
},
{
"filename": "src/gmp/http/__tests__/http.test.ts",
"code": "typescript(unbound-method)",
Expand Down Expand Up @@ -3638,18 +3602,6 @@
"sourceLine": "const {authMethod, comment, groups = [], hosts, roles = []} = entity;",
"fingerprint": "src/web/pages/users/UserDetails.tsx|typescript(no-useless-default-assignment)|Default value is useless because the property has type `Model[]` (not nullish). This default assignment will never be used.|59|const {authMethod, comment, groups = [], hosts, roles = []} = entity;"
},
{
"filename": "src/web/pages/users/UsersDialog.tsx",
"code": "typescript(no-misused-spread)",
"message": "Using the spread operator on class instances will lose their class prototype.",
"location": {
"line": 170,
"column": 5,
"offset": 4658
},
"sourceLine": "...user,",
"fingerprint": "src/web/pages/users/UsersDialog.tsx|typescript(no-misused-spread)|Using the spread operator on class instances will lose their class prototype.|5|...user,"
},
{
"filename": "src/web/pages/vulnerabilities/VulnerabilitiesListPage.tsx",
"code": "typescript(no-useless-default-assignment)",
Expand Down
27 changes: 15 additions & 12 deletions src/gmp/commands/__tests__/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,16 @@ describe('UserCommand tests', () => {
});

describe('UserCommand user lifecycle actions', () => {
const user = {
access_hosts: 'localhost',
const userData = {
accessHosts: ['localhost', '127.0.0.1'],
authMethod: 'password',
comment: 'comment',
group_ids: ['group-id'],
hosts_allow: '127.0.0.1',
groupIds: ['group-id'],
hostsAllow: '127.0.0.1',
name: 'user',
old_name: 'old-user',
oldName: 'old-user',
password: 'password',
role_ids: ['role-id'],
roleIds: ['role-id'],
};

test.each([
Expand All @@ -213,15 +214,16 @@ describe('UserCommand user lifecycle actions', () => {
const fakeHttp = createHttp(createActionResultResponse());
const cmd = new UserCommand(fakeHttp);

await cmd.create({...user, auth_method: authMethod});
await cmd.create({...userData, authMethod});

expect(fakeHttp.request).toHaveBeenCalledWith('post', {
data: expect.objectContaining({
cmd: 'create_user',
access_hosts: userData.accessHosts.join(','),
auth_method: expected,
login: user.name,
'group_ids:': user.group_ids,
'role_ids:': user.role_ids,
login: userData.name,
'group_ids:': userData.groupIds,
'role_ids:': userData.roleIds,
}),
});
},
Expand All @@ -238,14 +240,15 @@ describe('UserCommand user lifecycle actions', () => {
const fakeHttp = createHttp(createActionResultResponse());
const cmd = new UserCommand(fakeHttp);

await cmd.save({id: 'user-id', ...user, auth_method: authMethod});
await cmd.save({id: 'user-id', ...userData, authMethod});

expect(fakeHttp.request).toHaveBeenCalledWith('post', {
data: expect.objectContaining({
cmd: 'save_user',
access_hosts: userData.accessHosts.join(','),
user_id: 'user-id',
modify_password: expected,
old_login: user.old_name,
old_login: userData.oldName,
}),
});
},
Expand Down
105 changes: 43 additions & 62 deletions src/gmp/commands/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,19 @@ interface AuthSettingsValues {
}

interface CreateArguments {
access_hosts: string;
auth_method: string;
accessHosts: string[];
authMethod: string;
comment: string;
group_ids: string[];
hosts_allow: string;
groupIds: string[];
hostsAllow: string;
name: string;
password: string;
role_ids: string[];
roleIds: string[];
}

interface SaveArguments {
interface SaveArguments extends CreateArguments {
id: string;
access_hosts: string;
auth_method: string;
comment: string;
group_ids: string[];
hosts_allow: string;
name: string;
old_name: string;
password: string;
role_ids: string[];
oldName: string;
}

interface DeleteArguments {
Expand Down Expand Up @@ -306,81 +298,70 @@ class UserCommand extends EntityCommand<User, PortListElement> {
}

create({
// eslint-disable-next-line @typescript-eslint/naming-convention
access_hosts,
// eslint-disable-next-line @typescript-eslint/naming-convention
auth_method,
accessHosts,
authMethod,
comment,
// eslint-disable-next-line @typescript-eslint/naming-convention
group_ids,
// eslint-disable-next-line @typescript-eslint/naming-convention
hosts_allow,
groupIds,
hostsAllow,
name,
password,
// eslint-disable-next-line @typescript-eslint/naming-convention
role_ids,
roleIds,
}: CreateArguments) {
if (auth_method === AUTH_METHOD_LDAP) {
auth_method = '1';
} else if (auth_method === AUTH_METHOD_RADIUS) {
auth_method = '2';
if (authMethod === AUTH_METHOD_LDAP) {
authMethod = '1';
} else if (authMethod === AUTH_METHOD_RADIUS) {
authMethod = '2';
} else {
auth_method = '0';
authMethod = '0';
}
const data = {
cmd: 'create_user',
access_hosts,
auth_method,
access_hosts: accessHosts.join(','),
auth_method: authMethod,
comment,
'group_ids:': group_ids,
hosts_allow,
'group_ids:': groupIds,
hosts_allow: hostsAllow,
login: name,
password,
'role_ids:': role_ids,
'role_ids:': roleIds,
};
log.debug('Creating new user', data);
return this.action(data);
}

save({
id,
// eslint-disable-next-line @typescript-eslint/naming-convention
access_hosts = '',
// eslint-disable-next-line @typescript-eslint/naming-convention
auth_method,
comment = '',
// eslint-disable-next-line @typescript-eslint/naming-convention
group_ids,
// eslint-disable-next-line @typescript-eslint/naming-convention
hosts_allow,
accessHosts,
authMethod,
comment,
groupIds,
hostsAllow,
name,
// eslint-disable-next-line @typescript-eslint/naming-convention
old_name,
password = '', // needs to be included in httpPost, should be optional in gsad
// eslint-disable-next-line @typescript-eslint/naming-convention
role_ids,
oldName,
password, // needs to be included in httpPost, should be optional in gsad
roleIds,
}: SaveArguments) {
if (auth_method === AUTH_METHOD_LDAP) {
auth_method = '2';
} else if (auth_method === AUTH_METHOD_RADIUS) {
auth_method = '3';
} else if (auth_method === AUTH_METHOD_NEW_PASSWORD) {
auth_method = '1';
if (authMethod === AUTH_METHOD_LDAP) {
authMethod = '2';
} else if (authMethod === AUTH_METHOD_RADIUS) {
authMethod = '3';
} else if (authMethod === AUTH_METHOD_NEW_PASSWORD) {
authMethod = '1';
} else {
auth_method = '0';
authMethod = '0';
}
const data = {
cmd: 'save_user',
access_hosts,
access_hosts: accessHosts.join(','),
comment,
'group_ids:': group_ids,
hosts_allow,
'group_ids:': groupIds,
hosts_allow: hostsAllow,
id,
login: name,
modify_password: auth_method,
old_login: old_name,
modify_password: authMethod,
old_login: oldName,
password,
'role_ids:': role_ids,
'role_ids:': roleIds,
};
log.debug('Saving user', data);
return this.action(data);
Expand Down
Loading
Loading