@Before public void setUp() throws Throwable { // wait for needed services waitForServiceAvailability(AuthCredentialsService.FACTORY_LINK); // common setup System.clearProperty(EncryptionUtils.ENCRYPTION_KEY); System.clearProperty(EncryptionUtils.INIT_KEY_IF_MISSING); EncryptionUtils.initEncryptionService(); }
@Test public void testManagementHostInitializationWithEncryptionNoErrors() throws Throwable { File keyFile = Paths.get(folder.newFolder().getPath(), "encryption.key").toFile(); System.setProperty(EncryptionUtils.ENCRYPTION_KEY, keyFile.getPath()); System.setProperty(EncryptionUtils.INIT_KEY_IF_MISSING, "true"); EncryptionUtils.initEncryptionService(); try (TestManagementHost host = new TestManagementHost(false)) { // we're just verifying that no exceptions are thrown assertNull(host.getSecureListener()); } }
@Test public void testPlainTextSystemCredentials() throws Throwable { // init EncryptionUtils File keyFile = Paths.get(folder.newFolder().getPath(), "encryption.key").toFile(); System.setProperty(EncryptionUtils.ENCRYPTION_KEY, keyFile.getPath()); System.setProperty(EncryptionUtils.INIT_KEY_IF_MISSING, "true"); EncryptionUtils.initEncryptionService(); AuthCredentialsServiceState credentials = createCredentials("username", "password", true); assertEquals("username", credentials.userEmail); assertNotNull(credentials.privateKey); assertFalse(credentials.privateKey.startsWith(EncryptionUtils.ENCRYPTION_PREFIX)); assertEquals("password", credentials.privateKey); credentials = createCredentials("username2", "password2", false); assertEquals("username2", credentials.userEmail); assertNotNull(credentials.privateKey); assertTrue(credentials.privateKey.startsWith(EncryptionUtils.ENCRYPTION_PREFIX)); // like AuthBootstrapService does AuthCredentialsServiceState credentialsPatch = new AuthCredentialsServiceState(); credentialsPatch.privateKey = "password2"; credentialsPatch.customProperties = new HashMap<>(); credentialsPatch.customProperties.put(AuthConfigProvider.PROPERTY_SCOPE, AuthConfigProvider.CredentialsScope.SYSTEM.toString()); credentials = doPatch(credentialsPatch, credentials.documentSelfLink); assertEquals("username2", credentials.userEmail); assertNotNull(credentials.privateKey); assertFalse(credentials.privateKey.startsWith(EncryptionUtils.ENCRYPTION_PREFIX)); assertEquals("password2", credentials.privateKey); }
.getResource("/encryption.key").toURI().getPath(); System.setProperty(ENCRYPTION_KEY, encryptionKey); EncryptionUtils.initEncryptionService();
System.setProperty(EncryptionUtils.ENCRYPTION_KEY, keyFile.getPath()); System.setProperty(EncryptionUtils.INIT_KEY_IF_MISSING, "true"); EncryptionUtils.initEncryptionService();