Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
33 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
1f13577
Merge branch 'main' into lf-add-auto-lock
piyalbasu Jul 6, 2026
3d72965
Cap hash-key hard-expiry at 48h instead of 7 days
piyalbasu Jul 6, 2026
8de23cc
Abort cleanly (not error) when auto-lock engages during signing
piyalbasu Jul 6, 2026
0045ac7
Match auto-lock timer options exactly to the Freighter extension
piyalbasu Jul 7, 2026
8150ae1
Fix three soft-lock gaps from review triage
piyalbasu Jul 7, 2026
51e4790
Fix three soft-lock timing/ordering races from review triage
piyalbasu Jul 7, 2026
1c6ea0e
Harden hash-key hard-expiry against clock rollback
piyalbasu Jul 7, 2026
78455db
Fix AboutScreen test: mock getBundleId (unblocks CI)
piyalbasu Jul 7, 2026
e1becc7
Widen hash-key hard-expiry to 72h
piyalbasu Jul 7, 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();
});
});
143 changes: 143 additions & 0 deletions __tests__/components/screens/LockScreen.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
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),
}));

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";

useAuthenticationStore.setState({
signIn: mockSignIn,
verifyActionWithBiometrics:
mockVerifyActionWithBiometrics as unknown as ReturnType<
typeof useAuthenticationStore.getState
>["verifyActionWithBiometrics"],
signInMethod: LoginType.FACE,
isLoading: false,
error: null,
});
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("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("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);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { NativeStackScreenProps } from "@react-navigation/native-stack";
import { userEvent } from "@testing-library/react-native";
import AutoLockTimerScreen from "components/screens/SettingsScreen/SecurityScreen/AutoLockTimerScreen";
import { AUTO_LOCK_TIMER, DEFAULT_AUTO_LOCK_TIMER } from "config/constants";
import { SETTINGS_ROUTES, SettingsStackParamList } from "config/routes";
import { usePreferencesStore } from "ducks/preferences";
import { renderWithProviders } from "helpers/testUtils";
import React from "react";

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

type AutoLockTimerScreenNavigationProp = NativeStackScreenProps<
SettingsStackParamList,
typeof SETTINGS_ROUTES.AUTO_LOCK_TIMER_SCREEN
>["navigation"];

type AutoLockTimerScreenRouteProp = NativeStackScreenProps<
SettingsStackParamList,
typeof SETTINGS_ROUTES.AUTO_LOCK_TIMER_SCREEN
>["route"];

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

const mockRoute = {
key: "auto-lock-timer",
name: SETTINGS_ROUTES.AUTO_LOCK_TIMER_SCREEN,
} as unknown as AutoLockTimerScreenRouteProp;

describe("AutoLockTimerScreen", () => {
beforeEach(() => {
jest.clearAllMocks();
usePreferencesStore.setState({ autoLockTimer: DEFAULT_AUTO_LOCK_TIMER });
});

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

it("renders all timer options", () => {
const { getByTestId } = renderAutoLockTimerScreen();

expect(
getByTestId(`auto-lock-option-${AUTO_LOCK_TIMER.IMMEDIATELY}`),
Comment thread
leofelix077 marked this conversation as resolved.
Outdated
).toBeTruthy();
expect(
getByTestId(`auto-lock-option-${AUTO_LOCK_TIMER.ONE_MINUTE}`),
).toBeTruthy();
expect(
getByTestId(`auto-lock-option-${AUTO_LOCK_TIMER.FIFTEEN_MINUTES}`),
).toBeTruthy();
expect(
getByTestId(`auto-lock-option-${AUTO_LOCK_TIMER.THIRTY_MINUTES}`),
).toBeTruthy();
expect(
getByTestId(`auto-lock-option-${AUTO_LOCK_TIMER.ONE_HOUR}`),
).toBeTruthy();
expect(
getByTestId(`auto-lock-option-${AUTO_LOCK_TIMER.TWELVE_HOURS}`),
).toBeTruthy();
expect(
getByTestId(`auto-lock-option-${AUTO_LOCK_TIMER.TWENTY_FOUR_HOURS}`),
).toBeTruthy();
expect(
getByTestId(`auto-lock-option-${AUTO_LOCK_TIMER.NONE}`),
).toBeTruthy();
});

it("renders the footer explanation", () => {
const { getByText } = renderAutoLockTimerScreen();

expect(
getByText(
"After a set time, you will be prompted for your password again as an extra security measure.",
),
).toBeTruthy();
});

it("updates the preference when an option is tapped", async () => {
const { getByTestId } = renderAutoLockTimerScreen();

await userEvent.press(
getByTestId(`auto-lock-option-${AUTO_LOCK_TIMER.FIFTEEN_MINUTES}`),
);

expect(usePreferencesStore.getState().autoLockTimer).toBe(
AUTO_LOCK_TIMER.FIFTEEN_MINUTES,
);
});
});
Loading
Loading