app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

ImportSecretDraftTest.kt (1068B)


      1 package org.harvestcircle.application
      2 
      3 import kotlin.test.Test
      4 import kotlin.test.assertEquals
      5 import kotlin.test.assertFailsWith
      6 import kotlin.test.assertTrue
      7 
      8 class ImportSecretDraftTest {
      9     @Test
     10     fun hcSl005DraftIsBoundedRedactedAndOneUse() {
     11         val secret = "nsec1" + "x".repeat(200)
     12         val draft = ImportSecretDraft.from(secret)
     13 
     14         assertEquals(MAX_IMPORT_SECRET_CHARS, draft.length)
     15         assertEquals("ImportSecretDraft([REDACTED])", draft.toString())
     16         assertTrue(secret !in draft.toString())
     17         assertEquals(secret.take(MAX_IMPORT_SECRET_CHARS), draft.take())
     18         assertFailsWith<IllegalStateException> { draft.take() }
     19         assertEquals("", draft.revealForDisplay())
     20     }
     21 
     22     @Test
     23     fun hcSl005ClearIsIdempotentAndDestroysAvailability() {
     24         val draft = ImportSecretDraft.from("distinctive-secret")
     25 
     26         draft.clear()
     27         draft.clear()
     28 
     29         assertEquals(0, draft.length)
     30         assertEquals("", draft.revealForDisplay())
     31         assertFailsWith<IllegalStateException> { draft.take() }
     32     }
     33 }