package com.peachpasswords.ui.lock import com.peachpasswords.ui.security.scorePassword import org.junit.Assert.assertEquals import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Test /** * LockScreen suite (brief Suite 6): the create-vault validation rules and their * gating constants. The biometric/auto-lock paths need an instrumented device. */ class LockScreenTest { @Test fun min_password_length_is_twelve() = assertEquals(12, MIN_PASSWORD_LENGTH) @Test fun min_create_strength_is_two() = assertEquals(2, MIN_CREATE_STRENGTH) @Test fun password_below_minimum_length_is_rejected() { val err = createValidationError("short", "short", score = 4) assertEquals("password must be at least 12 characters", err) } @Test fun weak_password_is_rejected_even_when_long() { // 16 identical chars: long enough but trivially weak (score < 2). val pw = "aaaaaaaaaaaaaaaa" assertTrue("sanity: this password really is weak", scorePassword(pw) < MIN_CREATE_STRENGTH) assertEquals("Password too weak — try a longer or more varied password", createValidationError(pw, pw, scorePassword(pw))) } @Test fun mismatched_confirmation_is_rejected() { // Passes length + strength, but the confirmation differs. val err = createValidationError("Str0ng-Passphrase!23", "Str0ng-Passphrase!99", score = 4) assertEquals("passwords do not match", err) } @Test fun create_submit_is_blocked_until_confirmation_matches() { assertTrue(!canSubmitCreateVault("Str0ng-Passphrase!23", "", score = 4)) assertTrue(!canSubmitCreateVault("Str0ng-Passphrase!23", "Str0ng-Passphrase!99", score = 4)) assertTrue(canSubmitCreateVault("Str0ng-Passphrase!23", "Str0ng-Passphrase!23", score = 4)) } @Test fun valid_create_returns_no_error() { assertNull(createValidationError("Str0ng-Passphrase!23", "Str0ng-Passphrase!23", score = 4)) } @Test fun length_is_checked_before_strength() { // A short password that is also weak surfaces the length error first. assertEquals("password must be at least 12 characters", createValidationError("ab1", "ab1", score = 0)) } @Test fun strength_is_checked_before_match() { // Long but weak AND mismatched → strength error wins over the match error. assertEquals("Password too weak — try a longer or more varied password", createValidationError("aaaaaaaaaaaaaaaa", "different-confirm", score = 1)) } }