use of com.github.robozonky.common.secrets.SecretProvider in project robozonky by RoboZonky.
the class OperatingModeTest method withConfirmation.
@Test
void withConfirmation() {
final TweaksCommandLineFragment f = mock(TweaksCommandLineFragment.class);
when(f.isDryRunEnabled()).thenReturn(true);
final CommandLine cli = mock(CommandLine.class);
when(cli.getTweaksFragment()).thenReturn(f);
final SecretProvider secretProvider = SecretProvider.fallback("user", "pass".toCharArray());
final Authenticated auth = Authenticated.passwordBased(secretProvider);
final ConfirmationCommandLineFragment fragment = new ConfirmationCommandLineFragment();
fragment.confirmationCredentials = SERVICE + ":" + SERVICE_TOKEN;
when(cli.getConfirmationFragment()).thenReturn(fragment);
final OperatingMode mode = new DaemonOperatingMode(t -> {
});
final Optional<InvestmentMode> config = mode.configure(cli, auth);
assertSoftly(softly -> {
softly.assertThat(config).containsInstanceOf(DaemonInvestmentMode.class);
softly.assertThat(secretProvider.getSecret(SERVICE)).contains(SERVICE_TOKEN.toCharArray());
});
}
use of com.github.robozonky.common.secrets.SecretProvider in project robozonky by RoboZonky.
the class OperatingModeTest method withConfirmationAndUnknownId.
@Test
void withConfirmationAndUnknownId() {
final CommandLine cli = mock(CommandLine.class);
when(cli.getTweaksFragment()).thenReturn(mock(TweaksCommandLineFragment.class));
final SecretProvider secretProvider = SecretProvider.fallback("user", "pass".toCharArray());
final Authenticated auth = Authenticated.passwordBased(secretProvider);
final ConfirmationCommandLineFragment fragment = new ConfirmationCommandLineFragment();
fragment.confirmationCredentials = UUID.randomUUID().toString();
when(cli.getConfirmationFragment()).thenReturn(fragment);
final OperatingMode mode = new DaemonOperatingMode(t -> {
});
final Optional<InvestmentMode> config = mode.configure(cli, auth);
assertThat(config).isEmpty();
assertThat(secretProvider.getSecret(SERVICE)).isEmpty();
}
use of com.github.robozonky.common.secrets.SecretProvider in project robozonky by RoboZonky.
the class AuthenticatedTest method passwordProper.
@Test
void passwordProper() {
// prepare SUT
final SecretProvider sp = SecretProvider.fallback(UUID.randomUUID().toString(), new char[0]);
final String username = sp.getUsername();
final char[] password = sp.getPassword();
final ZonkyApiToken token = new ZonkyApiToken(UUID.randomUUID().toString(), UUID.randomUUID().toString(), 299);
final OAuth oauth = mock(OAuth.class);
when(oauth.login(eq(username), eq(password))).thenReturn(token);
final Zonky z = mock(Zonky.class);
final ApiProvider api = mockApiProvider(oauth, z);
final Authenticated a = Authenticated.passwordBased(api, sp);
// call SUT
final Function<Zonky, Collection<RawInvestment>> f = mock(Function.class);
final Collection<RawInvestment> expectedResult = Collections.emptyList();
when(f.apply(eq(z))).thenReturn(expectedResult);
final Collection<RawInvestment> result = a.call(f);
assertThat(result).isSameAs(expectedResult);
verify(oauth).login(eq(username), eq(password));
verify(oauth, never()).refresh(any());
verify(z).logout();
}
use of com.github.robozonky.common.secrets.SecretProvider in project robozonky by RoboZonky.
the class AuthenticatedTest method passwordLogsOutEvenWhenFailing.
@Test
void passwordLogsOutEvenWhenFailing() {
// prepare SUT
final SecretProvider sp = SecretProvider.fallback(UUID.randomUUID().toString(), new char[0]);
final String username = sp.getUsername();
final char[] password = sp.getPassword();
final ZonkyApiToken token = new ZonkyApiToken(UUID.randomUUID().toString(), UUID.randomUUID().toString(), 299);
final OAuth oauth = mock(OAuth.class);
when(oauth.login(eq(username), eq(password))).thenReturn(token);
final Zonky z = mock(Zonky.class);
final ApiProvider api = mockApiProvider(oauth, z);
final Authenticated a = Authenticated.passwordBased(api, sp);
// call SUT
final Function<Zonky, Collection<RawInvestment>> f = mock(Function.class);
when(f.apply(eq(z))).thenThrow(new IllegalStateException());
assertThatThrownBy(() -> a.call(f)).isInstanceOf(IllegalStateException.class);
verify(z).logout();
}
Aggregations