Skip to content
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.apache.ambari.server.view.ViewRegistry;
import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
Expand All @@ -60,6 +61,11 @@
import junit.framework.Assert;

public class AmbariAuthorizationFilterTest {
@Before
public void setUp() {
SecurityContextHolder.getContext().setAuthentication(null);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Technically, this is not the correct solution since the test case appears to use a mocked SecurityContext, not the one from the SecurityContextHolder. See org.apache.ambari.server.security.authorization.AmbariAuthorizationFilterTest#performGeneralDoFilterTest.

I think we need to remove the mocked SecurityContext and use the one provided by Spring. For example, see org.apache.ambari.server.controller.internal.UserResourceProviderTest#deleteResourcesTest.

In cases like the referenced method, we can do the following rather than create a mocked SecurityContext:

    SecurityContextHolder.getContext().setAuthentication(authentication);

Since the test case explictly sets the authenticated user before performing the test, there is no real need to explicitly clear it in the before method.

}

@After
public void clearAuthentication() {
SecurityContextHolder.getContext().setAuthentication(null);
Expand Down