Search in sources :

Example 86 with Assert.assertTrue

use of org.junit.Assert.assertTrue in project rskj by rsksmart.

the class ChannelManagerImplTest method broadcastTransaction_broadcastToAllActivePeers.

@Test
public void broadcastTransaction_broadcastToAllActivePeers() {
    final Transaction transaction = mock(Transaction.class);
    when(transaction.getHash()).thenReturn(TestUtils.randomHash());
    final Map<NodeID, Channel> activePeers = peersForTests(2);
    final ChannelManager channelManager = new ChannelManagerImpl(mock(RskSystemProperties.class), mock(SyncPool.class));
    channelManager.setActivePeers(activePeers);
    final Set<NodeID> broadcastedTo = channelManager.broadcastTransaction(transaction, Collections.emptySet());
    Assert.assertTrue(activePeers.keySet().stream().allMatch(activePeer -> broadcastedTo.contains(activePeer)));
    Assert.assertEquals(2, broadcastedTo.size());
}
Also used : java.util(java.util) TestUtils(org.ethereum.TestUtils) HashUtil(org.ethereum.crypto.HashUtil) NodeManager(org.ethereum.net.NodeManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Keccak256(co.rsk.crypto.Keccak256) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) Block(org.ethereum.core.Block) InetAddress(java.net.InetAddress) Mockito(org.mockito.Mockito) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncPool(org.ethereum.sync.SyncPool) NodeID(co.rsk.net.NodeID) RskSystemProperties(co.rsk.config.RskSystemProperties) Transaction(org.ethereum.core.Transaction) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Transaction(org.ethereum.core.Transaction) SyncPool(org.ethereum.sync.SyncPool) NodeID(co.rsk.net.NodeID) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 87 with Assert.assertTrue

use of org.junit.Assert.assertTrue in project rskj by rsksmart.

the class ChannelManagerImplTest method broadcastTransactions_broadcastToAllActivePeers.

@Test
public void broadcastTransactions_broadcastToAllActivePeers() {
    final Transaction transaction = mock(Transaction.class);
    when(transaction.getHash()).thenReturn(TestUtils.randomHash());
    final List<Transaction> transactions = Collections.singletonList(transaction);
    final Map<NodeID, Channel> activePeers = peersForTests(2);
    final ChannelManager channelManager = new ChannelManagerImpl(mock(RskSystemProperties.class), mock(SyncPool.class));
    channelManager.setActivePeers(activePeers);
    final Set<NodeID> broadcastedTo = channelManager.broadcastTransactions(transactions, Collections.emptySet());
    Assert.assertTrue(activePeers.keySet().stream().allMatch(activePeer -> broadcastedTo.contains(activePeer)));
    Assert.assertEquals(2, broadcastedTo.size());
}
Also used : java.util(java.util) TestUtils(org.ethereum.TestUtils) HashUtil(org.ethereum.crypto.HashUtil) NodeManager(org.ethereum.net.NodeManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Keccak256(co.rsk.crypto.Keccak256) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) Block(org.ethereum.core.Block) InetAddress(java.net.InetAddress) Mockito(org.mockito.Mockito) TestSystemProperties(co.rsk.config.TestSystemProperties) SyncPool(org.ethereum.sync.SyncPool) NodeID(co.rsk.net.NodeID) RskSystemProperties(co.rsk.config.RskSystemProperties) Transaction(org.ethereum.core.Transaction) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Transaction(org.ethereum.core.Transaction) SyncPool(org.ethereum.sync.SyncPool) NodeID(co.rsk.net.NodeID) RskSystemProperties(co.rsk.config.RskSystemProperties) Test(org.junit.Test)

Example 88 with Assert.assertTrue

use of org.junit.Assert.assertTrue in project keycloak by keycloak.

the class AccountFormServiceTest method removeTotpAsDifferentUser.

