Skip to content

Commit 2ec845e

Browse files
committed
chore(demo): mask IDs in E2E mode
1 parent 006421e commit 2ec845e

7 files changed

Lines changed: 32 additions & 4 deletions

File tree

examples/demo/src/components/sections/AppSection.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IonToggle } from '@ionic/react';
22
import type { FC } from 'react';
33

4+
import { maskValue } from '../../utils/maskValue';
45
import SectionCard from '../SectionCard';
56

67
interface AppSectionProps {
@@ -23,7 +24,7 @@ const AppSection: FC<AppSectionProps> = ({
2324
<div className="kv-row">
2425
<span>App ID</span>
2526
<span className="id-value" data-testid="app_id_value">
26-
{appId}
27+
{maskValue(appId)}
2728
</span>
2829
</div>
2930
</div>

examples/demo/src/components/sections/PushSection.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IonToggle } from '@ionic/react';
22
import type { FC } from 'react';
33

4+
import { maskValue } from '../../utils/maskValue';
45
import ActionButton from '../ActionButton';
56
import SectionCard from '../SectionCard';
67

@@ -26,7 +27,7 @@ const PushSection: FC<PushSectionProps> = ({
2627
<div className="kv-row">
2728
<span>Push ID</span>
2829
<span className="id-value" data-testid="push_id_value">
29-
{pushSubscriptionId ?? '—'}
30+
{maskValue(pushSubscriptionId ?? '—')}
3031
</span>
3132
</div>
3233
<div className="divider" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Mirrors the trim/strict-equals check used elsewhere so a stray newline
2+
// or whitespace in `.env` doesn't accidentally enable masking.
3+
const E2E_MODE = (import.meta.env.VITE_E2E_MODE ?? '').trim() === 'true';
4+
const MASK_CHAR = '•';
5+
6+
export function maskValue(value: string): string {
7+
if (E2E_MODE) {
8+
return MASK_CHAR.repeat(value.length);
9+
}
10+
return value;
11+
}

examples/demo_pods/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
VITE_ONESIGNAL_APP_ID=your_onesignal_app_id
12
VITE_ONESIGNAL_API_KEY=your_rest_api_key
3+
VITE_E2E_MODE=false

examples/demo_pods/src/components/sections/AppSection.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IonToggle } from '@ionic/react';
22
import type { FC } from 'react';
33

4+
import { maskValue } from '../../utils/maskValue';
45
import SectionCard from '../SectionCard';
56

67
interface AppSectionProps {
@@ -23,7 +24,7 @@ const AppSection: FC<AppSectionProps> = ({
2324
<div className="kv-row">
2425
<span>App ID</span>
2526
<span className="id-value" data-testid="app_id_value">
26-
{appId}
27+
{maskValue(appId)}
2728
</span>
2829
</div>
2930
</div>

examples/demo_pods/src/components/sections/PushSection.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IonToggle } from '@ionic/react';
22
import type { FC } from 'react';
33

4+
import { maskValue } from '../../utils/maskValue';
45
import ActionButton from '../ActionButton';
56
import SectionCard from '../SectionCard';
67

@@ -26,7 +27,7 @@ const PushSection: FC<PushSectionProps> = ({
2627
<div className="kv-row">
2728
<span>Push ID</span>
2829
<span className="id-value" data-testid="push_id_value">
29-
{pushSubscriptionId ?? '—'}
30+
{maskValue(pushSubscriptionId ?? '—')}
3031
</span>
3132
</div>
3233
<div className="divider" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Mirrors the trim/strict-equals check used elsewhere so a stray newline
2+
// or whitespace in `.env` doesn't accidentally enable masking.
3+
const E2E_MODE = (import.meta.env.VITE_E2E_MODE ?? '').trim() === 'true';
4+
const MASK_CHAR = '•';
5+
6+
export function maskValue(value: string): string {
7+
if (E2E_MODE) {
8+
return MASK_CHAR.repeat(value.length);
9+
}
10+
return value;
11+
}

0 commit comments

Comments
 (0)