Skip to content

Commit

Permalink
Merge pull request #242 from aivanovski/feature/refactor-fake-file-sy…
Browse files Browse the repository at this point in the history
…stem

Refactor fake file system
  • Loading branch information
aivanovski authored Mar 6, 2024
2 parents e4f0220 + 50ce62a commit c8f431e
Show file tree
Hide file tree
Showing 9 changed files with 643 additions and 501 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.ivanovsky.passnotes.data.repository.file

fun interface DatabaseContentFactory {
fun create(): ByteArray
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
package com.ivanovsky.passnotes.data.repository.file

import app.keemobile.kotpass.database.KeePassDatabase
import app.keemobile.kotpass.database.encode
import com.ivanovsky.passnotes.data.entity.PropertyType
import com.ivanovsky.passnotes.data.repository.file.databaseDsl.EntryEntity
import com.ivanovsky.passnotes.data.repository.file.databaseDsl.GroupEntity
import com.ivanovsky.passnotes.data.repository.file.databaseDsl.KotpassTreeDsl.tree
import java.io.ByteArrayOutputStream
import java.util.UUID

object FakeDatabaseContentFactory {

fun createDefaultLocalDatabase(): ByteArray {
return tree(ROOT) {
group(GROUP_EMAIL)
group(GROUP_INTERNET) {
group(GROUP_CODING) {
entry(ENTRY_LEETCODE)
entry(ENTRY_NEETCODE)
entry(ENTRY_GITHUB)
}
group(GROUP_GAMING) {
entry(ENTRY_STADIA)
}
group(GROUP_SHOPPING)
group(GROUP_SOCIAL)

entry(ENTRY_GOOGLE)
entry(ENTRY_APPLE)
entry(ENTRY_MICROSOFT)
}
entry(ENTRY_NAS_LOGIN)
entry(ENTRY_LAPTOP_LOGIN)
}
.toByteArray()
}

fun createDefaultRemoteDatabase(): ByteArray {
return tree(ROOT) {
group(GROUP_EMAIL)
group(GROUP_INTERNET) {
group(GROUP_CODING) {
entry(ENTRY_LEETCODE)
entry(ENTRY_NEETCODE)
entry(ENTRY_GITLAB)
}
group(GROUP_GAMING) {
entry(ENTRY_STADIA)
}
group(GROUP_SHOPPING) {
entry(ENTRY_AMAZON)
}
group(GROUP_SOCIAL)

entry(ENTRY_GOOGLE)
entry(ENTRY_APPLE)
entry(ENTRY_MICROSOFT_MODIFIED)
}
entry(ENTRY_NAS_LOGIN)
entry(ENTRY_LAPTOP_LOGIN)
entry(ENTRY_MAC_BOOK_LOGIN)
}
.toByteArray()
}

fun createDatabaseWithOtpData(): ByteArray {
return tree(ROOT) {
entry(ENTRY_TOTP)
entry(ENTRY_HOTP)
}
.toByteArray()
}

private fun KeePassDatabase.toByteArray(): ByteArray {
return ByteArrayOutputStream().use { out ->
this.encode(out)
out.toByteArray()
}
}

private val ROOT = GroupEntity(title = "Database")
private val GROUP_EMAIL = GroupEntity(title = "Email", uuid = UUID(100L, 1L))
private val GROUP_INTERNET = GroupEntity(title = "Internet", uuid = UUID(100L, 2L))
private val GROUP_CODING = GroupEntity(title = "Coding", uuid = UUID(100L, 3L))
private val GROUP_GAMING = GroupEntity(title = "Gaming", uuid = UUID(100L, 4L))
private val GROUP_SHOPPING = GroupEntity(title = "Shopping", uuid = UUID(100L, 5L))
private val GROUP_SOCIAL = GroupEntity(title = "Social", uuid = UUID(100L, 7L))

private val TOTP_URL = """
otpauth://totp/Example:john.doe?secret=AAAABBBBCCCCDDDD&period=30
&digits=6&issuer=Example&algorithm=SHA1
""".trimIndent()

private val HOTP_URL = """
otpauth://hotp/Example:john.doe?secret=AAAABBBBCCCCDDDD&digits=6
&issuer=Example&algorithm=SHA1&counter=1
""".trimIndent()

private val ENTRY_NAS_LOGIN = EntryEntity(
title = "NAS Login",
username = "john.doe",
password = "abc123",
created = parseDate("2020-01-01"),
modified = parseDate("2020-01-01")
)

private val ENTRY_LAPTOP_LOGIN = EntryEntity(
title = "Laptop login",
username = "john.doe",
password = "abc123",
created = parseDate("2020-01-02"),
modified = parseDate("2020-01-02")
)

private val ENTRY_MAC_BOOK_LOGIN = EntryEntity(
title = "MacBook Login",
username = "john.doe",
password = "abc123",
created = parseDate("2020-02-01"),
modified = parseDate("2020-02-01")
)

private val ENTRY_GOOGLE = EntryEntity(
title = "Google",
username = "[email protected]",
password = "abc123",
url = "https://google.com",
created = parseDate("2020-01-03"),
modified = parseDate("2020-01-03")
)

private val ENTRY_APPLE = EntryEntity(
title = "Apple",
username = "[email protected]",
password = "abc123",
url = "https://apple.com",
created = parseDate("2020-01-04"),
modified = parseDate("2020-01-04")
)

private val ENTRY_MICROSOFT = EntryEntity(
title = "Microsoft",
username = "[email protected]",
password = "abc123",
url = "https://microsoft.com",
created = parseDate("2020-01-05"),
modified = parseDate("2020-01-05")
)

private val ENTRY_MICROSOFT_MODIFIED = EntryEntity(
title = "Microsoft",
username = "[email protected]",
password = "qwerty",
url = "https://microsoft.com",
created = parseDate("2020-01-05"),
modified = parseDate("2020-01-05")
)

private val ENTRY_LEETCODE = EntryEntity(
title = "Leetcode.com",
username = "[email protected]",
password = "abc123",
url = "https://leetcode.com",
created = parseDate("2020-01-06"),
modified = parseDate("2020-01-06")
)

private val ENTRY_NEETCODE = EntryEntity(
title = "Neetcode.com",
username = "[email protected]",
url = "https://neetcode.io/practice",
created = parseDate("2020-01-07"),
modified = parseDate("2020-01-07")
)

private val ENTRY_GITHUB = EntryEntity(
title = "Github.com",
username = "[email protected]",
password = "abc123",
url = "https://github.com",
created = parseDate("2020-01-08"),
modified = parseDate("2020-01-08")
)

private val ENTRY_GITLAB = EntryEntity(
title = "Gitlab.com",
username = "[email protected]",
password = "abc123",
url = "https://gitlab.com",
created = parseDate("2020-01-08"),
modified = parseDate("2020-01-08")
)

private val ENTRY_STADIA = EntryEntity(
title = "Stadia.com",
username = "[email protected]",
password = "abc123",
created = parseDate("2020-01-09"),
modified = parseDate("2020-01-09")
)

private val ENTRY_AMAZON = EntryEntity(
title = "Amazon.com",
username = "[email protected]",
password = "abc123",
created = parseDate("2020-01-09"),
modified = parseDate("2020-01-09"),
custom = mapOf(
PropertyType.URL.propertyName to "https://amazon.com"
)
)

private val ENTRY_TOTP = EntryEntity(
title = "TOTP Entry",
username = "[email protected]",
password = "",
created = parseDate("2020-01-09"),
modified = parseDate("2020-01-09"),
custom = mapOf(
"otp" to TOTP_URL
)
)

private val ENTRY_HOTP = EntryEntity(
title = "HOTP Entry",
username = "[email protected]",
password = "",
created = parseDate("2020-01-09"),
modified = parseDate("2020-01-09"),
custom = mapOf(
"otp" to HOTP_URL
)
)
}
Loading

0 comments on commit c8f431e

Please sign in to comment.