Skip to content

Commit 7c4974f

Browse files
spetrescu84Copilot
andauthored
Add flatUsername attribute to UserAttributes builder Fixes AB#3607103 (#2513)
## Summary Adds a new `flatusername` built-in attribute to the `UserAttributes.Builder` class, following the existing pattern for other attributes (city, country, surname, etc.). ## Changes - **UserAttributes.kt**: Added `FLAT_USERNAME` constant and `flatUsername()` builder method with KDoc. - **SignUpEmailPasswordAttributesTest.kt**: Updated to exercise the new `flatUsername` attribute alongside existing attributes. [AB#3607103](https://identitydivision.visualstudio.com/Engineering/_workitems/edit/3607103) --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent eb7bd59 commit 7c4974f

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

msal/src/main/java/com/microsoft/identity/nativeauth/UserAttributes.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class UserAttributes(internal val userAttributes: Map<String, String>) {
4040
private const val STATE = "state"
4141
private const val STREET_ADDRESS = "streetAddress"
4242
private const val SURNAME = "surname"
43+
private const val FLAT_USERNAME = "flatusername"
4344
}
4445

4546
private val userAttributes = mutableMapOf<String, String>()
@@ -125,6 +126,15 @@ class UserAttributes(internal val userAttributes: Map<String, String>) {
125126
return this
126127
}
127128

129+
/**
130+
* Sets the flat username for the user
131+
* @param flatUsername: Flat username for the user
132+
*/
133+
fun flatUsername(flatUsername: String): Builder {
134+
userAttributes[FLAT_USERNAME] = flatUsername
135+
return this
136+
}
137+
128138
/**
129139
* Sets any custom attribute for the use
130140
* @param key: Name of the attribute

msal/src/test/java/com/microsoft/identity/client/e2e/tests/network/nativeauth/SignUpEmailPasswordAttributesTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SignUpEmailPasswordAttributesTest : NativeAuthPublicClientApplicationAbstr
6868
retryOperation {
6969
runBlocking {
7070
val user = tempEmailApi.generateRandomEmailAddressLocally()
71-
val attributes = UserAttributes.Builder().country("Ireland").city("Dublin").build()
71+
val attributes = UserAttributes.Builder().country("Ireland").city("Dublin").flatUsername("flatusername").build()
7272

7373
val param = NativeAuthSignUpParameters(username = user)
7474
param.password = getSafePassword().toCharArray()

msal/src/test/java/com/microsoft/identity/nativeauth/NativeAuthPublicClientApplicationJavaTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,8 @@ public void testSignUpInvalidEmailReturnsError() throws ExecutionException, Inte
31923192
assertTrue(signUpResult instanceof SignUpError);
31933193
assertTrue(((SignUpError) signUpResult).isInvalidUsername());
31943194
}
3195+
3196+
31953197
}
31963198

31973199
abstract class TestCallback<T> {

msal/src/test/java/com/microsoft/identity/nativeauth/NativeAuthPublicClientApplicationKotlinTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,4 +3042,24 @@ class NativeAuthPublicClientApplicationKotlinTest(private val allowPII: Boolean)
30423042
val submitChallengeResult = nextState4.submitChallenge(code)
30433043
assertResult<SignInResult.Complete>(submitChallengeResult)
30443044
}
3045+
3046+
@Test
3047+
fun testUserAttributesFlatUsernameBuilder() {
3048+
val attrs = UserAttributes.Builder()
3049+
.flatUsername("testuser")
3050+
.build()
3051+
assertEquals("testuser", attrs.userAttributes["flatusername"])
3052+
}
3053+
3054+
@Test
3055+
fun testUserAttributesFlatUsernameWithOtherAttributes() {
3056+
val attrs = UserAttributes.Builder()
3057+
.flatUsername("testuser")
3058+
.displayName("Test User")
3059+
.city("Seattle")
3060+
.build()
3061+
assertEquals("testuser", attrs.userAttributes["flatusername"])
3062+
assertEquals("Test User", attrs.userAttributes["displayName"])
3063+
assertEquals("Seattle", attrs.userAttributes["city"])
3064+
}
30453065
}

0 commit comments

Comments
 (0)