Skip to content

Commit 4c2856c

Browse files
authored
Merge branch 'dev' into fadi/server-telemetry
2 parents b1ed1f3 + 06771b8 commit 4c2856c

6 files changed

Lines changed: 89 additions & 265 deletions

File tree

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
vNext
22
----------
3+
4+
Version 24.1.0
5+
----------
36
- [MINOR] Add sovereign cloud (Bleu/Delos/SovSG) instance discovery support with pre-seeded cloud metadata, cache-aware discovery routing, and ensureCloudDiscoveryForAuthority API (#3027)
47
- [PATCH] Fix bug in Authority.getKnownAuthorityResult where cloud discovery failure would skip knownAuthorities check and fix thread safety in Authority.isKnownAuthority and getEquivalentConfiguredAuthority with synchronized block (#3027)
58
- [MINOR] Add helper method in the PackageHelper class for BrokerDiscovery (#3044)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#Wed May 12 20:08:39 UTC 2021
2-
versionName=24.0.1
2+
versionName=24.1.0
33
versionCode=1
44
latestPatchVersion=227

uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/BrokerHost.java

Lines changed: 42 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@
4444
/**
4545
* A model for interacting with the BrokerHost app during UI Test.
4646
* <p>
47-
* By default all the {@link ITestBroker} operations are performed using the {@link SingleWpjApiFragment} class.
47+
* By default all the {@link ITestBroker} operations are performed using the {@link MultipleWpjApiFragment} class.
4848
* if you want to perform specif broker host operations, you need to call the corresponding fragment class
4949
* and then call the corresponding method.
5050
* <p>
51-
* Legacy WPJ operations are contained in the {@link SingleWpjApiFragment} class.
5251
* Multiple WPJ operations are contained in the {@link MultipleWpjApiFragment} class.
5352
* Broker API operations are contained in the {@link BrokerApiFragment} class.
5453
* Broker Flights operations are contained in the {@link BrokerFlightsFragment} class.
@@ -71,11 +70,8 @@ public class BrokerHost extends AbstractTestBroker {
7170
public final BrokerFlightsFragment brokerFlightsFragment;
7271
public final BrokerApiFragment brokerApiFragment;
7372
@Getter
74-
public final SingleWpjApiFragment singleWpjApiFragment;
75-
// If you're writing test specifically for MWPJ, use this fragment
76-
// the default behavior for brokerHost app is to use the SingleWpjApiFragment
77-
@Getter
78-
public final MultipleWpjApiFragment multipleWpjApiFragment;
73+
private final MultipleWpjApiFragment multipleWpjApiFragment;
74+
7975

8076
public BrokerHost() {
8177
this(BROKER_HOST_APK, BROKER_HOST_APK);
@@ -97,53 +93,49 @@ public BrokerHost(@NonNull final String brokerHostApkName,
9793
localUpdateApkFileName = updateBrokerHostApkName;
9894
brokerFlightsFragment = new BrokerFlightsFragment();
9995
brokerApiFragment = new BrokerApiFragment();
100-
singleWpjApiFragment = new SingleWpjApiFragment();
10196
multipleWpjApiFragment = new MultipleWpjApiFragment(this);
10297
}
10398

10499
@Override
105100
public void performDeviceRegistration(@NonNull final String username,
106101
@NonNull final String password) {
107-
singleWpjApiFragment.launch();
108-
singleWpjApiFragment.performDeviceRegistration(
102+
multipleWpjApiFragment.launch();
103+
multipleWpjApiFragment.performDeviceRegistration(
109104
username,
110-
password,
111-
false,
112-
false,
113-
getDefaultBrokerPromptHandlerParameters(username)
105+
password
114106
);
115-
final String joinedUpn = singleWpjApiFragment.getWpjAccount();
116-
Assert.assertTrue("Assert that the joined account is the expected account", username.equalsIgnoreCase(joinedUpn));
117107
}
118108

119109
@Override
120110
public void performDeviceRegistration(@NonNull String username,
121111
@NonNull String password,
122112
boolean isFederatedUser) {
123-
singleWpjApiFragment.launch();
124-
singleWpjApiFragment.performDeviceRegistration(
113+
multipleWpjApiFragment.launch();
114+
multipleWpjApiFragment.performDeviceRegistration(
125115
username,
126116
password,
127-
isFederatedUser,
128117
false,
129-
getDefaultBrokerPromptHandlerParameters(username)
118+
false,
119+
getDefaultBrokerPromptHandlerParameters(username),
120+
isFederatedUser
130121
);
131-
final String joinedUpn = singleWpjApiFragment.getWpjAccount();
122+
final String joinedUpn = multipleWpjApiFragment.getRecordByUpn(username).get("Upn");
132123
Assert.assertTrue("Assert that the joined account is the expected account", username.equalsIgnoreCase(joinedUpn));
133124
}
134125

135126
@Override
136127
public void performSharedDeviceRegistration(String username, String password) {
137128
Logger.i(TAG, "Performing Shared Device Registration for the given account..");
138-
singleWpjApiFragment.launch();
139-
singleWpjApiFragment.performDeviceRegistration(
129+
multipleWpjApiFragment.launch();
130+
multipleWpjApiFragment.performDeviceRegistration(
140131
username,
141132
password,
142-
false,
143133
true,
144-
getDefaultBrokerPromptHandlerParameters(username)
134+
true,
135+
getDefaultBrokerPromptHandlerParameters(username),
136+
false
145137
);
146-
final String joinedUpn = singleWpjApiFragment.getWpjAccount();
138+
final String joinedUpn = multipleWpjApiFragment.getRecordByUpn(username).get("Upn");
147139
Assert.assertTrue("Assert that the joined account is the expected account", username.equalsIgnoreCase(joinedUpn));
148140
}
149141

@@ -156,15 +148,27 @@ public void performSharedDeviceRegistrationDontValidate(@NonNull final String us
156148
@Nullable
157149
@Override
158150
public String obtainDeviceId() {
159-
singleWpjApiFragment.launch();
160-
return singleWpjApiFragment.getDeviceId();
151+
multipleWpjApiFragment.launch();
152+
final List<?> records = multipleWpjApiFragment.getAllRecords();
153+
if (records == null || records.isEmpty()) {
154+
// No WPJ records are available; honor the @Nullable contract.
155+
return null;
156+
}
157+
158+
Assert.assertTrue(
159+
"Expected exactly one WPJ record when obtaining device id, but found: " + records.size(),
160+
records.size() == 1
161+
);
162+
163+
// Safe to access the first record now that we have asserted the size.
164+
return (String) ((java.util.Map<?, ?>) records.get(0)).get("DeviceId");
161165
}
162166

163167
@Override
164168
public void enableBrowserAccess(@NonNull final String username) {
165169
Logger.i(TAG, "Enable Browser Access..");
166-
singleWpjApiFragment.launch();
167-
singleWpjApiFragment.installCertificate();
170+
multipleWpjApiFragment.launch();
171+
multipleWpjApiFragment.installCertificate(username);
168172
}
169173

170174
@Override
@@ -183,31 +187,6 @@ public void initialiseAppImpl() {
183187
// nothing needed here
184188
}
185189

186-
@Nullable
187-
public String getAccountUpn() {
188-
singleWpjApiFragment.launch();
189-
return singleWpjApiFragment.getWpjAccount();
190-
}
191-
192-
@Nullable
193-
public String getDeviceState() {
194-
singleWpjApiFragment.launch();
195-
return singleWpjApiFragment.getDeviceState();
196-
}
197-
198-
@Nullable
199-
public String getBlob(@NonNull final String tenantId) {
200-
Logger.i(TAG, "Get Blob..");
201-
singleWpjApiFragment.launch();
202-
return singleWpjApiFragment.getBlob(tenantId);
203-
}
204-
205-
@NonNull
206-
public String getDeviceToken() {
207-
Logger.i(TAG, "Get Device Token..");
208-
singleWpjApiFragment.launch();
209-
return singleWpjApiFragment.getDeviceToken();
210-
}
211190

212191
@Override
213192
public void overwriteFlights(@NonNull final String flightsJson) {
@@ -233,15 +212,16 @@ public String getFlights() {
233212
public void performDeviceRegistration(@NonNull final String username,
234213
@NonNull final String password,
235214
@NonNull final PromptHandlerParameters promptHandlerParameters) {
236-
singleWpjApiFragment.launch();
237-
singleWpjApiFragment.performDeviceRegistration(
215+
multipleWpjApiFragment.launch();
216+
multipleWpjApiFragment.performDeviceRegistration(
238217
username,
239218
password,
240219
false,
241220
false,
242-
promptHandlerParameters
221+
promptHandlerParameters,
222+
false
243223
);
244-
final String joinedUpn = singleWpjApiFragment.getWpjAccount();
224+
final String joinedUpn = multipleWpjApiFragment.getRecordByUpn(username).get("Upn");
245225
Assert.assertTrue("Assert that the joined account is the expected account", username.equalsIgnoreCase(joinedUpn));
246226
}
247227

@@ -277,15 +257,11 @@ public String obtainDeviceIdLegacyApp() {
277257
}
278258

279259

280-
public void wpjLeave() {
281-
singleWpjApiFragment.launch();
282-
singleWpjApiFragment.wpjLeave();
260+
public void wpjLeave(@NonNull final String username) {
261+
multipleWpjApiFragment.launch();
262+
multipleWpjApiFragment.unregister(username);
283263
}
284264

285-
public void clickJoinTenant(@NonNull final String tenantId) {
286-
singleWpjApiFragment.launch();
287-
singleWpjApiFragment.clickJoinTenant(tenantId);
288-
}
289265

290266
/**
291267
* Gets all the accounts added

uiautomationutilities/src/main/java/com/microsoft/identity/client/ui/automation/broker/MultipleWpjApiFragment.java

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.widget.TextView;
2828

2929
import androidx.annotation.NonNull;
30+
import androidx.annotation.Nullable;
3031
import androidx.test.platform.app.InstrumentationRegistry;
3132
import androidx.test.uiautomator.UiDevice;
3233
import androidx.test.uiautomator.UiObject;
@@ -36,6 +37,7 @@
3637
import com.microsoft.identity.client.ui.automation.interaction.IPromptHandler;
3738
import com.microsoft.identity.client.ui.automation.interaction.PromptHandlerParameters;
3839
import com.microsoft.identity.client.ui.automation.interaction.PromptParameter;
40+
import com.microsoft.identity.client.ui.automation.interaction.microsoftsts.AdfsPromptHandler;
3941
import com.microsoft.identity.client.ui.automation.utils.UiAutomatorUtils;
4042
import com.microsoft.identity.common.java.util.StringUtil;
4143
import com.microsoft.identity.common.java.util.ThreadUtils;
@@ -215,10 +217,12 @@ public String getBlob(@NonNull final String tenantId) {
215217
* @param password the password to be used for device registration
216218
*/
217219
public String performDeviceRegistrationDontValidate(String username, String password) {
218-
return performDeviceRegistrationInternal(
220+
return performDeviceRegistration(
219221
username,
220222
password,
221223
false,
224+
false,
225+
null,
222226
false
223227
);
224228
}
@@ -230,11 +234,13 @@ public String performDeviceRegistrationDontValidate(String username, String pass
230234
* @param password the password to be used for device registration
231235
*/
232236
public void performDeviceRegistration(String username, String password) {
233-
performDeviceRegistrationInternal(
237+
performDeviceRegistration(
234238
username,
235239
password,
236240
false,
237-
true
241+
true,
242+
null,
243+
false
238244
);
239245
}
240246

@@ -245,11 +251,13 @@ public void performDeviceRegistration(String username, String password) {
245251
* @param password the password to be used for device registration
246252
*/
247253
public void performSharedDeviceRegistration(String username, String password) {
248-
performDeviceRegistrationInternal(
254+
performDeviceRegistration(
249255
username,
250256
password,
251257
true,
252-
true
258+
true,
259+
null,
260+
false
253261
);
254262
}
255263

@@ -261,10 +269,13 @@ public void performSharedDeviceRegistration(String username, String password) {
261269
* @param password the password to be used for device registration
262270
* @param isSharedDevice true if the device is a shared device
263271
*/
264-
private String performDeviceRegistrationInternal(@NonNull final String username,
265-
@NonNull final String password,
266-
final boolean isSharedDevice,
267-
final boolean shouldValidate) {
272+
public String performDeviceRegistration(
273+
@NonNull final String username,
274+
@NonNull final String password,
275+
final boolean isSharedDevice,
276+
final boolean shouldValidate,
277+
@Nullable final PromptHandlerParameters userPromptHandlerParameters,
278+
final boolean isFederatedUser) {
268279
launch();
269280
fillTextBox(USERNAME_EDIT_TEXT, username);
270281

@@ -274,26 +285,37 @@ private String performDeviceRegistrationInternal(@NonNull final String username,
274285
clickButton(DEVICE_REGISTRATION_BUTTON_ID);
275286
}
276287

277-
final PromptHandlerParameters promptHandlerParameters = PromptHandlerParameters.builder()
278-
.prompt(PromptParameter.LOGIN)
279-
.broker(brokerHost)
280-
.consentPageExpected(false)
281-
.expectingBrokerAccountChooserActivity(false)
282-
.expectingLoginPageAccountPicker(false)
283-
.sessionExpected(false)
284-
.loginHint(username)
285-
.build();
288+
final PromptHandlerParameters promptHandlerParameters;
289+
if (userPromptHandlerParameters == null) {
290+
promptHandlerParameters = PromptHandlerParameters.builder()
291+
.prompt(PromptParameter.LOGIN)
292+
.broker(brokerHost)
293+
.consentPageExpected(false)
294+
.expectingBrokerAccountChooserActivity(false)
295+
.expectingLoginPageAccountPicker(false)
296+
.sessionExpected(false)
297+
.loginHint(username)
298+
.build();
299+
} else if (isFederatedUser) {
300+
promptHandlerParameters = new AdfsPromptHandler(userPromptHandlerParameters).getParameters();
301+
} else {
302+
promptHandlerParameters = userPromptHandlerParameters;
303+
}
286304

287305

288306
final IPromptHandler promptHandler = getPromptHandler(false, promptHandlerParameters);
289307
promptHandler.handlePrompt(username, password);
290308
ThreadUtils.sleepSafely(1000,"performDeviceRegistrationInternal", "Waiting for result to be returned from the broker");
291309
if (shouldValidate) {
292-
dismissDialogBoxAndAssertContainsText("SUCCESS");
310+
final String dialogText = dismissDialogBoxAndGetText();
311+
Assert.assertTrue(
312+
"Expected dialog text to contain 'SUCCESS' but was: " + dialogText,
313+
!StringUtil.isNullOrEmpty(dialogText) && dialogText.contains("SUCCESS")
314+
);
315+
return dialogText;
293316
} else {
294317
return dismissDialogBoxAndGetText();
295318
}
296-
return null;
297319
}
298320

299321
}

0 commit comments

Comments
 (0)