Skip to content

Commit 9293254

Browse files
Merge branch 'main' into main
2 parents f6139cf + 688dd3a commit 9293254

File tree

21 files changed

+88
-1
lines changed

21 files changed

+88
-1
lines changed

app/src/main/java/com/x8bit/bitwarden/data/auth/datasource/disk/model/AccountJson.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package com.x8bit.bitwarden.data.auth.datasource.disk.model
22

33
import com.x8bit.bitwarden.data.auth.datasource.network.model.KdfTypeJson
44
import com.x8bit.bitwarden.data.auth.datasource.network.model.UserDecryptionOptionsJson
5+
import kotlinx.serialization.Contextual
56
import kotlinx.serialization.ExperimentalSerializationApi
67
import kotlinx.serialization.SerialName
78
import kotlinx.serialization.Serializable
89
import kotlinx.serialization.json.JsonNames
10+
import java.time.ZonedDateTime
911

1012
/**
1113
* Represents the current account information for a given user.
@@ -35,6 +37,7 @@ data class AccountJson(
3537
* @property userId The ID of the user.
3638
* @property email The user's email address.
3739
* @property isEmailVerified Whether or not the user's email is verified.
40+
* @property isTwoFactorEnabled If the profile has two factor authentication enabled.
3841
* @property name The user's name (if applicable).
3942
* @property stamp The account's security stamp (if applicable).
4043
* @property organizationId The ID of the associated organization (if applicable).
@@ -46,6 +49,7 @@ data class AccountJson(
4649
* @property kdfMemory The amount of memory to use when calculating a password hash (MB).
4750
* @property kdfParallelism The number of threads to use when calculating a password hash.
4851
* @property userDecryptionOptions The options available to a user for decryption.
52+
* @property creationDate The creation date of the account.
4953
*/
5054
@OptIn(ExperimentalSerializationApi::class)
5155
@Serializable
@@ -59,6 +63,9 @@ data class AccountJson(
5963
@SerialName("emailVerified")
6064
val isEmailVerified: Boolean?,
6165

66+
@SerialName("isTwoFactorEnabled")
67+
val isTwoFactorEnabled: Boolean?,
68+
6269
@SerialName("name")
6370
val name: String?,
6471

@@ -92,6 +99,10 @@ data class AccountJson(
9299
@SerialName("userDecryptionOptions")
93100
@JsonNames("accountDecryptionOptions")
94101
val userDecryptionOptions: UserDecryptionOptionsJson?,
102+
103+
@SerialName("creationDate")
104+
@Contextual
105+
val creationDate: ZonedDateTime?,
95106
)
96107

97108
/**

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/util/GetTokenResponseExtensions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fun GetTokenResponseJson.Success.toUserState(
2525
userId = userId,
2626
email = jwtTokenData.email,
2727
isEmailVerified = jwtTokenData.isEmailVerified,
28+
isTwoFactorEnabled = null,
2829
name = jwtTokenData.name,
2930
stamp = null,
3031
organizationId = null,
@@ -36,6 +37,7 @@ fun GetTokenResponseJson.Success.toUserState(
3637
kdfMemory = this.kdfMemory,
3738
kdfParallelism = this.kdfParallelism,
3839
userDecryptionOptions = this.userDecryptionOptions,
40+
creationDate = null,
3941
),
4042
settings = AccountJson.Settings(
4143
environmentUrlData = environmentUrlData,

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ fun UserStateJson.toUpdatedUserStateJson(
5959
avatarColorHex = syncProfile.avatarColor,
6060
stamp = syncProfile.securityStamp,
6161
hasPremium = syncProfile.isPremium || syncProfile.isPremiumFromOrganization,
62+
isTwoFactorEnabled = syncProfile.isTwoFactorEnabled,
63+
creationDate = syncProfile.creationDate,
6264
)
6365
val updatedAccount = account.copy(profile = updatedProfile)
6466
return this

app/src/main/java/com/x8bit/bitwarden/data/vault/datasource/network/model/SyncResponseJson.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ data class SyncResponseJson(
153153
* @property key The key of the profile (nullable).
154154
* @property securityStamp The secure stamp of the profile (nullable).
155155
* @property providers A list of providers associated with the profile (nullable).
156+
* @property creationDate The creation date of the account.
156157
*/
157158
@Serializable
158159
data class Profile(
@@ -209,6 +210,10 @@ data class SyncResponseJson(
209210

210211
@SerialName("providers")
211212
val providers: List<Provider>?,
213+
214+
@SerialName("creationDate")
215+
@Contextual
216+
val creationDate: ZonedDateTime,
212217
) {
213218
/**
214219
* Represents an organization in the vault response.

app/src/test/java/com/x8bit/bitwarden/data/auth/datasource/disk/AuthDiskSourceTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import org.junit.jupiter.api.Assertions.assertFalse
3232
import org.junit.jupiter.api.Assertions.assertNull
3333
import org.junit.jupiter.api.Assertions.assertTrue
3434
import org.junit.jupiter.api.Test
35+
import java.time.ZonedDateTime
3536

3637
@Suppress("LargeClass")
3738
class AuthDiskSourceTest {
@@ -1256,6 +1257,7 @@ private const val USER_STATE_JSON = """
12561257
"userId": "activeUserId",
12571258
"email": "email",
12581259
"emailVerified": true,
1260+
"isTwoFactorEnabled": false,
12591261
"name": "name",
12601262
"stamp": "stamp",
12611263
"orgIdentifier": "organizationId",
@@ -1278,7 +1280,8 @@ private const val USER_STATE_JSON = """
12781280
"keyConnectorOption": {
12791281
"keyConnectorUrl": "keyConnectorUrl"
12801282
}
1281-
}
1283+
},
1284+
"creationDate": "2024-09-13T01:00:00.000Z"
12821285
},
12831286
"tokens": {
12841287
"accessToken": "accessToken",
@@ -1318,6 +1321,8 @@ private val USER_STATE = UserStateJson(
13181321
kdfIterations = 600000,
13191322
kdfMemory = 16,
13201323
kdfParallelism = 4,
1324+
isTwoFactorEnabled = false,
1325+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
13211326
userDecryptionOptions = UserDecryptionOptionsJson(
13221327
hasMasterPassword = true,
13231328
trustedDeviceUserDecryptionOptions = TrustedDeviceUserDecryptionOptionsJson(

app/src/test/java/com/x8bit/bitwarden/data/auth/manager/AuthRequestManagerTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,8 @@ private val ACCOUNT: AccountJson = AccountJson(
11681168
kdfMemory = 16,
11691169
kdfParallelism = 4,
11701170
userDecryptionOptions = null,
1171+
isTwoFactorEnabled = false,
1172+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
11711173
),
11721174
tokens = AccountTokensJson(
11731175
accessToken = ACCESS_TOKEN,

app/src/test/java/com/x8bit/bitwarden/data/auth/manager/TrustedDeviceManagerTests.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ private val DEFAULT_ACCOUNT = AccountJson(
297297
kdfMemory = 16,
298298
kdfParallelism = 4,
299299
userDecryptionOptions = DEFAULT_USER_DECRYPTION_OPTIONS,
300+
isTwoFactorEnabled = false,
301+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
300302
),
301303
settings = AccountJson.Settings(
302304
environmentUrlData = EnvironmentUrlDataJson.DEFAULT_US,
@@ -319,6 +321,8 @@ private val UPDATED_ACCOUNT = AccountJson(
319321
kdfMemory = 16,
320322
kdfParallelism = 4,
321323
userDecryptionOptions = UPDATED_USER_DECRYPTION_OPTIONS,
324+
isTwoFactorEnabled = false,
325+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
322326
),
323327
settings = AccountJson.Settings(
324328
environmentUrlData = EnvironmentUrlDataJson.DEFAULT_US,

app/src/test/java/com/x8bit/bitwarden/data/auth/manager/UserLogoutManagerTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import io.mockk.verify
3030
import org.junit.jupiter.api.AfterEach
3131
import org.junit.jupiter.api.Test
3232
import org.junit.jupiter.api.extension.ExtendWith
33+
import java.time.ZonedDateTime
3334

3435
@ExtendWith(MainDispatcherExtension::class)
3536
class UserLogoutManagerTest {
@@ -256,6 +257,8 @@ private val ACCOUNT_1 = AccountJson(
256257
kdfMemory = 16,
257258
kdfParallelism = 4,
258259
userDecryptionOptions = null,
260+
isTwoFactorEnabled = false,
261+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
259262
),
260263
tokens = AccountTokensJson(
261264
accessToken = ACCESS_TOKEN,
@@ -281,6 +284,8 @@ private val ACCOUNT_2 = AccountJson(
281284
kdfMemory = null,
282285
kdfParallelism = null,
283286
userDecryptionOptions = null,
287+
isTwoFactorEnabled = false,
288+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
284289
),
285290
tokens = AccountTokensJson(
286291
accessToken = ACCESS_TOKEN_2,

app/src/test/java/com/x8bit/bitwarden/data/auth/manager/util/TrustDeviceResponseExtensionsTest.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.x8bit.bitwarden.data.auth.datasource.network.model.TrustedDeviceUserD
99
import com.x8bit.bitwarden.data.auth.datasource.network.model.UserDecryptionOptionsJson
1010
import org.junit.jupiter.api.Assertions.assertEquals
1111
import org.junit.jupiter.api.Test
12+
import java.time.ZonedDateTime
1213

1314
class TrustDeviceResponseExtensionsTest {
1415
@Test
@@ -78,6 +79,8 @@ private val DEFAULT_ACCOUNT = AccountJson(
7879
kdfMemory = 16,
7980
kdfParallelism = 4,
8081
userDecryptionOptions = DEFAULT_USER_DECRYPTION_OPTIONS,
82+
isTwoFactorEnabled = false,
83+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
8184
),
8285
settings = AccountJson.Settings(
8386
environmentUrlData = EnvironmentUrlDataJson.DEFAULT_US,
@@ -100,6 +103,8 @@ private val UPDATED_ACCOUNT = AccountJson(
100103
kdfMemory = 16,
101104
kdfParallelism = 4,
102105
userDecryptionOptions = UPDATED_USER_DECRYPTION_OPTIONS,
106+
isTwoFactorEnabled = false,
107+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
103108
),
104109
settings = AccountJson.Settings(
105110
environmentUrlData = EnvironmentUrlDataJson.DEFAULT_US,

app/src/test/java/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6571,6 +6571,8 @@ class AuthRepositoryTest {
65716571
kdfMemory = 16,
65726572
kdfParallelism = 4,
65736573
userDecryptionOptions = null,
6574+
isTwoFactorEnabled = false,
6575+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
65746576
)
65756577
private val ACCOUNT_1 = AccountJson(
65766578
profile = PROFILE_1,
@@ -6594,6 +6596,8 @@ class AuthRepositoryTest {
65946596
kdfMemory = null,
65956597
kdfParallelism = null,
65966598
userDecryptionOptions = null,
6599+
isTwoFactorEnabled = false,
6600+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
65976601
),
65986602
settings = AccountJson.Settings(
65996603
environmentUrlData = null,

app/src/test/java/com/x8bit/bitwarden/data/auth/repository/util/AuthDiskSourceExtensionsTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import kotlinx.coroutines.test.runTest
2020
import org.junit.jupiter.api.Assertions.assertEquals
2121
import org.junit.jupiter.api.Assertions.assertNull
2222
import org.junit.jupiter.api.Test
23+
import java.time.ZonedDateTime
2324

2425
class AuthDiskSourceExtensionsTest {
2526
private val authDiskSource: AuthDiskSource = FakeAuthDiskSource()
@@ -531,6 +532,8 @@ private val MOCK_PROFILE = AccountJson.Profile(
531532
kdfMemory = null,
532533
kdfParallelism = null,
533534
userDecryptionOptions = null,
535+
isTwoFactorEnabled = false,
536+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
534537
)
535538

536539
private val MOCK_ACCOUNT = AccountJson(

app/src/test/java/com/x8bit/bitwarden/data/auth/repository/util/GetTokenResponseExtensionsTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ private val PROFILE_1 = AccountJson.Profile(
141141
kdfMemory = 16,
142142
kdfParallelism = 4,
143143
userDecryptionOptions = null,
144+
isTwoFactorEnabled = null,
145+
creationDate = null,
144146
)
145147
private val ACCOUNT_1 = AccountJson(
146148
profile = PROFILE_1,
@@ -164,6 +166,8 @@ private val ACCOUNT_2 = AccountJson(
164166
kdfMemory = null,
165167
kdfParallelism = null,
166168
userDecryptionOptions = null,
169+
isTwoFactorEnabled = null,
170+
creationDate = null,
167171
),
168172
settings = AccountJson.Settings(
169173
environmentUrlData = EnvironmentUrlDataJson.DEFAULT_US,

app/src/test/java/com/x8bit/bitwarden/data/auth/repository/util/UserStateJsonExtensionsTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import io.mockk.every
2424
import io.mockk.mockk
2525
import org.junit.jupiter.api.Assertions.assertEquals
2626
import org.junit.jupiter.api.Test
27+
import java.time.ZonedDateTime
2728

2829
@Suppress("LargeClass")
2930
class UserStateJsonExtensionsTest {
@@ -59,6 +60,8 @@ class UserStateJsonExtensionsTest {
5960
kdfMemory = 16,
6061
kdfParallelism = 4,
6162
userDecryptionOptions = null,
63+
isTwoFactorEnabled = false,
64+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
6265
)
6366
val originalAccount = AccountJson(
6467
profile = originalProfile,
@@ -110,6 +113,8 @@ class UserStateJsonExtensionsTest {
110113
trustedDeviceUserDecryptionOptions = null,
111114
keyConnectorUserDecryptionOptions = null,
112115
),
116+
isTwoFactorEnabled = false,
117+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
113118
)
114119
val originalAccount = AccountJson(
115120
profile = originalProfile,
@@ -178,6 +183,8 @@ class UserStateJsonExtensionsTest {
178183
kdfMemory = 16,
179184
kdfParallelism = 4,
180185
userDecryptionOptions = null,
186+
isTwoFactorEnabled = false,
187+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
181188
)
182189
val originalAccount = AccountJson(
183190
profile = originalProfile,
@@ -192,6 +199,8 @@ class UserStateJsonExtensionsTest {
192199
profile = originalProfile.copy(
193200
avatarColorHex = "avatarColor",
194201
stamp = "securityStamp",
202+
isTwoFactorEnabled = false,
203+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
195204
),
196205
),
197206
),
@@ -210,6 +219,9 @@ class UserStateJsonExtensionsTest {
210219
every { securityStamp } returns "securityStamp"
211220
every { isPremium } returns true
212221
every { isPremiumFromOrganization } returns true
222+
every { isTwoFactorEnabled } returns false
223+
every { creationDate } returns ZonedDateTime
224+
.parse("2024-09-13T01:00:00.00Z")
213225
}
214226
},
215227
),
@@ -235,6 +247,8 @@ class UserStateJsonExtensionsTest {
235247
kdfMemory = 16,
236248
kdfParallelism = 4,
237249
userDecryptionOptions = null,
250+
isTwoFactorEnabled = false,
251+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
238252
)
239253
val originalAccount = AccountJson(
240254
profile = originalProfile,
@@ -296,6 +310,8 @@ class UserStateJsonExtensionsTest {
296310
keyConnectorUserDecryptionOptions = keyConnectorOptionsJson,
297311
trustedDeviceUserDecryptionOptions = trustedDeviceOptionsJson,
298312
),
313+
isTwoFactorEnabled = false,
314+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
299315
)
300316
val originalAccount = AccountJson(
301317
profile = originalProfile,

app/src/test/java/com/x8bit/bitwarden/data/platform/manager/FirstTimeActionManagerTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
2424
import org.junit.jupiter.api.Assertions.assertFalse
2525
import org.junit.jupiter.api.Assertions.assertTrue
2626
import org.junit.jupiter.api.Test
27+
import java.time.ZonedDateTime
2728

2829
class FirstTimeActionManagerTest {
2930
private val fakeAuthDiskSource = FakeAuthDiskSource()
@@ -328,6 +329,8 @@ private val MOCK_PROFILE = AccountJson.Profile(
328329
kdfMemory = 16,
329330
kdfParallelism = 4,
330331
userDecryptionOptions = MOCK_USER_DECRYPTION_OPTIONS,
332+
isTwoFactorEnabled = false,
333+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
331334
)
332335

333336
private val MOCK_ACCOUNT = AccountJson(

app/src/test/java/com/x8bit/bitwarden/data/platform/repository/SettingsRepositoryTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import org.junit.jupiter.api.Assertions.assertNull
4747
import org.junit.jupiter.api.Assertions.assertTrue
4848
import org.junit.jupiter.api.Test
4949
import java.time.Instant
50+
import java.time.ZonedDateTime
5051

5152
@Suppress("LargeClass")
5253
class SettingsRepositoryTest {
@@ -1259,6 +1260,8 @@ private val MOCK_PROFILE = AccountJson.Profile(
12591260
kdfMemory = 16,
12601261
kdfParallelism = 4,
12611262
userDecryptionOptions = MOCK_USER_DECRYPTION_OPTIONS,
1263+
isTwoFactorEnabled = false,
1264+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
12621265
)
12631266

12641267
private val MOCK_ACCOUNT = AccountJson(

app/src/test/java/com/x8bit/bitwarden/data/tools/generator/repository/GeneratorRepositoryTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import org.junit.jupiter.api.Test
5454
import java.time.Clock
5555
import java.time.Instant
5656
import java.time.ZoneOffset
57+
import java.time.ZonedDateTime
5758

5859
@Suppress("LargeClass")
5960
class GeneratorRepositoryTest {
@@ -788,6 +789,8 @@ private val USER_STATE = UserStateJson(
788789
keyConnectorUrl = "keyConnectorUrl",
789790
),
790791
),
792+
isTwoFactorEnabled = false,
793+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
791794
),
792795
tokens = AccountTokensJson(
793796
accessToken = "accessToken",

app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/network/model/SyncResponseProfileUtil.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fun createMockProfile(number: Int): SyncResponseJson.Profile =
2525
key = "mockKey-$number",
2626
securityStamp = "mockSecurityStamp-$number",
2727
providers = listOf(createMockProvider(number = number)),
28+
creationDate = ZonedDateTime.parse("2024-09-13T01:00:00.00Z"),
2829
)
2930

3031
/**

app/src/test/java/com/x8bit/bitwarden/data/vault/datasource/network/service/SyncServiceTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private const val SYNC_SUCCESS_JSON = """
5555
"forcePasswordReset": false,
5656
"usesKeyConnector": false,
5757
"avatarColor": "mockAvatarColor-1",
58+
"creationDate": "2024-09-13T01:00:00.00Z",
5859
"organizations": [
5960
{
6061
"usePolicies": false,

0 commit comments

Comments
 (0)