Skip to content

Commit be0d777

Browse files
committed
update tests
1 parent 72deaa0 commit be0d777

File tree

10 files changed

+141
-10
lines changed

10 files changed

+141
-10
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// All rights reserved.
3+
//
4+
// This code is licensed under the MIT License.
5+
//
6+
// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
// of this software and associated documentation files(the "Software"), to deal
8+
// in the Software without restriction, including without limitation the rights
9+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10+
// copies of the Software, and to permit persons to whom the Software is
11+
// furnished to do so, subject to the following conditions :
12+
//
13+
// The above copyright notice and this permission notice shall be included in
14+
// all copies or substantial portions of the Software.
15+
//
16+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
// THE SOFTWARE.
23+
package com.microsoft.identity.client.msal.automationapp
24+
25+
import android.content.Context
26+
import com.google.gson.Gson
27+
import com.microsoft.identity.client.ui.automation.broker.ITestBroker
28+
import com.microsoft.identity.common.adal.internal.AuthenticationConstants
29+
import com.microsoft.identity.common.adal.internal.AuthenticationConstants.BrokerContentProvider
30+
import com.microsoft.identity.common.internal.broker.ipc.ContentProviderStrategy
31+
import com.microsoft.identity.common.java.util.StringUtil
32+
import java.lang.Exception
33+
34+
object BrokerFlightUtils {
35+
36+
private val sGson = Gson()
37+
38+
/**
39+
* Probe into the broker module of each [BrokerApps] and check if the given flight is enabled
40+
* @param context App Context
41+
* @param flightKey The flight key to verify.
42+
* @param brokerApps The broker app(s) to validate with.
43+
*
44+
* @return true if ALL provided broker apps has the flight enabled. False otherwise.
45+
**/
46+
@JvmStatic
47+
fun isFlightEnabled(context: Context,
48+
flightKey: String,
49+
vararg brokerApps:ITestBroker): Boolean {
50+
for(app in brokerApps) {
51+
val flightValue = getFlightsFromBroker(app, context)[flightKey]
52+
if (flightValue is String && StringUtil.equalsIgnoreCase("true", flightValue)){
53+
continue
54+
}
55+
if (flightValue is Boolean && flightValue == true){
56+
continue
57+
}
58+
return false
59+
}
60+
61+
return true
62+
}
63+
64+
/**
65+
* Makes an IPC request into the broker process to get the flight values.
66+
**/
67+
private fun getFlightsFromBroker(brokerApp: ITestBroker,
68+
context: Context): Map<*, *> {
69+
val cursor = context.contentResolver.query(
70+
ContentProviderStrategy.getContentProviderURI(brokerApp.packageName,
71+
BrokerContentProvider.BROKER_API_GET_FLIGHTS_PATH),
72+
null,
73+
null,
74+
null,
75+
null
76+
) ?: throw Exception("Can't get flights from broker APKs.")
77+
78+
val resultBundle = cursor.extras
79+
return sGson.fromJson(
80+
resultBundle.getString(AuthenticationConstants.Broker.GET_FLIGHTS_RESULT),
81+
Map::class.java)
82+
}
83+
}

msalautomationapp/src/androidTest/java/com/microsoft/identity/client/msal/automationapp/testpass/broker/ltw/TestCase2572249.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import androidx.annotation.NonNull;
2626

