Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
723206e
add initial version of app auto lock
leofelix077 Jun 15, 2026
1b7d43c
update state handling when coming from background and comments
leofelix077 Jun 16, 2026
f50bf1f
Merge branch 'main' into lf-add-auto-lock
leofelix077 Jun 16, 2026
996b9a9
add secure flags for app background state to avoid snapshotting
leofelix077 Jun 16, 2026
820f7db
fix loading account states when coming from background
leofelix077 Jun 16, 2026
14fcdc9
add auto lock timer in seconds debug option and verification for lock…
leofelix077 Jun 16, 2026
ba81a3c
preserve sign in method from unlock and improve debug auto lock options
leofelix077 Jun 16, 2026
44f10d9
add visible countdown timers for debugging oh physical device
leofelix077 Jun 16, 2026
96ad730
add ios deterministic privacy shield
leofelix077 Jun 16, 2026
5cf10fd
add android auto lock privacy screen
leofelix077 Jun 16, 2026
98de964
adjust lock on foreground and background behaviors
leofelix077 Jun 16, 2026
8281249
capture presses and nav to reset idle lock count
leofelix077 Jun 17, 2026
e781e13
adjust comments from codex for stale state
leofelix077 Jun 17, 2026
3d82b3c
suprress biometric prompt on manual logout
leofelix077 Jun 17, 2026
9053a4e
wait for lock screen to show to ask for biometric prompt
leofelix077 Jun 17, 2026
288f47e
Merge branch 'main' into lf-add-auto-lock
leofelix077 Jun 17, 2026
7ab2ad5
clear auto lock values on wallet import and new sign up
leofelix077 Jun 17, 2026
08566bc
Merge branch 'lf-add-auto-lock' of github.com:stellar/freighter-mobil…
leofelix077 Jun 17, 2026
c80f602
harden background and lock security, change default to 12h and add mo…
leofelix077 Jun 22, 2026
ccf97d2
Merge remote-tracking branch 'origin/main' into lf-add-auto-lock
leofelix077 Jun 22, 2026
5a5e9e2
remove dev lock timers
leofelix077 Jun 22, 2026
d6d05ad
fix unlock toast error id
leofelix077 Jun 22, 2026
2e0f538
remove unintentional commited doc
leofelix077 Jun 29, 2026
5fa28e8
Merge remote-tracking branch 'origin/main' into lf-add-auto-lock
leofelix077 Jun 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions __tests__/components/LockScreenOverlay.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { act } from "@testing-library/react-native";
import { LockScreenOverlay } from "components/LockScreenOverlay";
import { AUTH_STATUS } from "config/types";
import { useAuthenticationStore } from "ducks/auth";
import { renderWithProviders } from "helpers/testUtils";
import React from "react";

jest.mock("ducks/auth", () => {
const actual = jest.requireActual("ducks/auth");
return {
...actual,
getActiveAccountPublicKey: jest.fn().mockResolvedValue(null),
};
});

jest.mock("services/autoLock", () => ({
persistAutoLockTimer: jest.fn().mockResolvedValue(undefined),
applyAutoLockTimerToHashKey: jest.fn().mockResolvedValue(undefined),
}));

