Files
openide/platform/credential-store-impl/test/CredentialSerializeTest.kt
Roman Shevchenko ddaee68015 [project] giving the credential store implementation module a better name
GitOrigin-RevId: 07a288ca290595c57c0f92fb2c62893a93554a42
2024-06-24 22:28:04 +00:00

35 lines
930 B
Kotlin

// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.credentialStore
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
class CredentialSerializeTest {
@Test
fun join() {
test("foo", "pass", "foo@pass")
test("foo", "\\pass@", "foo@\\pass@")
test("foo@", "pass", "foo\\@@pass")
test("\\foo@", "pass", "\\\\foo\\@@pass")
test("\\foo\\", "pass", "\\\\foo\\\\@pass")
test("foo", "", "foo@")
}
@Test
fun emptyUser() {
test("", "pass", "@pass")
}
@Test
fun nullPassword() {
test("foo", null, "foo")
test(null, "foo@", "@foo@")
}
private fun test(u: String?, p: String?, joined: String) {
val pass = p?.let(::OneTimeString)
assertThat(joinData(u, pass)).isEqualTo(joined.toByteArray())
assertThat(splitData(joined)).isEqualTo(Credentials(u, pass))
}
}