27+
import com.microsoft.identity.client.msal.automationapp.BrokerFlightUtils;
2728
import com.microsoft.identity.client.msal.automationapp.R;
2829
import com.microsoft.identity.client.msal.automationapp.testpass.broker.AbstractMsalBrokerTest;
2930
import com.microsoft.identity.client.ui.automation.annotations.LTWTests;
@@ -71,11 +72,17 @@ public static List<UserType> userType() {
7172

7273
@Test
7374
public void test_2572249_LTW_SSOAfterLTWUninstallIfAuthenticatorPresent() throws Throwable {
75+
final BrokerMicrosoftAuthenticator brokerMicrosoftAuthenticator = new BrokerMicrosoftAuthenticator();
76+
77+
if (BrokerFlightUtils.isFlightEnabled(mContext,"EnableBrokerDiscoveryV2Protocol", mBroker, brokerMicrosoftAuthenticator)) {
78+
// No longer applicable with V2 protocol.
79+
return;
80+
}
81+
7482
final String username = mLabAccount.getUsername();
7583
final String password = mLabAccount.getPassword();
7684

7785
// install updated auth app
78-
final BrokerMicrosoftAuthenticator brokerMicrosoftAuthenticator = new BrokerMicrosoftAuthenticator();
7986
brokerMicrosoftAuthenticator.install();
8087

8188
// acquire token interactively in MsalTestApp

msalautomationapp/src/androidTest/java/com/microsoft/identity/client/msal/automationapp/testpass/broker/ltw/TestCase2572294.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import androidx.annotation.NonNull;
2626

27+
import com.microsoft.identity.client.msal.automationapp.BrokerFlightUtils;
2728
import com.microsoft.identity.client.msal.automationapp.R;
2829
import com.microsoft.identity.client.msal.automationapp.testpass.broker.AbstractMsalBrokerTest;
2930
import com.microsoft.identity.client.ui.automation.annotations.LTWTests;
@@ -105,7 +106,13 @@ public void test_2572294_LTW_AuthenticatorHighestPriorityLTWAuthCP() throws Thro
105106

106107
msalTestApp.handleBackButton();
107108
final String activeBroker = msalTestApp.getActiveBrokerPackageName();
108-
Assert.assertEquals("Active broker pkg name : " + BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME, activeBroker);
109+
110+
// Check flight, if v2 is enabled, LTW should have the highest priority.
111+
final String activeBrokerApp = BrokerFlightUtils.isFlightEnabled(mContext,"EnableBrokerDiscoveryV2Protocol", mBroker, brokerCompanyPortal, brokerCompanyPortal) ?
112+
BrokerLTW.BROKER_LTW_APP_PACKAGE_NAME :
113+
BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME;
114+
115+
Assert.assertEquals("Active broker pkg name : " + activeBrokerApp, activeBroker);
109116
}
110117

111118
@Override

msalautomationapp/src/androidTest/java/com/microsoft/identity/client/msal/automationapp/testpass/broker/ltw/TestCase2584409.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import androidx.annotation.NonNull;
2626

27+
import com.microsoft.identity.client.msal.automationapp.BrokerFlightUtils;
2728
import com.microsoft.identity.client.msal.automationapp.R;
2829
import com.microsoft.identity.client.msal.automationapp.testpass.broker.AbstractMsalBrokerTest;
2930
import com.microsoft.identity.client.ui.automation.annotations.LTWTests;
@@ -105,7 +106,13 @@ public void test_2584409_LTW_AuthenticatorHighestPriorityLTWCPAuth() throws Thro
105106

106107
msalTestApp.handleBackButton();
107108
final String activeBroker = msalTestApp.getActiveBrokerPackageName();
108-
Assert.assertEquals("Active broker pkg name : " + BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME, activeBroker);
109+
110+
// Check flight, if v2 is enabled, LTW should have the highest priority.
111+
final String activeBrokerApp = BrokerFlightUtils.isFlightEnabled(mContext,"EnableBrokerDiscoveryV2Protocol", mBroker, brokerMicrosoftAuthenticator, brokerCompanyPortal) ?
112+
BrokerLTW.BROKER_LTW_APP_PACKAGE_NAME :
113+
BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME;
114+
115+
Assert.assertEquals("Active broker pkg name : " + activeBrokerApp, activeBroker);
109116
}
110117

111118
@Override

msalautomationapp/src/androidTest/java/com/microsoft/identity/client/msal/automationapp/testpass/broker/ltw/TestCase2584410.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import androidx.annotation.NonNull;
2626

27+
import com.microsoft.identity.client.msal.automationapp.BrokerFlightUtils;
2728
import com.microsoft.identity.client.msal.automationapp.R;
2829
import com.microsoft.identity.client.msal.automationapp.testpass.broker.AbstractMsalBrokerTest;
2930
import com.microsoft.identity.client.ui.automation.annotations.LTWTests;
@@ -108,7 +109,13 @@ public void test_2584410_LTW_AuthenticatorHighestPriorityAuthLTWCP() throws Thro
108109

109110
msalTestApp.handleBackButton();
110111
final String activeBroker = msalTestApp.getActiveBrokerPackageName();
111-
Assert.assertEquals("Active broker pkg name : " + BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME, activeBroker);
112+
113+
// Check flight, if v2 is enabled, LTW should have the highest priority.
114+
final String activeBrokerApp = BrokerFlightUtils.isFlightEnabled(mContext,"EnableBrokerDiscoveryV2Protocol", mBroker, brokerLTW, brokerCompanyPortal) ?
115+
BrokerLTW.BROKER_LTW_APP_PACKAGE_NAME :
116+
BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME;
117+
118+
Assert.assertEquals("Active broker pkg name : " + activeBrokerApp, activeBroker);
112119
}
113120

114121
@Override

msalautomationapp/src/androidTest/java/com/microsoft/identity/client/msal/automationapp/testpass/broker/ltw/TestCase2584411.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import androidx.annotation.NonNull;
2626

