Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP:GDB-6908 Added method compactAuthorities in the security controller and tests verifying it. #787

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sava-savov-ontotext
Copy link
Contributor

No description provided.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 31, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 6 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot B 5 Security Hotspots
Code Smell A 326 Code Smells

17.4% 17.4% Coverage
2.4% 2.4% Duplication

@@ -104,6 +104,37 @@ const parseAuthorities = function (authorities) {
};
};

const compactAuthorities = function (authorities) {
const writeAllRepos = authorities.find(authority => authority === `${WRITE_REPO_PREFIX}*`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writeAllRepos is not a good name, better name would be something like writeAllRole or writeAllAuthority.

const writeAllRepos = authorities.find(authority => authority === `${WRITE_REPO_PREFIX}*`);
if (writeAllRepos) {
return _.remove(authorities, function (_authority) {
if (_authority.indexOf(READ_REPO_PREFIX) === -1 && _authority.indexOf(WRITE_REPO_PREFIX) === -1) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we have constants for these WRITE_REPO_PREFIX_* and READ_REPO_PREFIX_*? As far as I can see, these are just static strings and can be defined once and reused.
E.g. WRITE_ALL_REPO_WILDCARD or something.

@@ -104,6 +104,37 @@ const parseAuthorities = function (authorities) {
};
};

const compactAuthorities = function (authorities) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to understand what this function does without reading the code and why. Can you drop some doc comment here. Other than that, I wonder, why this is not placed inside some service?

const compactAuthorities = function (authorities) {
const writeAllRepos = authorities.find(authority => authority === `${WRITE_REPO_PREFIX}*`);
if (writeAllRepos) {
return _.remove(authorities, function (_authority) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know that the function _.remove from lodash actually mutates the array argument, aren't you? Is it intentional that you just use the return value of the function and not aware of the actual authorities array? Isn't it better to use Array.reduce or Array.filter for example instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to modify the array, leaving only "WRITE_REPO_", "READ_REPO_" and all other authorities, that aren't related with read or write ones.

$scope.createUserHttp();
$httpBackend.expectPOST("rest/security/users/testov", {"password":"testova",
"appSettings":{"DEFAULT_SAMEAS":true,"DEFAULT_INFERENCE":true,"EXECUTE_COUNT":true, "IGNORE_SHARED_QUERIES":false,"DEFAULT_VIS_GRAPH_SCHEMA":true},
"grantedAuthorities":["ROLE_USER","WRITE_REPO_myrepo","READ_REPO_myrepo","READ_REPO_*"]})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I don't get the requirement correctly, but shouldn't you expect
"grantedAuthorities":["ROLE_USER","WRITE_REPO_myrepo","READ_REPO_*"]

Copy link
Contributor Author

@sava-savov-ontotext sava-savov-ontotext Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is "WRITE_REPO_myrepo", "READ_REPO_myrepo" authority is expected as well.

@sava-savov-ontotext sava-savov-ontotext changed the title GDB-6908 Added method compactAuthorities in the security controller and tests verifying it. WIP:GDB-6908 Added method compactAuthorities in the security controller and tests verifying it. Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants