Settings settings = new Settings();
Server server = new Server();
server.setPassphrase( "server_passphrase" );
server.setPassword( "server_password" );
settings.addServer( server );
Proxy proxy = new Proxy();
proxy.setPassword( "proxy_password" );
settings.addProxy( proxy );
ReleaseEnvironment releaseEnvironment = new DefaultReleaseEnvironment();
releaseEnvironment.setSettings( settings );
InvokerMavenExecutor executorSpy = spy( executor );
SettingsXpp3Writer settingsWriter = mock( SettingsXpp3Writer.class );
ArgumentCaptor<Settings> encryptedSettings = ArgumentCaptor.forClass( Settings.class );
when( executorSpy.getSettingsWriter() ).thenReturn( settingsWriter );
when( executorSpy.getOutputHandler() ).thenReturn( null );
when( executorSpy.getInvokerLogger() ).thenReturn( null );
try
{
executorSpy.executeGoals( workingDirectory, "validate", releaseEnvironment, false, null, new ReleaseResult() );
}
catch ( MavenExecutorException e )
{
}
verify( settingsWriter ).write( isA( Writer.class ), encryptedSettings.capture() );
assertNotSame( settings, encryptedSettings.getValue() );
Server encryptedServer = encryptedSettings.getValue().getServers().get( 0 );
assertEquals( "server_passphrase", secDispatcher.decrypt( encryptedServer.getPassphrase() ) );
assertEquals( "server_password", secDispatcher.decrypt( encryptedServer.getPassword() ) );
Proxy encryptedProxy = encryptedSettings.getValue().getProxies().get( 0 );
assertEquals( "proxy_password", secDispatcher.decrypt( encryptedProxy.getPassword() ) );
File settingsSecurity = new File( System.getProperty( "user.home" ), ".m2/settings-security.xml" );
if ( settingsSecurity.exists() )
{
assertFalse( "server_passphrase".equals( encryptedServer.getPassphrase() ) );
assertFalse( "server_password".equals( encryptedServer.getPassword() ) );
assertFalse( "proxy_password".equals( encryptedProxy.getPassword() ) );
}
}