mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-18 12:36:57 +01:00
Fix unit test
This commit is contained in:
@@ -51,6 +51,7 @@ import static com.google.common.base.Preconditions.*;
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@@ -88,12 +89,17 @@ public class SecureKeyResolver extends SigningKeyResolverAdapter
|
||||
*/
|
||||
@Inject
|
||||
@SuppressWarnings("unchecked")
|
||||
public SecureKeyResolver(ConfigurationEntryStoreFactory storeFactory)
|
||||
public SecureKeyResolver(ConfigurationEntryStoreFactory storeFactory) {
|
||||
this(storeFactory, new SecureRandom());
|
||||
}
|
||||
|
||||
SecureKeyResolver(ConfigurationEntryStoreFactory storeFactory, Random random)
|
||||
{
|
||||
store = storeFactory
|
||||
.withType(SecureKey.class)
|
||||
.withName(STORE_NAME)
|
||||
.build();
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
@@ -163,7 +169,7 @@ public class SecureKeyResolver extends SigningKeyResolverAdapter
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** secure randon */
|
||||
private final SecureRandom random = new SecureRandom();
|
||||
private final Random random;
|
||||
|
||||
/** configuration entry store */
|
||||
private final ConfigurationEntryStore<SecureKey> store;
|
||||
|
||||
@@ -44,12 +44,16 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.store.ConfigurationEntryStore;
|
||||
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.in;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.argThat;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -99,10 +103,11 @@ public class SecureKeyResolverTest
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
@Test
|
||||
public void testResolveSigningKeyBytesWithoutKey()
|
||||
{
|
||||
resolver.resolveSigningKeyBytes(null, Jwts.claims().setSubject("test"));
|
||||
byte[] bytes = resolver.resolveSigningKeyBytes(null, Jwts.claims().setSubject("test"));
|
||||
assertThat(bytes[0]).isEqualTo((byte) 42);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +137,9 @@ public class SecureKeyResolverTest
|
||||
assertThat(storeParameters.getType()).isEqualTo(SecureKey.class);
|
||||
return true;
|
||||
}))).thenReturn(store);
|
||||
resolver = new SecureKeyResolver(factory);
|
||||
Random random = mock(Random.class);
|
||||
doAnswer(invocation -> ((byte[]) invocation.getArguments()[0])[0] = 42).when(random).nextBytes(any());
|
||||
resolver = new SecureKeyResolver(factory, random);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user