@Test
public void removeTotpAsDifferentUser() {
    UserResource user1 = ApiUtil.findUserByUsernameId(testRealm(), "user-with-one-configured-otp");
    CredentialRepresentation otpCredential = user1.credentials().stream().filter(credentialRep -> OTPCredentialModel.TYPE.equals(credentialRep.getType())).findFirst().get();
    // Login as evil user (test-user@localhost) and setup TOTP
    totpPage.open();
    loginPage.login("test-user@localhost", "password");
    Assert.assertTrue(totpPage.isCurrent());
    totpPageSetup();
    totpPage.configure(totp.generateTOTP(totpPage.getTotpSecret()));
    Assert.assertEquals("Mobile authenticator configured.", profilePage.getSuccess());
    String currentStateChecker = driver.findElement(By.id("stateChecker")).getAttribute("value");
    // Try to delete TOTP of "user-with-one-configured-otp" by replace ID of the TOTP credential in the request
    String currentURL = driver.getCurrentUrl();
    String formParameters = "stateChecker=" + currentStateChecker + "&submitAction=Delete" + "&credentialId=" + otpCredential.getId();
    URLUtils.sendPOSTRequestWithWebDriver(currentURL, formParameters);
    // Assert credential of "user-with-one-configured-otp" was NOT deleted and is still present for the user
    Assert.assertTrue(user1.credentials().stream().anyMatch(credentialRepresentation -> credentialRepresentation.getType().equals(OTPCredentialModel.TYPE)));
    // Remove TOTP for "test-user" and logout
    totpPage.removeTotp();
    totpPage.logout();
}
Also used : CredentialRepresentation(org.keycloak.representations.idm.CredentialRepresentation) Arrays(java.util.Arrays) ClientAttributeUpdater(org.keycloak.testsuite.updaters.ClientAttributeUpdater) AssertEvents(org.keycloak.testsuite.AssertEvents) Page(org.jboss.arquillian.graphene.page.Page) Matchers.hasItems(org.hamcrest.Matchers.hasItems) OAuthClient(org.keycloak.testsuite.util.OAuthClient) Assert.assertThat(org.junit.Assert.assertThat) Map(java.util.Map) CredentialRepresentation(org.keycloak.representations.idm.CredentialRepresentation) RealmModel(org.keycloak.models.RealmModel) RealmResource(org.keycloak.admin.client.resource.RealmResource) IdentityProviderBuilder(org.keycloak.testsuite.util.IdentityProviderBuilder) DisableFeature(org.keycloak.testsuite.arquillian.annotation.DisableFeature) URLUtils(org.keycloak.testsuite.util.URLUtils) Collectors(java.util.stream.Collectors) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) EventRepresentation(org.keycloak.representations.idm.EventRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) AuthServerTestEnricher(org.keycloak.testsuite.arquillian.AuthServerTestEnricher) List(java.util.List) Details(org.keycloak.events.Details) LoginPage(org.keycloak.testsuite.pages.LoginPage) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Matchers.anyOf(org.hamcrest.Matchers.anyOf) AccountFederatedIdentityPage(org.keycloak.testsuite.pages.AccountFederatedIdentityPage) Matchers.containsString(org.hamcrest.Matchers.containsString) Profile(org.keycloak.common.Profile) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) AdminRoles(org.keycloak.models.AdminRoles) Different(org.keycloak.testsuite.drone.Different) RegisterPage(org.keycloak.testsuite.pages.RegisterPage) WebDriver(org.openqa.selenium.WebDriver) Constants(org.keycloak.models.Constants) DroneUtils(org.keycloak.testsuite.util.DroneUtils) HashMap(java.util.HashMap) ServerURLs.getAuthServerContextRoot(org.keycloak.testsuite.util.ServerURLs.getAuthServerContextRoot) TimeBasedOTP(org.keycloak.models.utils.TimeBasedOTP) AccountUpdateProfilePage(org.keycloak.testsuite.pages.AccountUpdateProfilePage) UserModel(org.keycloak.models.UserModel) RealmBuilder(org.keycloak.testsuite.util.RealmBuilder) AUTH_SERVER_SSL_REQUIRED(org.keycloak.testsuite.util.ServerURLs.AUTH_SERVER_SSL_REQUIRED) Drone(org.jboss.arquillian.drone.api.annotation.Drone) UserBuilder(org.keycloak.testsuite.util.UserBuilder) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Assume(org.junit.Assume) AccountPasswordPage(org.keycloak.testsuite.pages.AccountPasswordPage) UserResource(org.keycloak.admin.client.resource.UserResource) LinkedList(java.util.LinkedList) AuthServer(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer) Before(org.junit.Before) ApiUtil(org.keycloak.testsuite.admin.ApiUtil) AccountTotpPage(org.keycloak.testsuite.pages.AccountTotpPage) AccountApplicationsPage(org.keycloak.testsuite.pages.AccountApplicationsPage) AppPage(org.keycloak.testsuite.pages.AppPage) Errors(org.keycloak.events.Errors) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) CredentialModel(org.keycloak.credential.CredentialModel) Assert.assertNotNull(org.junit.Assert.assertNotNull) RoleScopeUpdater(org.keycloak.testsuite.updaters.RoleScopeUpdater) By(org.openqa.selenium.By) UIUtils(org.keycloak.testsuite.util.UIUtils) Matchers(org.hamcrest.Matchers) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EventType(org.keycloak.events.EventType) OTPCredentialModel(org.keycloak.models.credential.OTPCredentialModel) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) AccountLogPage(org.keycloak.testsuite.pages.AccountLogPage) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Rule(org.junit.Rule) AccountRoles(org.keycloak.models.AccountRoles) AccountSessionsPage(org.keycloak.testsuite.pages.AccountSessionsPage) RequestType(org.keycloak.testsuite.pages.AppPage.RequestType) ErrorPage(org.keycloak.testsuite.pages.ErrorPage) UserProfileContext(org.keycloak.userprofile.UserProfileContext) Assert(org.junit.Assert) PasswordPolicy(org.keycloak.models.PasswordPolicy) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) UserResource(org.keycloak.admin.client.resource.UserResource) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Aggregations

Assert (org.junit.Assert)88 Assert.assertTrue (org.junit.Assert.assertTrue)88 Test (org.junit.Test)88 Assert.assertEquals (org.junit.Assert.assertEquals)84 List (java.util.List)82 Before (org.junit.Before)67 UUID (java.util.UUID)55 Assert.assertFalse (org.junit.Assert.assertFalse)54 Autowired (org.springframework.beans.factory.annotation.Autowired)53 Assert.assertNotNull (org.junit.Assert.assertNotNull)52 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)51 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)51 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)49 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)48 Transactional (org.springframework.transaction.annotation.Transactional)46 After (org.junit.After)44 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)42 ApplicationContext (org.springframework.context.ApplicationContext)38 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)37 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)36