AzureAD / microsoft-authentication-library-common-for-android

Common code used by both the Active Directory Authentication Library (ADAL) and the Microsoft Authentication Library (MSAL)
MIT License
41 stars 35 forks source link

Make changes to BrokerValidator to make it robolectric-compliant #2154

Closed rpdome closed 1 year ago

rpdome commented 1 year ago

Somehow Robolectric doesn't like the previous format. (If I try to shadow BrokerValidator, and in the code I invoke BrokerValidator(context), it seems like Robolectric is unable to find that constructor, and therefore would throw an exception)


com.microsoft.identity.client.BrokerContentProviderWithDispatcherTests > testBrokerApiGetAccounts FAILED
    java.lang.VerifyError: Bad local variable type
    Exception Details:
      Location:
        com/microsoft/identity/common/internal/broker/BrokerValidator.<init>(Landroid/content/Context;)V @1: aload_2
      Reason:
        Type top (current frame, locals[2]) is not assignable to reference type
      Current Frame:
        bci: @1
        flags: { flagThisUninit }
        locals: { uninitializedThis, 'android/content/Context' }
        stack: { uninitializedThis }
      Bytecode:
        0x0000000: 2a2c 0504 54b2 0109 b601 0f2c 0604 54bb
        0x0000010: 002e 592b b701 11c0 00bd 2c07 0454 bb00
        0x0000020: 3059 b200 dcb7 0114 c000 c62c 0804 54b7
        0x0000030: 0116 2ab6 00f9 2a2b ba01 1a00 00b1     
        at com.microsoft.identity.broker.operation.brokerapi.BaseBrokerApiOperation$Companion.getDefaultBrokerValidator(BaseBrokerApiOperation.kt:57)
        at com.microsoft.identity.broker.passthrough.service.BrokerApiService.getOperationByName(BrokerApiService.kt:60)
        at com.microsoft.identity.client.request.AbstractRequestDispatcherHelper.executeWithDispatcher(AbstractRequestDispatcherHelper.kt:175)
        at com.microsoft.identity.client.request.AbstractRequestDispatcherHelper.execute(AbstractRequestDispatcherHelper.kt:121)
        at com.microsoft.identity.client.BrokerContentProvider.processRequestBundle(BrokerContentProvider.java:267)
        at com.microsoft.identity.client.BrokerContentProvider.query(BrokerContentProvider.java:207)
        at android.content.ContentProvider.query(ContentProvider.java:1020)
        at org.robolectric.shadows.ShadowContentResolver.query(ShadowContentResolver.java:292)
        at android.content.ContentResolver.query(ContentResolver.java)
        at com.microsoft.identity.client.AbstractBrokerContentProviderTests.testBrokerApiGetAccounts(AbstractBrokerContentProviderTests.java:251)
        at com.microsoft.identity.client.BrokerContentProviderWithDispatcherTests.testBrokerApiGetAccounts(BrokerContentProviderWithDispatcherTests.kt:125)

This issue somehow only occured in the pipeline though (or perhaps some specific settings triggered it).... I didn't run into the issue as I executed these tests on my machine.

Also optimize the build process by removing jetifier (no longer needed) and increasing max heap size in this pr.