describe("LockScreenOverlay", () => {
beforeEach(() => {
jest.clearAllMocks();
});

it("renders nothing when the wallet is not soft-locked", () => {
useAuthenticationStore.setState({
authStatus: AUTH_STATUS.AUTHENTICATED,
isSoftLocked: false,
});

const { queryByTestId } = renderWithProviders(<LockScreenOverlay />);

expect(queryByTestId("lock-screen-overlay")).toBeNull();
expect(queryByTestId("lock-screen")).toBeNull();
});

it("renders the lock UI above the app when soft-locked", () => {
useAuthenticationStore.setState({
authStatus: AUTH_STATUS.LOCKED,
isSoftLocked: true,
});

const { getByTestId } = renderWithProviders(<LockScreenOverlay />);

expect(getByTestId("lock-screen-overlay")).toBeTruthy();
expect(getByTestId("lock-screen")).toBeTruthy();
expect(getByTestId("unlock-button")).toBeTruthy();
});

it("disappears when the wallet is unlocked", () => {
useAuthenticationStore.setState({
authStatus: AUTH_STATUS.LOCKED,
isSoftLocked: true,
});

const { getByTestId, queryByTestId } = renderWithProviders(
<LockScreenOverlay />,
);
expect(getByTestId("lock-screen-overlay")).toBeTruthy();

// Unlock: signIn success resets the store which clears isSoftLocked
act(() => {
useAuthenticationStore.setState({
authStatus: AUTH_STATUS.AUTHENTICATED,
isSoftLocked: false,
});
});

expect(queryByTestId("lock-screen-overlay")).toBeNull();
});
});
232 changes: 232 additions & 0 deletions __tests__/components/screens/LockScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
import { NativeStackScreenProps } from "@react-navigation/native-stack";
import { waitFor } from "@testing-library/react-native";
import { LockScreen } from "components/screens/LockScreen";
import { LoginType } from "config/constants";
import { ROOT_NAVIGATOR_ROUTES, RootStackParamList } from "config/routes";
import { useAuthenticationStore } from "ducks/auth";
import { usePreferencesStore } from "ducks/preferences";
import { renderWithProviders } from "helpers/testUtils";
import React from "react";
import { AppState } from "react-native";

jest.mock("ducks/auth", () => {
const actual = jest.requireActual("ducks/auth");
return {
...actual,
getActiveAccountPublicKey: jest.fn().mockResolvedValue(null),
};
});

jest.mock("services/autoLock", () => ({
persistAutoLockTimer: jest.fn().mockResolvedValue(undefined),
applyAutoLockTimerToHashKey: jest.fn().mockResolvedValue(undefined),
}));

// Controllable privacy-shield state so we can assert the prompt is held until
// the shield drops on return from background.
let mockShieldVisible = false;
const mockShieldHiddenListeners = new Set<() => void>();
const emitShieldHidden = () => {
mockShieldVisible = false;
mockShieldHiddenListeners.forEach((listener) => listener());
};
jest.mock("helpers/privacyShield", () => ({
isPrivacyShieldVisible: () => mockShieldVisible,
onPrivacyShieldHidden: (listener: () => void) => {
mockShieldHiddenListeners.add(listener);
return () => mockShieldHiddenListeners.delete(listener);
},
markPrivacyShieldVisible: jest.fn(),
hidePrivacyShield: jest.fn(),
}));

type LockScreenNavigationProp = NativeStackScreenProps<
RootStackParamList,
typeof ROOT_NAVIGATOR_ROUTES.LOCK_SCREEN
>["navigation"];

type LockScreenRouteProp = NativeStackScreenProps<
RootStackParamList,
typeof ROOT_NAVIGATOR_ROUTES.LOCK_SCREEN
>["route"];

const mockNavigation = {
replace: jest.fn(),
goBack: jest.fn(),
setOptions: jest.fn(),
} as unknown as LockScreenNavigationProp;

const mockRoute = {
key: "lock-screen",
name: ROOT_NAVIGATOR_ROUTES.LOCK_SCREEN,
} as unknown as LockScreenRouteProp;

