Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten eligibility vpn check #2150

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function fingerprintLocationSpoofingBuilder(): IBuilder<FingerprintLocati
export function fingerprintVpnBuilder(): IBuilder<FingerprintVpn> {
return new Builder<FingerprintVpn>().with('data', {
result: faker.datatype.boolean(),
confidence: 'high',
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ export const FingerprintIpInfoSchema = z.object({
export type FingerprintIpInfo = z.infer<typeof FingerprintIpInfoSchema>;

export const FingerprintVpnSchema = z.object({
data: z.object({ result: z.boolean() }).nullish().default(null),
data: z
.object({
result: z.boolean(),
confidence: z.enum(['low', 'medium', 'high']),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could we extract this to an enum, as it's used in across several places?

(as an example):

export enum FingerprintConfidenceLevels {...}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we should add an unknown value that we fallback to as we do elsewhere to ensure we cover unknowns. We should also add test coverage for this.

})
.nullish()
.default(null),
});

export type FingerprintVpn = z.infer<typeof FingerprintVpnSchema>;
Expand Down
16 changes: 12 additions & 4 deletions src/datasources/locking-api/fingerprint-api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ describe('FingerprintApiService', () => {
locationSpoofing: fingerprintLocationSpoofingBuilder()
.with('data', { result: false })
.build(),
vpn: fingerprintVpnBuilder().with('data', { result: false }).build(),
vpn: fingerprintVpnBuilder()
.with('data', { result: false, confidence: 'high' })
.build(),
})
.build();
(unsealEventsResponse as jest.Mock).mockResolvedValue(unsealedData);
Expand Down Expand Up @@ -93,7 +95,9 @@ describe('FingerprintApiService', () => {
locationSpoofing: fingerprintLocationSpoofingBuilder()
.with('data', { result: false })
.build(),
vpn: fingerprintVpnBuilder().with('data', { result: false }).build(),
vpn: fingerprintVpnBuilder()
.with('data', { result: false, confidence: 'high' })
.build(),
})
.build();
(unsealEventsResponse as jest.Mock).mockResolvedValue(unsealedData);
Expand Down Expand Up @@ -122,7 +126,9 @@ describe('FingerprintApiService', () => {
locationSpoofing: fingerprintLocationSpoofingBuilder()
.with('data', { result: false })
.build(),
vpn: fingerprintVpnBuilder().with('data', { result: true }).build(),
vpn: fingerprintVpnBuilder()
.with('data', { result: true, confidence: 'high' })
.build(),
})
.build();
(unsealEventsResponse as jest.Mock).mockResolvedValue(unsealedData);
Expand All @@ -144,7 +150,9 @@ describe('FingerprintApiService', () => {
locationSpoofing: fingerprintLocationSpoofingBuilder()
.with('data', { result: false })
.build(),
vpn: fingerprintVpnBuilder().with('data', { result: true }).build(),
vpn: fingerprintVpnBuilder()
.with('data', { result: true, confidence: 'high' })
.build(),
})
.build();
(unsealEventsResponse as jest.Mock).mockResolvedValue(unsealedData);
Expand Down
4 changes: 3 additions & 1 deletion src/datasources/locking-api/fingerprint-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class FingerprintApiService implements IIdentityApi {
return {
requestId,
isAllowed: this.isAllowed(unsealedData),
isVpn: unsealedData.products.vpn?.data?.result === true,
isVpn:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: maybe we could extract this to a new private isVpn(unsealedData: FingerprintUnsealedData): boolean function?

unsealedData.products.vpn?.data?.result === true &&
unsealedData.products.vpn?.data?.confidence === 'high',
};
}

Expand Down