Skip to content

Commit

Permalink
nits (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
JFrankfurt authored Oct 4, 2024
1 parent d5b4050 commit 5316dff
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 32 deletions.
4 changes: 1 addition & 3 deletions apps/web/app/frames/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ function withIPCheck(handler: (req: NextRequest) => Promise<Response>) {
if (ipaddr.isValid(address)) {
if (!ipSafe(address)) {
allSafe = false;
} else {
}
} else {
return NextResponse.json({ message: 'Invalid IP address resolution' }, { status: 400 });
}
}

if (!allSafe) {
return NextResponse.json({ message: 'Forbidden: Unsafe IP' }, { status: 403 });
return NextResponse.json({ message: 'Forbidden' }, { status: 403 });
}

return await handler(req);
Expand All @@ -43,6 +42,5 @@ function withIPCheck(handler: (req: NextRequest) => Promise<Response>) {
};
}

//
export const GET = withIPCheck(getHandler);
export const POST = withIPCheck(postHandler);
29 changes: 0 additions & 29 deletions apps/web/src/middleware/ipSafe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,6 @@ jest.mock('ipaddr.js', () => ({
},
}));
describe('IP Safe Tests', () => {
let originalEnv: string | undefined;

beforeAll(() => {
originalEnv = process.env.NODE_ENV;
});

afterAll(() => {
// @ts-expect-error this is ok I promise
process.env.NODE_ENV = originalEnv;
});

beforeEach(() => {
jest.clearAllMocks();
});
Expand All @@ -57,9 +46,6 @@ describe('IP Safe Tests', () => {
});

test('returns false for invalid IP address', () => {
// @ts-expect-error this is ok I promise
process.env.NODE_ENV = 'production';

(ipaddr.parse as jest.Mock).mockImplementationOnce(() => {
throw new Error('Invalid IP');
});
Expand All @@ -68,9 +54,6 @@ describe('IP Safe Tests', () => {
});

test('returns false for unsafe IPv4 address', () => {
// @ts-expect-error this is ok I promise
process.env.NODE_ENV = 'production';

const mockIPv4 = {
kind: () => 'ipv4',
range: () => 'private',
Expand All @@ -83,9 +66,6 @@ describe('IP Safe Tests', () => {
});

test('returns true for safe IPv4 address', () => {
// @ts-expect-error this is ok I promise
process.env.NODE_ENV = 'production';

const mockIPv4 = {
kind: () => 'ipv4',
range: () => 'unicast',
Expand All @@ -98,9 +78,6 @@ describe('IP Safe Tests', () => {
});

test('returns false for unsafe IPv6 address', () => {
// @ts-expect-error this is ok I promise
process.env.NODE_ENV = 'production';

const mockIPv6 = {
kind: () => 'ipv6',
range: () => 'loopback',
Expand All @@ -113,9 +90,6 @@ describe('IP Safe Tests', () => {
});

test('returns true for safe IPv6 address', () => {
// @ts-expect-error this is ok I promise
process.env.NODE_ENV = 'production';

const mockIPv6 = {
kind: () => 'ipv6',
range: () => 'unicast',
Expand All @@ -128,9 +102,6 @@ describe('IP Safe Tests', () => {
});

test('returns true for safe IPv6 mapped IPv4 address', () => {
// @ts-expect-error this is ok I promise
process.env.NODE_ENV = 'production';

const mockIPv6 = {
kind: () => 'ipv6',
range: () => 'unicast',
Expand Down

0 comments on commit 5316dff

Please sign in to comment.