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

setting paramName only when it is not null #6258

Closed
wants to merge 7 commits into from

Conversation

shabari004
Copy link

#checking whether paramNames[i] is null, if it is not null then only we call StandardEvaluationContext.setVariable method

@pivotal-issuemaster
Copy link

@shabari004 Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@shabari004 Thank you for signing the Contributor License Agreement!

Copy link
Member

@rwinch rwinch left a comment

Choose a reason for hiding this comment

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

Thank you for the PR @shabari004!

  • Can you please update the commit message to align with the Spring Security conventions? Specifically, please ensure you have Fixes: gh-6223
  • Can you please add a test? You should be able to
    • Remove super from here
    • In the test extend MethodSecurityEvaluationContext and override setVariable method to throw an Exception if a null value is passed in.

@rwinch rwinch self-assigned this Dec 18, 2018
@rwinch rwinch added the status: waiting-for-feedback We need additional information before we can continue label Dec 18, 2018
@shabari004
Copy link
Author

Hi @rwinch

  • I updated the commit message and submit again (sorry about that).

  • For creating test class, I created a test class namedMethodSecurityAddArgumentsTests. I added the file below, I'm not sure how much help i can ask, if you dont mind can you check it please
    MethodSecurityAddArgumentsTests.txt

@rwinch
Copy link
Member

rwinch commented Dec 19, 2018

Thanks for the feedback. It is probably best to just include the files in the PR. We can modify them as needed. That makes it easier to review and provide feedback.

For the tests:

  • I'd start by creating a standard test named MethodSecurityEvaluationContextTests.
  • Then I would create a static inner class named NotNullVariableMethodSecurityEvaluationContext that behaves exactly as you have defined MethodSecurityAddArgumentsTests.setVariable
  • Then create a test that creates a NotNullVariableMethodSecurityEvaluationContext instance and injects a mock ParameterNameDiscoverer that returns a new String[] { null }.
  • Next invoke NotNullVariableMethodSecurityEvaluationContext.lookupVariable on the instance created in the previous step. Before your change this would then invoke the setVariable method with a null variable name. Since this test overrides the setVariable method to forbid a null value, if there is no Exception at this point, we know the code is fixed. You can validate that the test is real by temporarily removing the null check and see that it will fail.

@shabari004
Copy link
Author

I created the test cases as you mentioned. can you review it please. Thank you.

Copy link
Member

@rwinch rwinch left a comment

Choose a reason for hiding this comment

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

Thanks! The code/tests look good.

  • I have a few stylistic comments inline that need fixed.
  • Can you please squash your commits?
  • Can you please update the commit message to align with the Spring Security conventions? Specifically can you ensure to have a meaningful subject and Fixes: gh-17565 at the end of the commit message?

ParameterNameDiscoverer paramNameDiscoverer = mock(ParameterNameDiscoverer.class);
when(paramNameDiscoverer.getParameterNames(method)).thenReturn( new String[] {null});

NotNullVariableMethodSecurityEvaluationContext NNVMSEC= new NotNullVariableMethodSecurityEvaluationContext(mock(Authentication.class), mock(MethodInvocation.class), paramNameDiscoverer);
Copy link
Member

Choose a reason for hiding this comment

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

We don't use all caps unless it is a final member variable. You could rename this to something like Context

when(paramNameDiscoverer.getParameterNames(method)).thenReturn( new String[] {null});

NotNullVariableMethodSecurityEvaluationContext NNVMSEC= new NotNullVariableMethodSecurityEvaluationContext(mock(Authentication.class), mock(MethodInvocation.class), paramNameDiscoverer);
try {
Copy link
Member

Choose a reason for hiding this comment

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

There is no need need for this try/catch since it would fail with an uncaught exception

* @author shabarijonnalagadda
*
*/
public class MethodSecurityEvaluationContextTests{
Copy link
Member

Choose a reason for hiding this comment

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

Try to pay attention to whitespace (i.e. add a space so it isMethodSecurityEvaluationContextTests {)

@Mock
private Method method;

public static class NotNullVariableMethodSecurityEvaluationContext extends MethodSecurityEvaluationContext {
Copy link
Member

Choose a reason for hiding this comment

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

Just a few style guides to be consistent with our code base.

  • Place the static class below the method that uses it
  • Do not make the class public (you can make it private or package private)
  • Fix the whitespace (there are extra spaces in the declaration above)

…not null before calling setVariable

Fixes: 17565

adding Junit test MethodSecurityEvaluationContext setVariable
Fixes: spring-projectsgh-6223

Update MethodSecurityEvaluationContextTests.java

changing the code to be consistent with the existing code base.
…ethodSecurityEvaluationContext should check Parameter Names are not null

Fixes:17565
@rwinch
Copy link
Member

rwinch commented Dec 21, 2018

Thanks for the updates. It appears we now have a few problems:

  • There are test failures. You can run ./gradlew check to find the errors
  • The branch needs to be rebased off of master due to the conflicts
  • The commits need to be squashed

@shabari004
Copy link
Author

@rwinch i think i lost it, is there anyway somebody can work on this bug. I think i dont have enough knowledge, Thanks for guidance till this point.

@ankurpathak
Copy link
Contributor

@rwinch i think i lost it, is there anyway somebody can work on this bug. I think i dont have enough knowledge, Thanks for guidance till this point.

@rwinch @shabari004 I would like to take it forward.

@ankurpathak
Copy link
Contributor

Here is new pull request for the issue:
#6332

@rwinch rwinch removed the status: waiting-for-feedback We need additional information before we can continue label Jan 7, 2019
@rwinch
Copy link
Member

rwinch commented Jan 7, 2019

@shabari004 Thanks for following up. I will proceed with #6332

@rwinch rwinch closed this Jan 7, 2019
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.

4 participants