Search in sources :

Example 6 with IIpcStrategy

use of com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy in project microsoft-authentication-library-common-for-android by AzureAD.

the class BrokerOperationExecutorTests method getStrategyWithServiceExceptionResult.

// Gets a bundle back, the bundle contains a service exception result.
private IIpcStrategy getStrategyWithServiceExceptionResult() {
    return new IIpcStrategy() {

        @Override
        @NonNull
        public Bundle communicateToBroker(@NonNull final BrokerOperationBundle bundle) throws BrokerCommunicationException {
            final Bundle result = new Bundle();
            result.putBoolean(SERVICE_EXCEPTION_BUNDLE_KEY, true);
            return result;
        }

        @Override
        public Type getType() {
            return MOCK_TYPE;
        }
    };
}
Also used : BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) Bundle(android.os.Bundle) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) IIpcStrategy(com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy) NonNull(androidx.annotation.NonNull)

Example 7 with IIpcStrategy

use of com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy in project microsoft-authentication-library-common-for-android by AzureAD.

the class HelloCacheTests method testHelloShouldOnlyTriggerOnce.

@Test
public void testHelloShouldOnlyTriggerOnce() {
    final String minimumVer = "1.0";
    final String negotiatedVer = "2.5";
    class MockStrategy implements IIpcStrategy {

        int triggered = 0;

        @Nullable
        @Override
        public Bundle communicateToBroker(@NonNull BrokerOperationBundle bundle) throws BrokerCommunicationException {
            triggered += 1;
            if (triggered == 2) {
                Assert.fail("Should never be triggered");
            }
            final Bundle resultBundle = new Bundle();
            resultBundle.putString(NEGOTIATED_BP_VERSION_KEY, negotiatedVer);
            return resultBundle;
        }

        @Override
        public Type getType() {
            return Type.CONTENT_PROVIDER;
        }
    }
    class MockController extends BrokerMsalController {

        public MockController(Context applicationContext) {
            super(applicationContext);
        }

        @Override
        public HelloCache getHelloCache() {
            return HelloCacheTests.this.getHelloCache(protocolA);
        }

        @Override
        public String getActiveBrokerPackageName() {
            return brokerAppName;
        }
    }
    final MockController controller = new MockController(ApplicationProvider.getApplicationContext());
    final MockStrategy strategy = new MockStrategy();
    final CommandParameters parameters = CommandParameters.builder().requiredBrokerProtocolVersion(minimumVer).build();
    try {
        final String negotiatedProtocolVersion = controller.hello(strategy, parameters.getRequiredBrokerProtocolVersion());
        final String negotiatedProtocolVersion2 = controller.hello(strategy, parameters.getRequiredBrokerProtocolVersion());
        Assert.assertEquals(negotiatedProtocolVersion, negotiatedProtocolVersion2);
    } catch (BaseException e) {
        Assert.fail();
    }
}
Also used : Context(android.content.Context) BaseException(com.microsoft.identity.common.exception.BaseException) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) Bundle(android.os.Bundle) BrokerOperationBundle(com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle) NonNull(androidx.annotation.NonNull) IIpcStrategy(com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy) CommandParameters(com.microsoft.identity.common.internal.commands.parameters.CommandParameters) BrokerMsalController(com.microsoft.identity.common.internal.controllers.BrokerMsalController) Test(org.junit.Test)

Example 8 with IIpcStrategy

use of com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy in project microsoft-authentication-library-common-for-android by AzureAD.

the class IpcStrategyTests method testIpcConnectionFailed.

protected void testIpcConnectionFailed(@NonNull final BrokerOperationBundle bundle) {
    final IIpcStrategy strategy = getStrategy();
    try {
        strategy.communicateToBroker(bundle);
        Assert.fail("Operation should fail.");
    } catch (BaseException e) {
        Assert.assertTrue(e instanceof BrokerCommunicationException);
        Assert.assertSame(((BrokerCommunicationException) e).getCategory(), CONNECTION_ERROR);
        Assert.assertSame(((BrokerCommunicationException) e).getStrategyType(), strategy.getType());
    }
}
Also used : BaseException(com.microsoft.identity.common.exception.BaseException) IIpcStrategy(com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy) BrokerCommunicationException(com.microsoft.identity.common.exception.BrokerCommunicationException)

Example 9 with IIpcStrategy

use of com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy in project microsoft-authentication-library-common-for-android by AzureAD.

the class IpcStrategyTests method testOperationNotSupportedOnClientSide.

protected void testOperationNotSupportedOnClientSide(@NonNull final BrokerOperationBundle bundle) {
    final IIpcStrategy strategy = getStrategy();
    try {
        strategy.communicateToBroker(bundle);
        Assert.fail("Operation should fail.");
    } catch (BaseException e) {
        Assert.assertTrue(e instanceof BrokerCommunicationException);
        Assert.assertSame(((BrokerCommunicationException) e).getCategory(), OPERATION_NOT_SUPPORTED_ON_CLIENT_SIDE);
        Assert.assertSame(((BrokerCommunicationException) e).getStrategyType(), strategy.getType());
    }
}
Also used : BaseException(com.microsoft.identity.common.exception.BaseException) IIpcStrategy(com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy) BrokerCommunicationException(com.microsoft.identity.common.exception.BrokerCommunicationException)

Aggregations

IIpcStrategy (com.microsoft.identity.common.internal.broker.ipc.IIpcStrategy)9 Bundle (android.os.Bundle)5 NonNull (androidx.annotation.NonNull)5 BaseException (com.microsoft.identity.common.exception.BaseException)5 BrokerOperationBundle (com.microsoft.identity.common.internal.broker.ipc.BrokerOperationBundle)5 BrokerCommunicationException (com.microsoft.identity.common.exception.BrokerCommunicationException)3 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 BaseBundle (android.os.BaseBundle)1 ClientException (com.microsoft.identity.common.exception.ClientException)1 MicrosoftAuthClient (com.microsoft.identity.common.internal.broker.MicrosoftAuthClient)1 AccountManagerAddAccountStrategy (com.microsoft.identity.common.internal.broker.ipc.AccountManagerAddAccountStrategy)1 ContentProviderStrategy (com.microsoft.identity.common.internal.broker.ipc.ContentProviderStrategy)1 CommandParameters (com.microsoft.identity.common.internal.commands.parameters.CommandParameters)1 BrokerMsalController (com.microsoft.identity.common.internal.controllers.BrokerMsalController)1 Test (org.junit.Test)1