ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-15980 - RU/EU Precheck fails on Ranger Admin with SSL Because Of Missing Truststore (jonathanhurley)
Date Tue, 19 Apr 2016 20:17:52 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.2.2 8e821e028 -> 34ac6f423


AMBARI-15980 - RU/EU Precheck fails on Ranger Admin with SSL Because Of Missing Truststore
(jonathanhurley)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/34ac6f42
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/34ac6f42
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/34ac6f42

Branch: refs/heads/branch-2.2.2
Commit: 34ac6f42336a528c7dcef3d2a29f5418b941cda2
Parents: 8e821e0
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Tue Apr 19 14:32:01 2016 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Tue Apr 19 16:17:45 2016 -0400

----------------------------------------------------------------------
 .../server/checks/RangerPasswordCheck.java      |  77 +++++++-----
 .../server/checks/RangerPasswordCheckTest.java  | 116 ++++++++-----------
 2 files changed, 98 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/34ac6f42/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java
b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java
index 33f971a..5e2db33 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/checks/RangerPasswordCheck.java
@@ -62,15 +62,11 @@ public class RangerPasswordCheck extends AbstractCheckDescriptor {
   static final String KEY_RANGER_OTHER_ISSUE = "invalid_response";
   static final String KEY_RANGER_CONFIG_MISSING = "missing_config";
 
-  // !!! package protected for testing
-  URLStreamProvider m_streamProvider;
-
   /**
    * Constructor.
    */
   public RangerPasswordCheck() {
     super(CheckDescription.SERVICES_RANGER_PASSWORD_VERIFY);
-    m_streamProvider = new URLStreamProvider(2000, 2000, ComponentSSLConfiguration.instance());
   }
 
   /**
@@ -97,6 +93,12 @@ public class RangerPasswordCheck extends AbstractCheckDescriptor {
 
   @Override
   public void perform(PrerequisiteCheck check, PrereqCheckRequest request) throws AmbariException
{
+    // !!! ComponentSSLConfiguration is an old-school singleton which doesn't
+    // get initialized until after Guice is done - because this check is bound
+    // as a singleton via Guice, we can't initialize the stream provider in the
+    // constructor since the SSL configuration instance hasn't been initialized
+    URLStreamProvider streamProvider = new URLStreamProvider(2000, 2000,
+        ComponentSSLConfiguration.instance());
 
     String rangerUrl = checkEmpty("admin-properties", "policymgr_external_url", check, request);
     if (null == rangerUrl) {
@@ -138,7 +140,7 @@ public class RangerPasswordCheck extends AbstractCheckDescriptor {
 
     // !!! first, just try the service with the admin credentials
     try {
-      int response = checkLogin(rangerAuthUrl, adminUsername, adminPassword);
+      int response = checkLogin(streamProvider, rangerAuthUrl, adminUsername, adminPassword);
 
       switch (response) {
         case 401: {
@@ -178,14 +180,14 @@ public class RangerPasswordCheck extends AbstractCheckDescriptor {
     }
 
     // !!! Check for the user, capture exceptions as a warning.
-    boolean hasUser = checkRangerUser(rangerUserUrl, adminUsername, adminPassword,
+    boolean hasUser = checkRangerUser(streamProvider, rangerUserUrl, adminUsername, adminPassword,
         rangerAdminUsername, check, request, warnReasons);
 
     if (hasUser) {
-
       // !!! try credentials for specific user
       try {
-        int response = checkLogin(rangerAuthUrl, rangerAdminUsername, rangerAdminPassword);
+        int response = checkLogin(streamProvider, rangerAuthUrl, rangerAdminUsername,
+            rangerAdminPassword);
 
         switch (response) {
           case 401: {
@@ -227,22 +229,29 @@ public class RangerPasswordCheck extends AbstractCheckDescriptor {
   }
 
   /**
-   * Checks the credentials.  From the Ranger team, bad credentials result in a
-   * successful call, but the Ranger admin server will redirect to the home page.  They
-   * recommend parsing the result.  If it parses, the credentials are good, otherwise
-   * consider the user as unverified.
+   * Checks the credentials. From the Ranger team, bad credentials result in a
+   * successful call, but the Ranger admin server will redirect to the home
+   * page. They recommend parsing the result. If it parses, the credentials are
+   * good, otherwise consider the user as unverified.
    *
-   * @param url       the url to check
-   * @param username  the user to check
-   * @param password  the password to check
-   * @return  the http response code
-   * @throws IOException if there was an error reading the response
+   * @param streamProvider
+   *          the stream provider to use when making requests
+   * @param url
+   *          the url to check
+   * @param username
+   *          the user to check
+   * @param password
+   *          the password to check
+   * @return the http response code
+   * @throws IOException
+   *           if there was an error reading the response
    */
-  private int checkLogin(String url, String username, String password) throws IOException
{
+  private int checkLogin(URLStreamProvider streamProvider, String url, String username,
+      String password) throws IOException {
 
     Map<String, List<String>> headers = getHeaders(username, password);
 
-    HttpURLConnection conn = m_streamProvider.processURL(url, "GET", (InputStream) null,
headers);
+    HttpURLConnection conn = streamProvider.processURL(url, "GET", (InputStream) null, headers);
 
     int result = conn.getResponseCode();
 
@@ -260,24 +269,34 @@ public class RangerPasswordCheck extends AbstractCheckDescriptor {
   }
 
   /**
-   * @param rangerUserUrl the url to use when looking for the user
-   * @param username      the username to use when loading the url
-   * @param password      the password for the user url
-   * @param userToSearch  the user to look for
-   * @param check         the check instance for loading failure reasons
-   * @param request       the request instance for loading failure reasons
-   * @param warnReasons   the list of warn reasons to fill
+   * @param streamProvider
+   *          the stream provider to use when making requests
+   * @param rangerUserUrl
+   *          the url to use when looking for the user
+   * @param username
+   *          the username to use when loading the url
+   * @param password
+   *          the password for the user url
+   * @param userToSearch
+   *          the user to look for
+   * @param check
+   *          the check instance for loading failure reasons
+   * @param request
+   *          the request instance for loading failure reasons
+   * @param warnReasons
+   *          the list of warn reasons to fill
    * @return {@code true} if the user was found
    */
-  private boolean checkRangerUser(String rangerUserUrl, String username, String password,
-      String userToSearch, PrerequisiteCheck check, PrereqCheckRequest request, List<String>
warnReasons) {
+  private boolean checkRangerUser(URLStreamProvider streamProvider, String rangerUserUrl,
+      String username, String password, String userToSearch, PrerequisiteCheck check,
+      PrereqCheckRequest request, List<String> warnReasons) {
 
     String url = String.format("%s?name=%s", rangerUserUrl, userToSearch);
 
     Map<String, List<String>> headers = getHeaders(username, password);
 
     try {
-      HttpURLConnection conn = m_streamProvider.processURL(url, "GET", (InputStream) null,
headers);
+      HttpURLConnection conn = streamProvider.processURL(url, "GET", (InputStream) null,
headers);
 
       int result = conn.getResponseCode();
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/34ac6f42/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java
index afa3789..e5b231f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/checks/RangerPasswordCheckTest.java
@@ -46,6 +46,10 @@ import org.apache.ambari.server.state.stack.PrerequisiteCheck;
 import org.easymock.EasyMock;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
 import com.google.inject.Provider;
 
@@ -54,6 +58,8 @@ import com.google.inject.Provider;
  * Unit tests for RangerPasswordCheck
  *
  */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(RangerPasswordCheck.class)
 public class RangerPasswordCheckTest {
 
   private static final String RANGER_URL = "http://foo:6080/";
@@ -78,6 +84,7 @@ public class RangerPasswordCheckTest {
   private Clusters m_clusters = EasyMock.createMock(Clusters.class);
   private Map<String, String> m_configMap = new HashMap<String, String>();
   private RangerPasswordCheck m_rpc = null;
+  private URLStreamProvider m_streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
   @Before
   public void setup() throws Exception {
@@ -119,6 +126,9 @@ public class RangerPasswordCheckTest {
         return m_clusters;
       }
     };
+
+    EasyMock.reset(m_streamProvider);
+    PowerMockito.whenNew(URLStreamProvider.class).withAnyArguments().thenReturn(m_streamProvider);
   }
 
   @Test
@@ -158,9 +168,6 @@ public class RangerPasswordCheckTest {
   public void testMissingProps() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
-
-    m_rpc.m_streamProvider = streamProvider;
 
     m_configMap.clear();
 
@@ -200,10 +207,10 @@ public class RangerPasswordCheckTest {
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_USER_RESPONSE.getBytes()));
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes()));
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
+    replay(conn, m_streamProvider);
 
     m_configMap.put("ranger_admin_password", "r_pass");
     check = new PrerequisiteCheck(null, null);
@@ -217,7 +224,6 @@ public class RangerPasswordCheckTest {
   public void testNormal() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once();
@@ -226,18 +232,17 @@ public class RangerPasswordCheckTest {
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once();
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
 
     assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
   @SuppressWarnings("unchecked")
@@ -245,25 +250,23 @@ public class RangerPasswordCheckTest {
   public void testNoUser() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once();
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(NO_USER_RESPONSE.getBytes())).once();
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
 
     assertEquals(PrereqCheckStatus.PASS, check.getStatus());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
   @SuppressWarnings("unchecked")
@@ -271,7 +274,6 @@ public class RangerPasswordCheckTest {
   public void testBadUserParsing() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once();
@@ -279,11 +281,10 @@ public class RangerPasswordCheckTest {
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(
         "some really bad non-json".getBytes()));
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
@@ -295,7 +296,7 @@ public class RangerPasswordCheckTest {
     assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
     assertEquals(error, check.getFailReason());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
   @SuppressWarnings("unchecked")
@@ -303,7 +304,6 @@ public class RangerPasswordCheckTest {
   public void testJsonCasting() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes()));
@@ -311,11 +311,10 @@ public class RangerPasswordCheckTest {
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(
         "{ \"data\": \"bad\", \"vXUsers\": \"xyz\" }".getBytes()));
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
@@ -327,7 +326,7 @@ public class RangerPasswordCheckTest {
     assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
     assertEquals(error, check.getFailReason());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
 
@@ -336,15 +335,13 @@ public class RangerPasswordCheckTest {
   public void testAdminUnauthorized() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(401);
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.SERVICES_RANGER_PASSWORD_VERIFY,
null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
@@ -352,7 +349,7 @@ public class RangerPasswordCheckTest {
     assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
     assertEquals("Credentials for user 'admin' in Ambari do not match Ranger.", check.getFailReason());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
   @SuppressWarnings("unchecked")
@@ -360,16 +357,14 @@ public class RangerPasswordCheckTest {
   public void testAdminUnauthorizedByRedirect() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(BAD_LOGIN_RESPONSE.getBytes()));
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.SERVICES_RANGER_PASSWORD_VERIFY,
null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
@@ -377,7 +372,7 @@ public class RangerPasswordCheckTest {
     assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
     assertEquals("Credentials for user 'admin' in Ambari do not match Ranger.", check.getFailReason());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
   @SuppressWarnings("unchecked")
@@ -385,15 +380,13 @@ public class RangerPasswordCheckTest {
   public void testAdminIOException() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andThrow(new IOException("whoops"));
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.SERVICES_RANGER_PASSWORD_VERIFY,
null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
@@ -401,7 +394,7 @@ public class RangerPasswordCheckTest {
     assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
     assertEquals("Could not access Ranger to verify user 'admin' against " + RANGER_URL +
"service/public/api/repository/count. whoops", check.getFailReason());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
   @SuppressWarnings("unchecked")
@@ -409,15 +402,13 @@ public class RangerPasswordCheckTest {
   public void testAdminBadResponse() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(404);
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(CheckDescription.SERVICES_RANGER_PASSWORD_VERIFY,
null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
@@ -425,7 +416,7 @@ public class RangerPasswordCheckTest {
     assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
     assertEquals("Could not verify credentials for user 'admin'.  Response code 404 received
from " + RANGER_URL + "service/public/api/repository/count", check.getFailReason());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
   @SuppressWarnings("unchecked")
@@ -433,7 +424,6 @@ public class RangerPasswordCheckTest {
   public void testUserUnauthorized() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once();
@@ -441,11 +431,10 @@ public class RangerPasswordCheckTest {
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_USER_RESPONSE.getBytes())).once();
     expect(conn.getResponseCode()).andReturn(401);
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
@@ -453,7 +442,7 @@ public class RangerPasswordCheckTest {
     assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
     assertEquals("Credentials for user 'r_admin' in Ambari do not match Ranger.", check.getFailReason());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
   @SuppressWarnings("unchecked")
@@ -461,7 +450,6 @@ public class RangerPasswordCheckTest {
   public void testUserUnauthorizedByRedirect() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once();
@@ -470,11 +458,10 @@ public class RangerPasswordCheckTest {
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(BAD_LOGIN_RESPONSE.getBytes())).once();
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
@@ -482,7 +469,7 @@ public class RangerPasswordCheckTest {
     assertEquals(PrereqCheckStatus.FAIL, check.getStatus());
     assertEquals("Credentials for user 'r_admin' in Ambari do not match Ranger.", check.getFailReason());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
   @SuppressWarnings("unchecked")
@@ -490,7 +477,6 @@ public class RangerPasswordCheckTest {
   public void testUserIOException() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once();
@@ -498,11 +484,10 @@ public class RangerPasswordCheckTest {
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_USER_RESPONSE.getBytes())).once();
     expect(conn.getResponseCode()).andThrow(new IOException("again!"));
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
         (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
@@ -510,7 +495,7 @@ public class RangerPasswordCheckTest {
     assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
     assertEquals("Could not access Ranger to verify user 'r_admin' against " + RANGER_URL
+ "service/public/api/repository/count. again!", check.getFailReason());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 
   @SuppressWarnings("unchecked")
@@ -518,7 +503,6 @@ public class RangerPasswordCheckTest {
   public void testUserBadResponse() throws Exception {
 
     HttpURLConnection conn = EasyMock.createMock(HttpURLConnection.class);
-    URLStreamProvider streamProvider = EasyMock.createMock(URLStreamProvider.class);
 
     expect(conn.getResponseCode()).andReturn(200);
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_LOGIN_RESPONSE.getBytes())).once();
@@ -526,11 +510,11 @@ public class RangerPasswordCheckTest {
     expect(conn.getInputStream()).andReturn(new ByteArrayInputStream(GOOD_USER_RESPONSE.getBytes())).once();
     expect(conn.getResponseCode()).andReturn(500);
 
-    expect(streamProvider.processURL((String) anyObject(), (String) anyObject(),
-        (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(conn).anyTimes();
+    expect(m_streamProvider.processURL((String) anyObject(), (String) anyObject(),
+        (InputStream) anyObject(), (Map<String, List<String>>) anyObject())).andReturn(
+            conn).anyTimes();
 
-    replay(conn, streamProvider);
-    m_rpc.m_streamProvider = streamProvider;
+    replay(conn, m_streamProvider);
 
     PrerequisiteCheck check = new PrerequisiteCheck(null, null);
     m_rpc.perform(check, new PrereqCheckRequest("cluster"));
@@ -538,6 +522,6 @@ public class RangerPasswordCheckTest {
     assertEquals(PrereqCheckStatus.WARNING, check.getStatus());
     assertEquals("Could not verify credentials for user 'r_admin'.  Response code 500 received
from " + RANGER_URL + "service/public/api/repository/count", check.getFailReason());
 
-    verify(conn, streamProvider);
+    verify(conn, m_streamProvider);
   }
 }


Mime
View raw message