Skip to content

Commit

Permalink
Use camelCase for capabilities, update exceptions
Browse files Browse the repository at this point in the history
Attributes in Capabilities now use camelCase and exceptions for
snake_case in the GMP responses have been added.
  • Loading branch information
timopollmeier committed Jul 1, 2024
1 parent d390b03 commit e2c6ed7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion allowedSnakeCase.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ module.exports = [
'general_permissions',
'get_aggregate',
'get_aggregates_response',
'get_capabilities',

Check warning on line 209 in allowedSnakeCase.cjs

View check run for this annotation

Codecov / codecov/patch

allowedSnakeCase.cjs#L209

Added line #L209 was not covered by tests
'get_config_family_response',
'get_config_nvt_response',
'get_features_response',

Check warning on line 212 in allowedSnakeCase.cjs

View check run for this annotation

Codecov / codecov/patch

allowedSnakeCase.cjs#L212

Added line #L212 was not covered by tests
'get_feeds',
'get_feeds_response',
'get_identifier',
Expand Down Expand Up @@ -236,13 +238,13 @@ module.exports = [
'groups_data',
'gsad_response',
'has_av_duration',
'_has_caps',
'has_detection',
'has_duration',
'has_reference',
'has_selected',
'has_severity_filter',
'header_title',
'help_response',

Check warning on line 247 in allowedSnakeCase.cjs

View check run for this annotation

Codecov / codecov/patch

allowedSnakeCase.cjs#L247

Added line #L247 was not covered by tests
'highest_severity',
'high_per_host',
'host_allow',
Expand Down
10 changes: 5 additions & 5 deletions src/gmp/capabilities/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ const convertType = type => {

class Capabilities {
constructor(cap_names, featuresList) {
this._has_caps = isDefined(cap_names);
this._has_features = isDefined(featuresList);
this._hasCaps = isDefined(cap_names);
this._hasFeatures = isDefined(featuresList);

let caps;
let featuresEnabled = {};

if (this._has_caps) {
if (this._hasCaps) {
caps = map(cap_names, name => name.toLowerCase());
}

if (this._has_features) {
if (this._hasFeatures) {
forEach(featuresList, feature => {
featuresEnabled[feature.name.toUpperCase()] = parseBoolean(
feature._enabled,
Expand All @@ -79,7 +79,7 @@ class Capabilities {
}

areDefined() {
return this._has_caps;
return this._hasCaps;
}

has(name) {
Expand Down
4 changes: 2 additions & 2 deletions src/gmp/commands/__tests__/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ describe('UserCommand capabilities tests', () => {
},
});

expect(caps._has_caps).toBe(true);
expect(caps._hasCaps).toBe(true);
expect(caps.mayAccess('report')).toBe(true);
expect(caps.mayAccess('task')).toBe(true);
expect(caps.mayAccess('user')).toBe(false);

expect(caps._has_features).toBe(true);
expect(caps._hasFeatures).toBe(true);
expect(caps.featureEnabled('test_feature_1')).toBe(true);
expect(caps.featureEnabled('TEST_FEATURE_2')).toBe(true);
expect(caps.featureEnabled('TEST_FEATURE_3')).toBe(false);
Expand Down

0 comments on commit e2c6ed7

Please sign in to comment.