List of usage examples for junit.framework Assert assertFalse
static public void assertFalse(boolean condition)
From source file:org.apache.ambari.server.configuration.ConfigurationTest.java
@Test public void testGetClientHTTPSSettings() throws IOException { File passFile = File.createTempFile("https.pass.", "txt"); passFile.deleteOnExit();// w ww . j av a 2s . c om String password = "pass12345"; FileUtils.writeStringToFile(passFile, password); Properties ambariProperties = new Properties(); ambariProperties.setProperty(Configuration.API_USE_SSL, "true"); ambariProperties.setProperty(Configuration.CLIENT_API_SSL_KSTR_DIR_NAME_KEY, passFile.getParent()); ambariProperties.setProperty(Configuration.CLIENT_API_SSL_CRT_PASS_FILE_NAME_KEY, passFile.getName()); String oneWayPort = RandomStringUtils.randomNumeric(4); String twoWayPort = RandomStringUtils.randomNumeric(4); ambariProperties.setProperty(Configuration.SRVR_TWO_WAY_SSL_PORT_KEY, twoWayPort.toString()); ambariProperties.setProperty(Configuration.SRVR_ONE_WAY_SSL_PORT_KEY, oneWayPort.toString()); Configuration conf = new Configuration(ambariProperties); Assert.assertTrue(conf.getApiSSLAuthentication()); //Different certificates for two-way SSL and HTTPS Assert.assertFalse(conf.getConfigsMap().get(Configuration.KSTR_NAME_KEY) .equals(conf.getConfigsMap().get(Configuration.CLIENT_API_SSL_KSTR_NAME_KEY))); Assert.assertFalse(conf.getConfigsMap().get(Configuration.SRVR_CRT_NAME_KEY) .equals(conf.getConfigsMap().get(Configuration.CLIENT_API_SSL_CRT_NAME_KEY))); Assert.assertEquals("https.keystore.p12", conf.getConfigsMap().get(Configuration.CLIENT_API_SSL_KSTR_NAME_KEY)); Assert.assertEquals(passFile.getName(), conf.getConfigsMap().get(Configuration.CLIENT_API_SSL_CRT_PASS_FILE_NAME_KEY)); Assert.assertEquals(password, conf.getConfigsMap().get(Configuration.CLIENT_API_SSL_CRT_PASS_KEY)); Assert.assertEquals(Integer.parseInt(twoWayPort), conf.getTwoWayAuthPort()); Assert.assertEquals(Integer.parseInt(oneWayPort), conf.getOneWayAuthPort()); }
From source file:org.apache.ambari.server.configuration.ConfigurationTest.java
@Test public void testIsViewValidationEnabled() throws Exception { final Properties ambariProperties = new Properties(); Configuration configuration = new Configuration(ambariProperties); Assert.assertFalse(configuration.isViewValidationEnabled()); ambariProperties.setProperty(Configuration.VIEWS_VALIDATE, "false"); configuration = new Configuration(ambariProperties); Assert.assertFalse(configuration.isViewValidationEnabled()); ambariProperties.setProperty(Configuration.VIEWS_VALIDATE, "true"); configuration = new Configuration(ambariProperties); Assert.assertTrue(configuration.isViewValidationEnabled()); }
From source file:org.apache.ambari.server.security.encryption.CredentialProviderTest.java
@Test public void testIsAliasString() { String test = "cassablanca"; Assert.assertFalse(CredentialProvider.isAliasString(test)); test = "${}"; Assert.assertFalse(CredentialProvider.isAliasString(test)); test = "{}";/* w w w . j a v a 2s . c o m*/ Assert.assertFalse(CredentialProvider.isAliasString(test)); test = "{cassablanca}"; Assert.assertFalse(CredentialProvider.isAliasString(test)); test = "${cassablanca}"; Assert.assertFalse(CredentialProvider.isAliasString(test)); test = "${alias=cassablanca}"; Assert.assertTrue(CredentialProvider.isAliasString(test)); }
From source file:org.apache.ambari.server.security.encryption.CredentialStoreServiceTest.java
@Test public void testAddCredentialToStore() throws Exception { String masterKey = "ThisissomeSecretPassPhrasse"; String masterKeyLocation = keystore_dir.getAbsolutePath() + "/master"; MasterKeyService masterKeyService = new MasterKeyServiceImpl(masterKey, masterKeyLocation, false); credentialStoreService.setMasterKeyService(masterKeyService); String password = "mypassword"; credentialStoreService.addCredential("myalias", password); char[] credential = credentialStoreService.getCredential("myalias"); Assert.assertEquals(password, new String(credential)); File f = new File(masterKeyLocation); Assert.assertFalse(f.exists()); }
From source file:org.apache.ambari.server.security.encryption.MasterKeyServiceTest.java
@Test public void testReadFromEnvAsPath() throws Exception { // Create a master key MasterKeyService ms = new MasterKeyServiceImpl("ThisisSomePassPhrase", fileDir + File.separator + "master", true);//from w ww. j ava 2s.com Assert.assertTrue(ms.isMasterKeyInitialized()); File f = new File(fileDir + File.separator + "master"); Assert.assertTrue(f.exists()); Map<String, String> mapRet = new HashMap<String, String>(); mapRet.put(Configuration.MASTER_KEY_LOCATION, f.getAbsolutePath()); mockStatic(System.class); expect(System.getenv()).andReturn(mapRet); replayAll(); ms = new MasterKeyServiceImpl(); verifyAll(); Assert.assertTrue(ms.isMasterKeyInitialized()); Assert.assertNotNull(ms.getMasterSecret()); Assert.assertEquals("ThisisSomePassPhrase", new String(ms.getMasterSecret())); Assert.assertFalse(f.exists()); }
From source file:org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandlerTest.java
@Test public void testCreateSecurePassword() throws Exception { KerberosOperationHandler handler1 = createHandler(); KerberosOperationHandler handler2 = createHandler(); String password1 = handler1.createSecurePassword(); Assert.assertNotNull(password1);/* ww w.ja v a 2 s . c om*/ Assert.assertEquals(KerberosOperationHandler.SECURE_PASSWORD_LENGTH, password1.length()); String password2 = handler2.createSecurePassword(); Assert.assertNotNull(password2); Assert.assertEquals(KerberosOperationHandler.SECURE_PASSWORD_LENGTH, password2.length()); // Make sure the passwords are different... if they are the same, that indicated the random // number generators are generating using the same pattern and that is not secure. Assert.assertFalse((password1.equals(password2))); }
From source file:org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandlerTest.java
@Test public void testCreateKeytabFileOneAtATime() throws Exception { KerberosOperationHandler handler = createHandler(); File file = folder.newFile(); final String principal1 = "principal1@REALM.COM"; final String principal2 = "principal2@REALM.COM"; int count;/*from w w w.j av a2 s. c o m*/ Assert.assertTrue(handler.createKeytabFile(principal1, handler.createSecurePassword(), 0, file)); Keytab keytab = Keytab.read(file); Assert.assertNotNull(keytab); List<KeytabEntry> entries = keytab.getEntries(); Assert.assertNotNull(entries); Assert.assertFalse(entries.isEmpty()); count = entries.size(); for (KeytabEntry entry : entries) { Assert.assertEquals(principal1, entry.getPrincipalName()); } Assert.assertTrue(handler.createKeytabFile(principal2, handler.createSecurePassword(), 0, file)); keytab = Keytab.read(file); Assert.assertNotNull(keytab); entries = keytab.getEntries(); Assert.assertNotNull(entries); Assert.assertFalse(entries.isEmpty()); Assert.assertEquals(count * 2, entries.size()); }
From source file:org.apache.ambari.server.serveraction.kerberos.KerberosOperationHandlerTest.java
@Test public void testEnsureKeytabFileContainsNoDuplicates() throws Exception { KerberosOperationHandler handler = createHandler(); File file = folder.newFile(); final String principal1 = "principal1@REALM.COM"; final String principal2 = "principal2@REALM.COM"; Set<String> seenEntries = new HashSet<String>(); Assert.assertTrue(handler.createKeytabFile(principal1, handler.createSecurePassword(), 0, file)); Assert.assertTrue(handler.createKeytabFile(principal2, handler.createSecurePassword(), 0, file)); // Attempt to add duplicate entries Assert.assertTrue(handler.createKeytabFile(principal2, handler.createSecurePassword(), 0, file)); Keytab keytab = Keytab.read(file);//from ww w. jav a2s . c om Assert.assertNotNull(keytab); List<KeytabEntry> entries = keytab.getEntries(); Assert.assertNotNull(entries); Assert.assertFalse(entries.isEmpty()); for (KeytabEntry entry : entries) { String seenEntry = String.format("%s|%s", entry.getPrincipalName(), entry.getKey().getKeyType().toString()); Assert.assertFalse(seenEntries.contains(seenEntry)); seenEntries.add(seenEntry); } }