RangerSSLConfigCheck extends AbstractCheckDescriptor { @Override public void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request) throws AmbariException { String isRangerHTTPEnabled = getProperty(request, "ranger-admin-site", "ranger.service.http.enabled"); String isRangerSSLEnabled = getProperty(request, "ranger-admin-site", "ranger.service.https.attrib.ssl.enabled"); String rangerSSLKeystoreFile = getProperty(request, "ranger-admin-site", "ranger.https.attrib.keystore.file"); if (("false").equalsIgnoreCase(isRangerHTTPEnabled) && ("true").equalsIgnoreCase(isRangerSSLEnabled) && rangerSSLKeystoreFile.contains("/etc/ranger/admin/conf") ) { LOG.info("Ranger is SSL enabled, need to show Configuration changes warning before upragade proceeds."); prerequisiteCheck.getFailedOn().add(serviceName); prerequisiteCheck.setStatus(PrereqCheckStatus.WARNING); prerequisiteCheck.setFailReason(getFailReason(prerequisiteCheck, request)); } else { LOG.info("Ranger is not SSL enabled, no need to show Configuration changes warning before upragade proceeds."); } } RangerSSLConfigCheck(); @Override boolean isApplicable(PrereqCheckRequest request); @Override void perform(PrerequisiteCheck prerequisiteCheck, PrereqCheckRequest request);  }
@Test public void testPerform() throws Exception { final Cluster cluster = Mockito.mock(Cluster.class); final Map<String, Service> services = new HashMap<>(); final Service service = Mockito.mock(Service.class); services.put("RANGER", service); Mockito.when(cluster.getServices()).thenReturn(services); Mockito.when(cluster.getClusterId()).thenReturn(1L); Mockito.when(clusters.getCluster("cluster")).thenReturn(cluster); final DesiredConfig desiredConfig = Mockito.mock(DesiredConfig.class); Mockito.when(desiredConfig.getTag()).thenReturn("tag"); Map<String, DesiredConfig> configMap = new HashMap<String, DesiredConfig>(); configMap.put("ranger-admin-site", desiredConfig); Mockito.when(cluster.getDesiredConfigs()).thenReturn(configMap); final Config config = Mockito.mock(Config.class); Mockito.when(cluster.getConfig(Mockito.anyString(), Mockito.anyString())).thenReturn(config); final Map<String, String> properties = new HashMap<String, String>(); Mockito.when(config.getProperties()).thenReturn(properties); properties.put("ranger.service.http.enabled","true"); properties.put("ranger.service.https.attrib.ssl.enabled","true"); properties.put("ranger.https.attrib.keystore.file","/etc/ranger/security/ranger-admin-keystore.jks"); PrerequisiteCheck check = new PrerequisiteCheck(null, null); rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("ranger.service.http.enabled","true"); properties.put("ranger.service.https.attrib.ssl.enabled","true"); properties.put("ranger.https.attrib.keystore.file","/etc/ranger/security/ranger-admin-keystore.jks"); check = new PrerequisiteCheck(null, null); rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("ranger.service.http.enabled","true"); properties.put("ranger.service.https.attrib.ssl.enabled","fasle"); properties.put("ranger.https.attrib.keystore.file","/etc/ranger/security/ranger-admin-keystore.jks"); check = new PrerequisiteCheck(null, null); rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("ranger.service.http.enabled","false"); properties.put("ranger.service.https.attrib.ssl.enabled","true"); properties.put("ranger.https.attrib.keystore.file","/etc/ranger/admin/conf/ranger-admin-keystore.jks"); check = new PrerequisiteCheck(null, null); rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.WARNING, check.getStatus()); properties.put("ranger.service.http.enabled","false"); properties.put("ranger.service.https.attrib.ssl.enabled","true"); properties.put("ranger.https.attrib.keystore.file","/etc/ranger/security/ranger-admin-keystore.jks"); check = new PrerequisiteCheck(null, null); rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); properties.put("ranger.service.http.enabled","false"); properties.put("ranger.service.https.attrib.ssl.enabled","false"); properties.put("ranger.https.attrib.keystore.file","/etc/ranger/security/ranger-admin-keystore.jks"); check = new PrerequisiteCheck(null, null); rangerSSLConfigCheck.perform(check, new PrereqCheckRequest("cluster")); Assert.assertEquals(PrereqCheckStatus.PASS, check.getStatus()); }