Skip to content

Commit a4ff3cb

Browse files
authored
Add homeObjectId to ILabAcccount, Fixes AB#3463642 (#2836)
Add homeObjectId to ILabAcccount. The value will be used in Resource account automation and can potentially be used for other purposes in future. Fixes [AB#3463642](https://identitydivision.visualstudio.com/fac9d424-53d2-45c0-91b5-ef6ba7a6bf26/_workitems/edit/3463642)
1 parent 27f3aa9 commit a4ff3cb

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

LabApiUtilities/src/main/com/microsoft/identity/labapi/utilities/client/ILabAccount.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ public interface ILabAccount {
5858
*/
5959
String getHomeTenantId();
6060

61+
/**
62+
* Get the object id in home tenant.
63+
*
64+
* @return a String representing the account's object id in home tenant
65+
*/
66+
String getHomeObjectId();
67+
6168
/**
6269
* A client id that can be used alongside this account to get a token.
6370
*

LabApiUtilities/src/main/com/microsoft/identity/labapi/utilities/client/LabAccount.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public class LabAccount implements ILabAccount {
5252
@NonNull
5353
private final String mHomeTenantId;
5454

55+
@NonNull
56+
private final String mHomeObjectId;
57+
5558
// nullable
5659
// dependency for Nullable annotation not currently added to LabApiUtilities
5760
private final ConfigInfo mConfigInfo;

LabApiUtilities/src/main/com/microsoft/identity/labapi/utilities/client/LabClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ private ILabAccount getLabAccountObject(@NonNull final ConfigInfo configInfo) th
144144
.password(password)
145145
.userType(UserType.fromName(configInfo.getUserInfo().getUserType()))
146146
.homeTenantId(configInfo.getUserInfo().getHomeTenantID())
147+
.homeObjectId(configInfo.getUserInfo().getHomeObjectId())
147148
.configInfo(configInfo)
148149
.build();
149150
}
@@ -252,6 +253,7 @@ private ILabAccount createTempAccountInternal(@NonNull final TempUserType tempUs
252253
// all temp users created by Lab Api are currently cloud users
253254
.userType(UserType.CLOUD)
254255
.homeTenantId(tempUser.getTenantId())
256+
.homeObjectId(tempUser.getObjectId())
255257
.build();
256258
}
257259

LabApiUtilities/src/test/com/microsoft/identity/labapi/utilities/client/LabClientTest.java

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.junit.After;
3434
import org.junit.Assert;
3535
import org.junit.Before;
36-
import org.junit.Ignore;
3736
import org.junit.Rule;
3837
import org.junit.Test;
3938

@@ -73,12 +72,7 @@ public void canFetchCloudAccount() {
7372

7473
try {
7574
final ILabAccount labAccount = mLabClient.getLabAccount(query);
76-
Assert.assertNotNull(labAccount);
77-
Assert.assertNotNull(labAccount.getUsername());
78-
Assert.assertNotNull(labAccount.getPassword());
79-
Assert.assertNotNull(labAccount.getUserType());
80-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("msidlab4"));
81-
Assert.assertEquals(UserType.CLOUD, labAccount.getUserType());
75+
assertLabAccount(labAccount, UserType.CLOUD, "msidlab4");
8276
} catch (final LabApiException e) {
8377
throw new AssertionError(e);
8478
}
@@ -92,12 +86,7 @@ public void canFetchMSAAccount() {
9286

9387
try {
9488
final ILabAccount labAccount = mLabClient.getLabAccount(query);
95-
Assert.assertNotNull(labAccount);
96-
Assert.assertNotNull(labAccount.getUsername());
97-
Assert.assertNotNull(labAccount.getPassword());
98-
Assert.assertNotNull(labAccount.getUserType());
99-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("outlook"));
100-
Assert.assertEquals(UserType.MSA, labAccount.getUserType());
89+
assertLabAccount(labAccount, UserType.MSA, "outlook");
10190
} catch (final LabApiException e) {
10291
throw new AssertionError(e);
10392
}
@@ -111,12 +100,7 @@ public void canFetchGuestAccount() {
111100

112101
try {
113102
final ILabAccount labAccount = mLabClient.getLabAccount(query);
114-
Assert.assertNotNull(labAccount);
115-
Assert.assertNotNull(labAccount.getUsername());
116-
Assert.assertNotNull(labAccount.getPassword());
117-
Assert.assertNotNull(labAccount.getUserType());
118-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("msidlab4"));
119-
Assert.assertEquals(UserType.GUEST, labAccount.getUserType());
103+
assertLabAccount(labAccount, UserType.GUEST, "msidlab4");
120104
} catch (final LabApiException e) {
121105
throw new AssertionError(e);
122106
}
@@ -130,12 +114,7 @@ public void canFetchFederatedAccount() {
130114

131115
try {
132116
final ILabAccount labAccount = mLabClient.getLabAccount(query);
133-
Assert.assertNotNull(labAccount);
134-
Assert.assertNotNull(labAccount.getUsername());
135-
Assert.assertNotNull(labAccount.getPassword());
136-
Assert.assertNotNull(labAccount.getUserType());
137-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("msidlab4"));
138-
Assert.assertEquals(UserType.FEDERATED, labAccount.getUserType());
117+
assertLabAccount(labAccount, UserType.FEDERATED, "msidlab4");
139118
} catch (final LabApiException e) {
140119
throw new AssertionError(e);
141120
}
@@ -145,12 +124,7 @@ public void canFetchFederatedAccount() {
145124
public void canCreateBasicTempUser() {
146125
try {
147126
final ILabAccount labAccount = mLabClient.createTempAccount(TempUserType.BASIC);
148-
Assert.assertNotNull(labAccount);
149-
Assert.assertNotNull(labAccount.getUsername());
150-
Assert.assertNotNull(labAccount.getPassword());
151-
Assert.assertNotNull(labAccount.getUserType());
152-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("msidlab4"));
153-
Assert.assertEquals(UserType.CLOUD, labAccount.getUserType());
127+
assertLabAccount(labAccount, UserType.CLOUD, "msidlab4");
154128
} catch (final LabApiException e) {
155129
throw new AssertionError(e);
156130
}
@@ -160,11 +134,7 @@ public void canCreateBasicTempUser() {
160134
public void canCreateMAMCATempUser() {
161135
try {
162136
final ILabAccount labAccount = mLabClient.createTempAccount(TempUserType.MAM_CA);
163-
Assert.assertNotNull(labAccount);
164-
Assert.assertNotNull(labAccount.getUsername());
165-
Assert.assertNotNull(labAccount.getPassword());
166-
Assert.assertNotNull(labAccount.getUserType());
167-
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains("msidlab4"));
137+
assertLabAccount(labAccount, UserType.CLOUD, "msidlab4");
168138
} catch (final LabApiException e) {
169139
throw new AssertionError(e);
170140
}
@@ -203,4 +173,22 @@ public void canDisablePolicy() {
203173
}
204174
}
205175

176+
177+
// Helper to assert common properties of a lab account
178+
private void assertLabAccount(final ILabAccount labAccount,
179+
final UserType expectedUserType,
180+
final String expectedUsernameContains) {
181+
Assert.assertNotNull(labAccount);
182+
Assert.assertNotNull(labAccount.getUsername());
183+
Assert.assertNotNull(labAccount.getPassword());
184+
Assert.assertNotNull(labAccount.getUserType());
185+
if (expectedUsernameContains != null) {
186+
Assert.assertTrue(labAccount.getUsername().toLowerCase().contains(expectedUsernameContains));
187+
}
188+
if (expectedUserType != null) {
189+
Assert.assertEquals(expectedUserType, labAccount.getUserType());
190+
}
191+
Assert.assertNotNull(labAccount.getHomeObjectId());
192+
Assert.assertNotNull(labAccount.getHomeTenantId());
193+
}
206194
}

0 commit comments

Comments
 (0)