Search in sources :

Example 6 with SecretProvider

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());
    });
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) DaemonInvestmentMode(com.github.robozonky.app.configuration.daemon.DaemonInvestmentMode) SecretProvider(com.github.robozonky.common.secrets.SecretProvider) Test(org.junit.jupiter.api.Test)

Example 7 with SecretProvider

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();
}
Also used : Authenticated(com.github.robozonky.app.authentication.Authenticated) DaemonInvestmentMode(com.github.robozonky.app.configuration.daemon.DaemonInvestmentMode) SecretProvider(com.github.robozonky.common.secrets.SecretProvider) Test(org.junit.jupiter.api.Test)

Example 8 with SecretProvider

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();
}
Also used : ApiProvider(com.github.robozonky.common.remote.ApiProvider) Collection(java.util.Collection) RawInvestment(com.github.robozonky.api.remote.entities.RawInvestment) ZonkyApiToken(com.github.robozonky.api.remote.entities.ZonkyApiToken) SecretProvider(com.github.robozonky.common.secrets.SecretProvider) OAuth(com.github.robozonky.common.remote.OAuth) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Example 9 with SecretProvider

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();
}
Also used : ApiProvider(com.github.robozonky.common.remote.ApiProvider) Collection(java.util.Collection) ZonkyApiToken(com.github.robozonky.api.remote.entities.ZonkyApiToken) SecretProvider(com.github.robozonky.common.secrets.SecretProvider) OAuth(com.github.robozonky.common.remote.OAuth) Zonky(com.github.robozonky.common.remote.Zonky) Test(org.junit.jupiter.api.Test) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest)

Aggregations

SecretProvider (com.github.robozonky.common.secrets.SecretProvider)9 Test (org.junit.jupiter.api.Test)7 Authenticated (com.github.robozonky.app.authentication.Authenticated)5 DaemonInvestmentMode (com.github.robozonky.app.configuration.daemon.DaemonInvestmentMode)4 ZonkyApiToken (com.github.robozonky.api.remote.entities.ZonkyApiToken)3 AbstractZonkyLeveragingTest (com.github.robozonky.app.AbstractZonkyLeveragingTest)3 ApiProvider (com.github.robozonky.common.remote.ApiProvider)3 OAuth (com.github.robozonky.common.remote.OAuth)3 Zonky (com.github.robozonky.common.remote.Zonky)3 Collection (java.util.Collection)3 RawInvestment (com.github.robozonky.api.remote.entities.RawInvestment)2 ConfirmationProvider (com.github.robozonky.api.confirmations.ConfirmationProvider)1 SessionInfo (com.github.robozonky.api.notifications.SessionInfo)1 Events (com.github.robozonky.app.Events)1 Investor (com.github.robozonky.app.investing.Investor)1 ConfirmationProviderLoader (com.github.robozonky.common.extensions.ConfirmationProviderLoader)1 Credentials (com.github.robozonky.common.secrets.Credentials)1 ToStringBuilder (com.github.robozonky.internal.api.ToStringBuilder)1 Optional (java.util.Optional)1 Logger (org.slf4j.Logger)1