27+
import com.microsoft.identity.client.msal.automationapp.BrokerFlightUtils;
2728
import com.microsoft.identity.client.msal.automationapp.R;
2829
import com.microsoft.identity.client.msal.automationapp.testpass.broker.AbstractMsalBrokerTest;
2930
import com.microsoft.identity.client.ui.automation.annotations.LTWTests;
@@ -67,6 +68,7 @@ public static List<UserType> userType() {
6768
UserType.CLOUD
6869
);
6970
}
71+
7072
@Test
7173
public void test_2584411_LTW_AuthenticatorHighestPriorityAuthCPLTW() throws Throwable {
7274
final String username = mLabAccount.getUsername();
@@ -107,7 +109,13 @@ public void test_2584411_LTW_AuthenticatorHighestPriorityAuthCPLTW() throws Thro
107109

108110
msalTestApp.handleBackButton();
109111
final String activeBroker = msalTestApp.getActiveBrokerPackageName();
110-
Assert.assertEquals("Active broker pkg name : " + BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME, activeBroker);
112+
113+
// Check flight, if v2 is enabled, LTW should have the highest priority.
114+
final String activeBrokerApp = BrokerFlightUtils.isFlightEnabled(mContext,"EnableBrokerDiscoveryV2Protocol", mBroker, brokerLTW, brokerCompanyPortal) ?
115+
BrokerLTW.BROKER_LTW_APP_PACKAGE_NAME :
116+
BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME;
117+
118+
Assert.assertEquals("Active broker pkg name : " + activeBrokerApp, activeBroker);
111119
}
112120

113121
@Override

msalautomationapp/src/androidTest/java/com/microsoft/identity/client/msal/automationapp/testpass/broker/ltw/TestCase2584412.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import androidx.annotation.NonNull;
2626

27+
import com.microsoft.identity.client.msal.automationapp.BrokerFlightUtils;
2728
import com.microsoft.identity.client.msal.automationapp.R;
2829
import com.microsoft.identity.client.msal.automationapp.testpass.broker.AbstractMsalBrokerTest;
2930
import com.microsoft.identity.client.ui.automation.annotations.LTWTests;
@@ -107,7 +108,13 @@ public void test_2584412_LTW_AuthenticatorHighestPriorityCPAuthLTW() throws Thro
107108

108109
msalTestApp.handleBackButton();
109110
final String activeBroker = msalTestApp.getActiveBrokerPackageName();
110-
Assert.assertEquals("Active broker pkg name : " + BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME, activeBroker);
111+
112+
// Check flight, if v2 is enabled, LTW should have the highest priority.
113+
final String activeBrokerApp = BrokerFlightUtils.isFlightEnabled(mContext,"EnableBrokerDiscoveryV2Protocol", mBroker, brokerLTW, brokerMicrosoftAuthenticator) ?
114+
BrokerLTW.BROKER_LTW_APP_PACKAGE_NAME :
115+
BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME;
116+
117+
Assert.assertEquals("Active broker pkg name : " + activeBrokerApp, activeBroker);
111118
}
112119

113120
@Override

msalautomationapp/src/androidTest/java/com/microsoft/identity/client/msal/automationapp/testpass/broker/ltw/TestCase2584414.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import androidx.annotation.NonNull;
2626

27+
import com.microsoft.identity.client.msal.automationapp.BrokerFlightUtils;
2728
import com.microsoft.identity.client.msal.automationapp.R;
2829
import com.microsoft.identity.client.msal.automationapp.testpass.broker.AbstractMsalBrokerTest;
2930
import com.microsoft.identity.client.ui.automation.annotations.LTWTests;
@@ -107,7 +108,13 @@ public void test_2584414_LTW_AuthenticatorHighestPriorityCPLTWAuth() throws Thro
107108

108109
msalTestApp.handleBackButton();
109110
final String activeBroker = msalTestApp.getActiveBrokerPackageName();
110-
Assert.assertEquals("Active broker pkg name : " + BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME, activeBroker);
111+
112+
// Check flight, if v2 is enabled, LTW should have the highest priority.
113+
final String activeBrokerApp = BrokerFlightUtils.isFlightEnabled(mContext,"EnableBrokerDiscoveryV2Protocol", mBroker, brokerLTW, brokerMicrosoftAuthenticator) ?
114+
BrokerLTW.BROKER_LTW_APP_PACKAGE_NAME :
115+
BrokerMicrosoftAuthenticator.AUTHENTICATOR_APP_PACKAGE_NAME;
116+
117+
Assert.assertEquals("Active broker pkg name : " + activeBrokerApp, activeBroker);
111118
}
112119
@Override
113120
public LabQuery getLabQuery() {

msalautomationapp/src/androidTest/java/com/microsoft/identity/client/msal/automationapp/testpass/broker/ltw/TestCase3029738.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import androidx.annotation.NonNull;
2626

27-
import com.microsoft.identity.client.msal.automationapp.BuildConfig;
2827
import com.microsoft.identity.client.msal.automationapp.R;
2928
import com.microsoft.identity.client.msal.automationapp.testpass.broker.AbstractMsalBrokerTest;
3029
import com.microsoft.identity.client.ui.automation.annotations.LTWTests;
@@ -40,7 +39,6 @@
4039
import com.microsoft.identity.labapi.utilities.constants.UserType;
4140

4241
import org.junit.Assert;
43-
import org.junit.Assume;
4442
import org.junit.Test;
4543
import org.junit.runner.RunWith;
4644
import org.junit.runners.Parameterized;

0 commit comments

Comments
 (0)