describe("LockScreen", () => {
const mockSignIn = jest.fn();
const mockVerifyActionWithBiometrics = jest.fn(
(callback: (password?: string) => Promise<unknown>) =>
callback("biometric-password"),
);

const previousAppState = AppState.currentState;

beforeEach(() => {
jest.clearAllMocks();
(AppState as { currentState: string }).currentState = "active";
mockShieldVisible = false;
mockShieldHiddenListeners.clear();

useAuthenticationStore.setState({
signIn: mockSignIn,
verifyActionWithBiometrics:
mockVerifyActionWithBiometrics as unknown as ReturnType<
typeof useAuthenticationStore.getState
>["verifyActionWithBiometrics"],
signInMethod: LoginType.FACE,
isLoading: false,
error: null,
suppressBiometricAutoPrompt: false,
});
usePreferencesStore.setState({ isBiometricsEnabled: true });
});

afterAll(() => {
(AppState as { currentState: typeof previousAppState }).currentState =
previousAppState;
});

const renderLockScreen = () =>
renderWithProviders(
<LockScreen navigation={mockNavigation} route={mockRoute} />,
);

it("auto-prompts biometrics on mount and unlocks with the stored password", async () => {
renderLockScreen();

await waitFor(() => {
expect(mockVerifyActionWithBiometrics).toHaveBeenCalledTimes(1);
});
expect(mockSignIn).toHaveBeenCalledWith({
password: "biometric-password",
});
});

it("does not auto-prompt when biometrics are disabled", async () => {
usePreferencesStore.setState({ isBiometricsEnabled: false });
useAuthenticationStore.setState({ signInMethod: LoginType.PASSWORD });

renderLockScreen();

await waitFor(() => {
expect(mockVerifyActionWithBiometrics).not.toHaveBeenCalled();
});
expect(mockSignIn).not.toHaveBeenCalled();
});

it("does not auto-prompt on mount when the lock was user-initiated (idle or manual)", async () => {
// The user stayed in the app and idled out, or locked manually — no
// unprompted Face ID
useAuthenticationStore.setState({ suppressBiometricAutoPrompt: true });

renderLockScreen();

// Give the mount effect a chance to (not) fire
await waitFor(() => {
expect(mockSignIn).not.toHaveBeenCalled();
});
expect(mockVerifyActionWithBiometrics).not.toHaveBeenCalled();
});

it("still re-prompts on return from background after a user-initiated lock", async () => {
useAuthenticationStore.setState({ suppressBiometricAutoPrompt: true });

renderLockScreen();

// No mount prompt for the idle lock...
await waitFor(() => {
expect(mockVerifyActionWithBiometrics).not.toHaveBeenCalled();
});

// ...but returning from the background still prompts (coming from bg)
const appStateHandlers = (
AppState.addEventListener as jest.Mock
).mock.calls.map(([, handler]) => handler as (state: string) => void);

appStateHandlers.forEach((handler) => handler("background"));
appStateHandlers.forEach((handler) => handler("active"));

await waitFor(() => {
expect(mockVerifyActionWithBiometrics).toHaveBeenCalledTimes(1);
});
});

it("re-prompts biometrics when the app returns from the background", async () => {
renderLockScreen();

await waitFor(() => {
expect(mockVerifyActionWithBiometrics).toHaveBeenCalledTimes(1);
});

// Simulate the app going to the background and returning to the foreground
const appStateHandlers = (
AppState.addEventListener as jest.Mock
).mock.calls.map(([, handler]) => handler as (state: string) => void);

appStateHandlers.forEach((handler) => handler("background"));
appStateHandlers.forEach((handler) => handler("active"));

await waitFor(() => {
expect(mockVerifyActionWithBiometrics).toHaveBeenCalledTimes(2);
});
});

it("holds the biometric prompt until the privacy shield drops on return from background", async () => {
renderLockScreen();

// Mount prompt fires immediately — the shield isn't up at mount
await waitFor(() => {
expect(mockVerifyActionWithBiometrics).toHaveBeenCalledTimes(1);
});

// App backgrounds (shield raised) and returns to the foreground
mockShieldVisible = true;
const appStateHandlers = (
AppState.addEventListener as jest.Mock
).mock.calls.map(([, handler]) => handler as (state: string) => void);

appStateHandlers.forEach((handler) => handler("background"));
appStateHandlers.forEach((handler) => handler("active"));

// The prompt is held while the shield still covers the wallet
await waitFor(() => {
expect(mockVerifyActionWithBiometrics).toHaveBeenCalledTimes(1);
});

// Once the shield drops, the held prompt fires so Face ID appears over
// the now-visible lock screen
emitShieldHidden();

await waitFor(() => {
expect(mockVerifyActionWithBiometrics).toHaveBeenCalledTimes(2);
});
});

it("does not re-prompt on inactive-to-active transitions (e.g. the biometric overlay itself)", async () => {
renderLockScreen();

await waitFor(() => {
expect(mockVerifyActionWithBiometrics).toHaveBeenCalledTimes(1);
});

const appStateHandlers = (
AppState.addEventListener as jest.Mock
).mock.calls.map(([, handler]) => handler as (state: string) => void);

appStateHandlers.forEach((handler) => handler("inactive"));
appStateHandlers.forEach((handler) => handler("active"));

await waitFor(() => {
expect(mockVerifyActionWithBiometrics).toHaveBeenCalledTimes(1);
});
});
});
Loading
Loading