Search in sources :

Example 1 with InternalApiSignatureKeyGenerator

use of com.emc.storageos.security.authentication.InternalApiSignatureKeyGenerator in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method testPlannedFailover_noError.

@Test
public void testPlannedFailover_noError() throws Exception {
    List<Site> sites = new ArrayList<>();
    sites.add(primarySite);
    sites.add(standbySite2);
    SecretKey keyMock = mock(SecretKey.class);
    InternalApiSignatureKeyGenerator apiSignatureGeneratorMock = mock(InternalApiSignatureKeyGenerator.class);
    doReturn("SecreteKey".getBytes()).when(keyMock).getEncoded();
    doReturn(keyMock).when(apiSignatureGeneratorMock).getSignatureKey(SignatureKeyType.INTERVDC_API);
    doReturn(sites).when(drUtil).listSites();
    doReturn(primarySite).when(drUtil).getActiveSite();
    doReturn(true).when(drUtil).isSiteUp(standbySite2.getUuid());
    doReturn(ClusterInfo.ClusterState.STABLE).when(coordinator).getControlNodesState(standbySite2.getUuid());
    doReturn(mock(DistributedBarrier.class)).when(coordinator).getDistributedBarrier(any(String.class));
    doNothing().when(drService).precheckForSwitchover(standbySite2.getUuid());
    drService.setApiSignatureGenerator(apiSignatureGeneratorMock);
    drService.doSwitchover(standbySite2.getUuid());
    verify(coordinator, times(1)).persistServiceConfiguration(any(Configuration.class));
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) SecretKey(javax.crypto.SecretKey) Configuration(com.emc.storageos.coordinator.common.Configuration) DistributedBarrier(org.apache.curator.framework.recipes.barriers.DistributedBarrier) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) InternalApiSignatureKeyGenerator(com.emc.storageos.security.authentication.InternalApiSignatureKeyGenerator) Test(org.junit.Test)

Example 2 with InternalApiSignatureKeyGenerator

use of com.emc.storageos.security.authentication.InternalApiSignatureKeyGenerator in project coprhd-controller by CoprHD.

the class VdcControllerTest method setup.

@Before
public void setup() throws Exception {
    vdcController = new VdcControllerImpl();
    MockCoordinatorClient coordinator = new MockCoordinatorClient();
    // setup mock objects for vdc controller test
    dbClient = new MockDbClient();
    vdcController.setDbClient(dbClient);
    InternalApiSignatureKeyGenerator secretKeyGenerator = new InternalApiSignatureKeyGenerator() {

        public synchronized void loadKeys() {
        }

        public SecretKey getSignatureKey(SignatureKeyType type) {
            return SignatureHelper.createKey("test", InternalApiSignatureKeyGenerator.CURRENT_INTERVDC_API_SIGN_ALGO);
        }
    };
    clientManager = new MockGeoClientCacheManager(coordinator, secretKeyGenerator);
    vdcController.setGeoClientManager(clientManager);
    vdcController.setVdcOperationLockHelper(new MockVdcOperationLockHelper());
    keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    password = "some password".toCharArray();
    keystore.load(null, password);
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
    keyGen.initialize(512, new SecureRandom());
    CertAndKeyGen keypair = new CertAndKeyGen("RSA", "SHA1WithRSA", null);
    X500Name x500Name = new X500Name("EMC", "EMC", "EMC", "EMC", "MA", "US");
    keypair.generate(512);
    PrivateKey privKey = keypair.getPrivateKey();
    chain = new X509Certificate[1];
    chain[0] = keypair.getSelfCertificate(x500Name, new Date(), (long) 365 * 24 * 60 * 60);
    keystore.setKeyEntry(KeystoreEngine.ViPR_KEY_AND_CERTIFICATE_ALIAS, privKey, password, chain);
    vdcController.setKeystore(keystore);
    vdcController.setSignatureGenerator(secretKeyGenerator);
    BasePermissionsHelper permissionsHelper = new BasePermissionsHelper(dbClient);
    vdcController.setPermissionsHelper(permissionsHelper);
    // Setup helper based on mocked db client
    VdcConfigHelper helper = new VdcConfigHelper();
    helper.setDbClient(dbClient);
    helper.setGeoClientCacheManager(clientManager);
    helper.setCoordinatorClient(coordinator);
    vdcController.setVdcHelper(helper);
    VdcUtil.setDbClient(dbClient);
    dbClient.buildGeodbData();
}
Also used : PrivateKey(java.security.PrivateKey) SecureRandom(java.security.SecureRandom) VdcControllerImpl(com.emc.storageos.geo.vdccontroller.impl.VdcControllerImpl) KeyPairGenerator(java.security.KeyPairGenerator) X500Name(sun.security.x509.X500Name) Date(java.util.Date) CertAndKeyGen(sun.security.tools.keytool.CertAndKeyGen) InternalApiSignatureKeyGenerator(com.emc.storageos.security.authentication.InternalApiSignatureKeyGenerator) BasePermissionsHelper(com.emc.storageos.security.authorization.BasePermissionsHelper) VdcConfigHelper(com.emc.storageos.geo.service.impl.util.VdcConfigHelper) Before(org.junit.Before)

Aggregations

InternalApiSignatureKeyGenerator (com.emc.storageos.security.authentication.InternalApiSignatureKeyGenerator)2 Site (com.emc.storageos.coordinator.client.model.Site)1 Configuration (com.emc.storageos.coordinator.common.Configuration)1 VdcConfigHelper (com.emc.storageos.geo.service.impl.util.VdcConfigHelper)1 VdcControllerImpl (com.emc.storageos.geo.vdccontroller.impl.VdcControllerImpl)1 BasePermissionsHelper (com.emc.storageos.security.authorization.BasePermissionsHelper)1 KeyPairGenerator (java.security.KeyPairGenerator)1 PrivateKey (java.security.PrivateKey)1 SecureRandom (java.security.SecureRandom)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 SecretKey (javax.crypto.SecretKey)1 DistributedBarrier (org.apache.curator.framework.recipes.barriers.DistributedBarrier)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 CertAndKeyGen (sun.security.tools.keytool.CertAndKeyGen)1 X500Name (sun.security.x509.X500Name)1