-
Notifications
You must be signed in to change notification settings - Fork 807
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
feat(pipeline executions/orca) : Added ability to add roles to manual… #3983
base: master
Are you sure you want to change the base?
Changes from all commits
7a15388
c13a948
51d70a3
9ea608b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2020 OpsMx, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.orca.echo.util; | ||
|
||
import com.netflix.spinnaker.fiat.model.Authorization; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class ManualJudgmentAuthzGroupsUtil { | ||
|
||
public static boolean checkAuthorizedGroups( | ||
List<String> userRoles, List<String> stageRoles, Map<String, Object> permissions) { | ||
Comment on lines
+25
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected to see a test for this class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 6 test cases are written/added in ManualJudgmentStageSpec.groovy only to test this logic. Please have a look at this test case. @unroll There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems weird to have a test case for a different class (ManualJudgmentStage) specifically testing a different class, doesn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are using the logic in the ManualJudgmentStage.groovy. So i have written 6 test cases to check the ManualJudgmentAuthzGroupsUtil.java logic in the ManualJudgmentStageSpec.groovy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're also using it in a controller, which means that the test cases don't belong where there are today. I'd say the tests that are testing this code should live in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
|
||
boolean isAuthorizedGroup = false; | ||
if (stageRoles == null || stageRoles.isEmpty()) { | ||
return true; | ||
} | ||
for (String role : userRoles) { | ||
if (stageRoles.contains(role)) { | ||
for (Map.Entry<String, Object> entry : permissions.entrySet()) { | ||
if (Authorization.CREATE.name().equals(entry.getKey()) | ||
|| Authorization.EXECUTE.name().equals(entry.getKey()) | ||
|| Authorization.WRITE.name().equals(entry.getKey())) { | ||
if (entry.getValue() != null && ((List<String>) entry.getValue()).contains(role)) { | ||
return true; | ||
} | ||
} else if (Authorization.READ.name().equals(entry.getKey())) { | ||
if (entry.getValue() != null && ((List<String>) entry.getValue()).contains(role)) { | ||
isAuthorizedGroup = false; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return isAuthorizedGroup; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this should never happen, I presume we want to know when it does happen? Perhaps would be useful to have a warn-level log about it?
log.warn("Attempted to get user permission for '$username' but none were found."
or something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done